Export 0.2.3
[platform/framework/web/web-ui-fw.git] / tests / unit-tests / swipe / swipe-tests.js
1 /*
2  * swipe unit tests
3  *
4  * Hyunjung Kim <hjnim.kim@samsung.com>
5  *
6  */
7
8 ( function ( $ ) {
9
10         module("swipe");
11
12         var unit_swipe = function( swipe, type ) {
13                 var     covers,
14                         cover,
15                         coverStart,
16                         item,
17                         slideLeftDone = function () {
18                                 ok(true, "Animation Complete - sliding left");
19                                 cover.unbind("animationComplete");
20                                 equal(cover.position().left, coverStart, "Position - Cover");
21                                 start();
22                         },
23                         slideRightDone = function () {
24                                 ok(true, "Animation Complete - sliding right");
25                                 setTimeout(function () {
26                                         cover.unbind("animationComplete");
27                                         cover.bind("animationComplete", slideLeftDone);
28                                         item.trigger("swipeleft");
29                                 }, 0);
30                         };
31
32                 $("#swipepage").page();
33                 swipe.swipe();
34                 ok(swipe.hasClass("ui-swipe"), "Create - Swipe");
35
36                 covers = swipe.find("div.ui-swipe-item-cover");
37                 cover = covers.first();
38
39                 coverStart = cover.position().left;
40                 item = swipe.find("div.ui-swipe-item").first();
41
42                 cover.bind("animationComplete", slideRightDone);
43                 cover.trigger("swiperight");
44                 stop();
45
46                 equal( swipe.find("div.ui-swipe-item").length , 1, "Count - Swipeable li");
47                 equal( covers.length , 1, "Count - cover");
48
49                 equal( covers.get(0).innerText,
50                                 "Swipe2",
51                                 "Check - Cover string value");
52         };
53
54         var unit_swipe_destroy = function(swipe, type) {
55                 var covers,
56                         new_page = $("#swipedestorypage");
57
58                 new_page.page();
59                 swipe.swipe();
60                 ok(swipe.hasClass("ui-swipe"),"Create - Swipe");
61                 covers = swipe.find("div.ui-swipe-item-cover");
62                 equal( swipe.find("div.ui-swipe-item").length , 1, "Count - Swipeable ui-swipe-item");
63
64                 equal( covers.length , 1, "Count - cover");
65
66                 swipe.swipe("destroy");
67
68                 equal(new_page.has('.ui-swipe').length, 0, "Destroy - swipe");
69                 equal(new_page.has('.ui-swipe-item').length, 0 , "Destroy - item" );
70                 equal(new_page.has('.ui-swipe-item-cover').length, 0, "Destroy - cover");
71
72         };
73
74         asyncTest( " swipe ", function() {
75                 expect(7);
76                 unit_swipe( $("#swipewidget"), "swipe" );
77                 start();
78         });
79
80         asyncTest( " swipe - destory", function() {
81                 expect(6),
82                 unit_swipe_destroy( $("#swipedestroy"), "swipedestroy"),
83                 start()
84         });
85
86 } ) ( jQuery );