Show More
@@ -0,0 +1,116 | |||||
|
1 | // Test the notification area and widgets | |||
|
2 | ||||
|
3 | casper.notebook_test(function () { | |||
|
4 | var that = this; | |||
|
5 | var widget = function (name) { | |||
|
6 | return that.evaluate(function (name) { | |||
|
7 | return (IPython.notification_area.widget(name) !== undefined); | |||
|
8 | }, name); | |||
|
9 | }; | |||
|
10 | ||||
|
11 | var get_widget = function (name) { | |||
|
12 | return that.evaluate(function (name) { | |||
|
13 | return (IPython.notification_area.get_widget(name) !== undefined); | |||
|
14 | }, name); | |||
|
15 | }; | |||
|
16 | ||||
|
17 | var new_notification_widget = function (name) { | |||
|
18 | return that.evaluate(function (name) { | |||
|
19 | return (IPython.notification_area.new_notification_widget(name) !== undefined); | |||
|
20 | }, name); | |||
|
21 | }; | |||
|
22 | ||||
|
23 | var widget_has_class = function (name, class_name) { | |||
|
24 | return that.evaluate(function (name, class_name) { | |||
|
25 | var w = IPython.notification_area.get_widget(name); | |||
|
26 | return w.element.hasClass(class_name); | |||
|
27 | }, name, class_name); | |||
|
28 | }; | |||
|
29 | ||||
|
30 | var widget_message = function (name) { | |||
|
31 | return that.evaluate(function (name) { | |||
|
32 | var w = IPython.notification_area.get_widget(name); | |||
|
33 | return w.get_message(); | |||
|
34 | }, name); | |||
|
35 | }; | |||
|
36 | ||||
|
37 | this.then(function () { | |||
|
38 | // check that existing widgets are there | |||
|
39 | this.test.assert(get_widget('kernel') && widget('kernel'), 'The kernel notification widget exists'); | |||
|
40 | this.test.assert(get_widget('notebook') && widget('notbook'), 'The notebook notification widget exists'); | |||
|
41 | ||||
|
42 | // try getting a non-existant widget | |||
|
43 | this.test.assertRaises(get_widget, 'foo', 'get_widget: error is thrown'); | |||
|
44 | ||||
|
45 | // try creating a non-existant widget | |||
|
46 | this.test.assert(widget('bar'), 'widget: new widget is created'); | |||
|
47 | ||||
|
48 | // try creating a widget that already exists | |||
|
49 | this.test.assertRaises(new_notification_widget, 'kernel', 'new_notification_widget: error is thrown'); | |||
|
50 | }); | |||
|
51 | ||||
|
52 | // test creating 'info' messages | |||
|
53 | this.thenEvaluate(function () { | |||
|
54 | var tnw = IPython.notification_area.widget('test'); | |||
|
55 | tnw.info('test info'); | |||
|
56 | }); | |||
|
57 | this.waitUntilVisible('#notification_test', function () { | |||
|
58 | this.test.assert(widget_has_class('test', 'info'), 'info: class is correct'); | |||
|
59 | this.test.assertEquals(widget_message('test'), 'test info', 'info: message is correct'); | |||
|
60 | }); | |||
|
61 | ||||
|
62 | // test creating 'warning' messages | |||
|
63 | this.thenEvaluate(function () { | |||
|
64 | var tnw = IPython.notification_area.widget('test'); | |||
|
65 | tnw.warning('test warning'); | |||
|
66 | }); | |||
|
67 | this.waitUntilVisible('#notification_test', function () { | |||
|
68 | this.test.assert(widget_has_class('test', 'warning'), 'warning: class is correct'); | |||
|
69 | this.test.assertEquals(widget_message('test'), 'test warning', 'warning: message is correct'); | |||
|
70 | }); | |||
|
71 | ||||
|
72 | // test creating 'danger' messages | |||
|
73 | this.thenEvaluate(function () { | |||
|
74 | var tnw = IPython.notification_area.widget('test'); | |||
|
75 | tnw.danger('test danger'); | |||
|
76 | }); | |||
|
77 | this.waitUntilVisible('#notification_test', function () { | |||
|
78 | this.test.assert(widget_has_class('test', 'danger'), 'danger: class is correct'); | |||
|
79 | this.test.assertEquals(widget_message('test'), 'test danger', 'danger: message is correct'); | |||
|
80 | }); | |||
|
81 | ||||
|
82 | // test message timeout | |||
|
83 | this.thenEvaluate(function () { | |||
|
84 | var tnw = IPython.notification_area.widget('test'); | |||
|
85 | tnw.set_message('test timeout', 1000); | |||
|
86 | }); | |||
|
87 | this.waitUntilVisible('#notification_test', function () { | |||
|
88 | this.test.assertEquals(widget_message('test'), 'test timeout', 'timeout: message is correct'); | |||
|
89 | }); | |||
|
90 | this.waitWhileVisible('#notification_test', function () { | |||
|
91 | this.test.assertEquals(widget_message('test'), '', 'timeout: message was cleared'); | |||
|
92 | }); | |||
|
93 | ||||
|
94 | // test click callback | |||
|
95 | this.thenEvaluate(function () { | |||
|
96 | var tnw = IPython.notification_area.widget('test'); | |||
|
97 | tnw._clicked = false; | |||
|
98 | tnw.set_message('test click', undefined, function () { | |||
|
99 | tnw._clicked = true; | |||
|
100 | return true; | |||
|
101 | }); | |||
|
102 | }); | |||
|
103 | this.waitUntilVisible('#notification_test', function () { | |||
|
104 | this.test.assertEquals(widget_message('test'), 'test click', 'callback: message is correct'); | |||
|
105 | this.click('#notification_test'); | |||
|
106 | }); | |||
|
107 | this.waitFor(function () { | |||
|
108 | return this.evaluate(function () { | |||
|
109 | return IPython.notification_area.widget('test')._clicked; | |||
|
110 | }); | |||
|
111 | }, function () { | |||
|
112 | this.waitWhileVisible('#notification_test', function () { | |||
|
113 | this.test.assertEquals(widget_message('test'), '', 'callback: message was cleared'); | |||
|
114 | }); | |||
|
115 | }); | |||
|
116 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now