UnitTC: Additional unit testcases have been added
[platform/framework/web/web-ui-fw.git] / tests / additional-unit-tests / notification / notification-tests.js
1 /*
2  * Unit Test : Notification
3  *
4  * Minkyu Kang <mk7.kang@samsung.com>
5  */
6 /*jslint browser: true*/
7 /*global $, jQuery, test, equal, ok*/
8 (function ($) {
9         module("Notification");
10
11         var unit_notification = function ( widget, type ) {
12                 var notification,
13                         elem = ".ui-" + type,
14                         text,
15                         closebutton;
16
17                 /* Create */
18                 widget.notification();
19
20                 notification = widget.children( elem );
21                 ok( notification, "Create");
22
23                 /*markup check*/
24                 if (type == ' ticker') {
25                         ok(notification.find('.ui-ticker-btn'), "makrup Check : Close button") ;
26                         ok(notification.find('.ui-ticker-btn').find(":jqmData(role=button)"), "makrup Check : Close button present") ;
27                         equal(notification.find('.ui-ticker-btn').find(":jqmData(role=button)").text(), 'Close', "makrup Check : Close button text") ;
28                         ok(notification.find('.ui-ticker').find(".ui.ticker-text1-bg"), "makrup Check : ticker text present") ;
29                         ok(notification.find('.ui-ticker').find(".ui.ticker-text2-bg"), "makrup Check : ticker text present") ;
30                         ok(notification.find('.ui-ticker').find("img.ui-ticker-icon").length > 0, "makrup Check : ticker icon present") ;
31                 } else {
32                         ok(notification.find('.ui-smallpopup'), "makrup Check : smapll popup") ;
33                         ok(notification.find('.ui-smallpopup').find(".ui.smallpopup-text-bg"), "makrup Check : popup text present") ;
34                 }
35
36                 /* Open */
37                 widget.notification("open");
38                 notification = widget.children( elem );
39                 ok( notification.hasClass("show"), "API : open");
40
41                 /* Close */
42                 widget.notification("close");
43                 notification = widget.children( elem );
44                 ok( notification.hasClass("hide"), "API : close");
45
46                 /* hide when click */
47                 widget.notification("open");
48                 notification = widget.children( elem );
49
50                 /*for coverage open notification when it is already open*/
51                 widget.notification("open");
52                 notification.trigger("vmouseup");
53                 notification = widget.children( elem );
54                 ok( notification.hasClass("hide"), "Hide when click the notification");
55
56                 if ( type == ' ticker') {
57                         widget.notification("open");
58                         closebutton = widget.find(':jqmData(role=button)');
59                         closebutton.trigger("vmouseup");
60                         notification = widget.children( elem );
61                         ok( notification.hasClass("hide"), "Hide when click on the close button");
62                 }
63
64                 text = notification.children("p");
65                 if ( type === "smallpopup") {
66                         ok( $( text[0] ).hasClass("ui-smallpopup-text-bg"), "Text");
67                         widget.notification('text', 'Text21');
68                         ok( $( text[0] ).hasClass("ui-smallpopup-text-bg"), "Text21");
69                         equal( widget.notification('text')[0], "Text21", "API : text - smallpopup");
70                         equal( text[0].innerHTML, "Text21", "API : text - smallpopup");
71                 } else {
72                         ok( $( text[0] ).hasClass("ui-ticker-text1-bg"), "Top Text");
73                         ok( $( text[1] ).hasClass("ui-ticker-text2-bg"), "Bottom Text");
74
75                         widget.notification('text', 'Text31', 'Text32');
76                         ok( $( text[0] ).hasClass("ui-ticker-text1-bg"), "Text31", "API : text- ticker");
77                         ok( $( text[1] ).hasClass("ui-ticker-text2-bg"), "Text32", "API : text- ticker");
78                         equal( text[0].innerHTML, "Text31", "API : text - ticker");
79                         equal( text[1].innerHTML, "Text32", "API : text - ticker");
80                         equal( widget.notification('text')[0], "Text31", "API : text - ticker");
81                         equal( widget.notification('text')[1], "Text32", "API : text - ticker");
82
83                         /*icon*/
84                         equal(widget.jqmData('icon'), '02_icon.png', "API : icon , initial check") ;
85                         widget.notification('icon', '03_icon.png');
86                         equal(widget.find('img').attr("src"), '03_icon.png', "API : icon , new icon is set") ;
87                 }
88                 /*destroy*/
89                 widget.notification("destroy");
90                 notification = widget.children( elem );
91                 ok( !notification.hasClass("show") || !notification.hasClass("hide"), "destroy check");
92         };
93
94         test("smallpopup", function () {
95                 $('#notifiaction0').page();
96                 unit_notification( $("#smallpopup"), "smallpopup");
97                 unit_notification( $("#smallpopup2"), "smallpopup");
98                 unit_notification( $("#smallpopup3"), "smallpopup");
99         });
100
101         test("tickernoti", function () {
102                 $('#notifiaction1').page();
103                 unit_notification( $("#tickernoti"), "ticker");
104                 unit_notification( $("#tickernoti2"), "ticker");
105                 unit_notification( $("#tickernoti3"), "ticker");
106         });
107 }( jQuery ));