2.0_beta sync to rsa
[framework/web/web-ui-fw.git] / tests / unit-tests / popupwindow_ctxpopup / ctxpopup-tests.js
1 $(document).ready( function () {
2
3         module( "CtxPopup" );
4         asyncTest( "Auto-initialization", function () {
5                 $.testHelper.pageSequence( [
6                         function () {
7                                 var plain = $("#pop_plain"),
8                                         plainBtn = $("#btn_plain"),
9                                         horizontal = $("#pop_horizontal"),
10                                         horizontalBtn = $("#btn_horizontal"),
11                                         buttons = $("#pop_buttons"),
12                                         buttonsBtn = $("#btn_buttons"),
13                                         notCtxpopup  = $("#pop_not"),
14                                         notCtxpopupBtn = $("#btn_not");
15
16                                 ok( plain.data( "ctxpopup" ), "should Normal type ctxpopup created" );
17                                 ok( horizontal.data( "ctxpopup" ), "should Horizontal type ctxpopup created" );
18                                 ok( buttons.data( "ctxpopup" ), "should Button type ctxpopup created" );
19                                 ok( !notCtxpopup.data( "ctxpopup" ), "should wihthout arrow ctxpopup not created" );
20                         },
21
22                         function () {
23                                 expect( 4 );
24                                 start();
25                         }
26                 ]);
27         });
28
29         // ctxpopup shares code with popupwindow so only tests ctxpopup specific codes
30         asyncTest( "Open and Placements", function () {
31                 $.testHelper.pageSequence( [
32                         function () {
33                                 var plain = $("#pop_plain").ctxpopup(),
34                                         horizontal = $("#pop_horizontal").ctxpopup(),
35                                         buttons = $("#pop_buttons").ctxpopup();
36
37                                 function placementsTest( popup ) {
38                                         var width = $(window).width(),
39                                                 height = $(window).height(),
40                                                 x = 0,
41                                                 y = 0,
42                                                 parents = popup.parents(".ui-popupwindow"),
43                                                 popPos,
44                                                 popDim,
45                                                 segment = 5,
46                                                 closed = 0,
47                                                 open = 0;
48
49                                         popup.bind( "popupafterclose", function () {
50                                                 // tests event trigger
51                                                 closed++;
52                                                 if ( closed == open ) {
53                                                         equal( closed, open, "should 'popupafterclose' triggered." );
54                                                         start();
55                                                 }
56                                         });
57
58                                         while ( y <= height ) {
59                                                 while ( x <= width ) {
60                                                         popup.popupwindow( "open", x, y );
61                                                         open++;
62                                                         popPos = parents.position();
63                                                         popDim = {
64                                                                 width: parents.width(),
65                                                                 height: parents.height()
66                                                         };
67
68                                                         if ( popPos.left < 0 || popPos.top < 0 || popPos.left > (width - popDim.width) || popPos.top > (height - popDim.height) ) {
69                                                                 throw "Pop up occured at wrong position: (" + parseInt(popPos.left, 10) + "," + parseInt(popPos.top, 10) + "," + popDim.width + "," + popDim.height + ")";
70                                                         }
71
72                                                         popup.popupwindow( "close" );
73                                                         x += width / segment;
74                                                 }
75                                                 y += height / segment;
76                                                 x = 0;
77                                         }
78                                         setTimeout( function() {
79                                                 if ( closed != open )
80                                                         throw "  Error, popupafterclose event was not triggering ";
81                                         }, 1000 * 10 );
82                                         stop();
83                                         return true;
84                                 }
85
86                                 var testee = [
87                                         { name: "Plain", popup: plain },
88                                         { name: "Horizontal", popup: horizontal },
89                                         { name: "Buttons", popup: buttons }
90                                 ];
91
92                                 for ( var i = 0; i < testee.length; i++ ) {
93                                         ok( placementsTest( testee[i].popup ), "should " + testee[i].name + " pop up within window area" );
94                                 }
95                         },
96
97                         function () {
98                                 expect( 6 );
99                                 start();
100                         }
101                 ]);
102         });
103 });