Show More
@@ -1,108 +1,113 b'' | |||||
1 | // Test multicontainer class |
|
1 | // Test multicontainer class | |
2 | casper.notebook_test(function () { |
|
2 | casper.notebook_test(function () { | |
3 | index = this.append_cell( |
|
3 | index = this.append_cell( | |
4 | 'from IPython.html import widgets\n' + |
|
4 | 'from IPython.html import widgets\n' + | |
5 | 'from IPython.display import display, clear_output\n' + |
|
5 | 'from IPython.display import display, clear_output\n' + | |
6 | 'print("Success")'); |
|
6 | 'print("Success")'); | |
7 | this.execute_cell_then(index); |
|
7 | this.execute_cell_then(index); | |
8 |
|
8 | |||
9 | // Test tab view |
|
9 | // Test tab view | |
10 | var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs'; |
|
10 | var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs'; | |
11 | var multicontainer1_index = this.append_cell( |
|
11 | var multicontainer1_index = this.append_cell( | |
12 | 'multicontainer = widgets.TabWidget()\n' + |
|
12 | 'multicontainer = widgets.TabWidget()\n' + | |
13 | 'page1 = widgets.TextWidget()\n' + |
|
13 | 'page1 = widgets.TextWidget()\n' + | |
14 | 'page2 = widgets.TextWidget()\n' + |
|
14 | 'page2 = widgets.TextWidget()\n' + | |
15 | 'page3 = widgets.TextWidget()\n' + |
|
15 | 'page3 = widgets.TextWidget()\n' + | |
16 | 'multicontainer.children = [page1, page2, page3]\n' + |
|
16 | 'multicontainer.children = [page1, page2, page3]\n' + | |
17 | 'display(multicontainer)\n' + |
|
17 | 'display(multicontainer)\n' + | |
18 | 'multicontainer.selected_index = 0\n' + |
|
18 | 'multicontainer.selected_index = 0\n' + | |
19 | 'print("Success")\n'); |
|
19 | 'print("Success")\n'); | |
20 | this.execute_cell_then(multicontainer1_index, function(index){ |
|
20 | this.execute_cell_then(multicontainer1_index, function(index){ | |
21 |
|
21 | |||
22 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
22 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
23 | 'Create multicontainer cell executed with correct output. (1)'); |
|
23 | 'Create multicontainer cell executed with correct output. (1)'); | |
24 |
|
24 | |||
25 | this.test.assert(this.cell_element_exists(index, |
|
25 | this.test.assert(this.cell_element_exists(index, | |
26 | '.widget-area .widget-subarea'), |
|
26 | '.widget-area .widget-subarea'), | |
27 | 'Widget subarea exists.'); |
|
27 | 'Widget subarea exists.'); | |
28 |
|
28 | |||
29 | this.test.assert(this.cell_element_exists(index, multicontainer1_query), |
|
29 | this.test.assert(this.cell_element_exists(index, multicontainer1_query), | |
30 | 'Widget tab list exists.'); |
|
30 | 'Widget tab list exists.'); | |
31 |
|
31 | |||
32 | this.test.assert(this.cell_element_exists(index, multicontainer1_query), |
|
32 | this.test.assert(this.cell_element_exists(index, multicontainer1_query), | |
33 | 'First widget tab list exists.'); |
|
33 | 'First widget tab list exists.'); | |
34 |
|
34 | |||
35 | // JQuery selector is 1 based |
|
35 | // JQuery selector is 1 based | |
36 | this.click(multicontainer1_query + ' li:nth-child(2) a'); |
|
36 | this.click(multicontainer1_query + ' li:nth-child(2) a'); | |
37 | }); |
|
37 | }); | |
38 |
|
38 | |||
39 | this.wait_for_idle(); |
|
39 | this.wait_for_idle(); | |
40 |
|
40 | |||
41 | index = this.append_cell( |
|
41 | index = this.append_cell( | |
42 | 'print(multicontainer.selected_index)\n' + |
|
42 | 'print(multicontainer.selected_index)\n' + | |
43 | 'multicontainer.selected_index = 2'); // 0 based |
|
43 | 'multicontainer.selected_index = 2'); // 0 based | |
44 | this.execute_cell_then(index, function(index){ |
|
44 | this.execute_cell_then(index, function(index){ | |
45 | this.test.assertEquals(this.get_output_cell(index).text, '1\n', // 0 based |
|
45 | this.test.assertEquals(this.get_output_cell(index).text, '1\n', // 0 based | |
46 | 'selected_index property updated with tab change.'); |
|
46 | 'selected_index property updated with tab change.'); | |
47 |
|
47 | |||
48 | // JQuery selector is 1 based |
|
48 | // JQuery selector is 1 based | |
49 | this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(1)', 'hasClass', ['active']), |
|
49 | this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(1)', 'hasClass', ['active']), | |
50 | "Tab 1 is not selected."); |
|
50 | "Tab 1 is not selected."); | |
51 | this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(2)', 'hasClass', ['active']), |
|
51 | this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(2)', 'hasClass', ['active']), | |
52 | "Tab 2 is not selected."); |
|
52 | "Tab 2 is not selected."); | |
53 | this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(3)', 'hasClass', ['active']), |
|
53 | this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(3)', 'hasClass', ['active']), | |
54 | "Tab 3 is selected."); |
|
54 | "Tab 3 is selected."); | |
55 | }); |
|
55 | }); | |
56 |
|
56 | |||
57 | index = this.append_cell('multicontainer.set_title(1, "hello")\nprint("Success")'); // 0 based |
|
57 | index = this.append_cell('multicontainer.set_title(1, "hello")\nprint("Success")'); // 0 based | |
58 | this.execute_cell_then(index, function(index){ |
|
58 | this.execute_cell_then(index, function(index){ | |
59 | this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + |
|
59 | this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + | |
60 | ' li:nth-child(2) a', 'html') == 'hello', |
|
60 | ' li:nth-child(2) a', 'html') == 'hello', | |
61 | 'Tab page title set (after display).'); |
|
61 | 'Tab page title set (after display).'); | |
62 | }); |
|
62 | }); | |
63 |
|
63 | |||
64 | // Test accordion view |
|
64 | // Test accordion view | |
65 | var multicontainer2_query = '.widget-area .widget-subarea .accordion'; |
|
65 | var multicontainer2_query = '.widget-area .widget-subarea .accordion'; | |
66 | var multicontainer2_index = this.append_cell( |
|
66 | var multicontainer2_index = this.append_cell( | |
67 | 'multicontainer = widgets.AccordionWidget()\n' + |
|
67 | 'multicontainer = widgets.AccordionWidget()\n' + | |
68 | 'page1 = widgets.TextWidget()\n' + |
|
68 | 'page1 = widgets.TextWidget()\n' + | |
69 | 'page2 = widgets.TextWidget()\n' + |
|
69 | 'page2 = widgets.TextWidget()\n' + | |
70 | 'page3 = widgets.TextWidget()\n' + |
|
70 | 'page3 = widgets.TextWidget()\n' + | |
71 | 'multicontainer.children = [page1, page2, page3]\n' + |
|
71 | 'multicontainer.children = [page1, page2, page3]\n' + | |
72 | 'multicontainer.set_title(2, "good")\n' + |
|
72 | 'multicontainer.set_title(2, "good")\n' + | |
73 | 'display(multicontainer)\n' + |
|
73 | 'display(multicontainer)\n' + | |
74 | 'multicontainer.selected_index = 0\n' + |
|
74 | 'multicontainer.selected_index = 0\n' + | |
75 | 'print("Success")\n'); |
|
75 | 'print("Success")\n'); | |
76 | this.execute_cell_then(multicontainer2_index, function(index){ |
|
76 | this.execute_cell_then(multicontainer2_index, function(index){ | |
77 |
|
77 | |||
78 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
78 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
79 | 'Create multicontainer cell executed with correct output. (2)'); |
|
79 | 'Create multicontainer cell executed with correct output. (2)'); | |
80 |
|
80 | |||
81 | this.test.assert(this.cell_element_exists(index, |
|
81 | this.test.assert(this.cell_element_exists(index, | |
82 | '.widget-area .widget-subarea'), |
|
82 | '.widget-area .widget-subarea'), | |
83 | 'Widget subarea exists.'); |
|
83 | 'Widget subarea exists.'); | |
84 |
|
84 | |||
85 | this.test.assert(this.cell_element_exists(index, multicontainer2_query), |
|
85 | this.test.assert(this.cell_element_exists(index, multicontainer2_query), | |
86 | 'Widget accordion exists.'); |
|
86 | 'Widget accordion exists.'); | |
87 |
|
87 | |||
88 | this.test.assert(this.cell_element_exists(index, multicontainer2_query + |
|
88 | this.test.assert(this.cell_element_exists(index, multicontainer2_query + | |
89 | ' .accordion-group:nth-child(1) .accordion-body'), |
|
89 | ' .accordion-group:nth-child(1) .accordion-body'), | |
90 | 'First accordion page exists.'); |
|
90 | 'First accordion page exists.'); | |
91 |
|
91 | |||
92 | // JQuery selector is 1 based |
|
92 | // JQuery selector is 1 based | |
93 | this.test.assert(this.cell_element_function(index, multicontainer2_query + |
|
93 | this.test.assert(this.cell_element_function(index, multicontainer2_query + | |
94 | ' .accordion-group:nth-child(3) .accordion-heading .accordion-toggle', |
|
94 | ' .accordion-group:nth-child(3) .accordion-heading .accordion-toggle', | |
95 | 'html')=='good', 'Accordion page title set (before display).'); |
|
95 | 'html')=='good', 'Accordion page title set (before display).'); | |
96 |
|
96 | |||
97 | // JQuery selector is 1 based |
|
97 | // JQuery selector is 1 based | |
98 | this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle'); |
|
98 | this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle'); | |
99 | }); |
|
99 | }); | |
100 |
|
100 | |||
101 | this.wait_for_idle(); |
|
101 | this.wait_for_idle(); | |
102 |
|
102 | |||
103 | index = this.append_cell('print(multicontainer.selected_index)'); // 0 based |
|
103 | index = this.append_cell('print(multicontainer.selected_index)'); // 0 based | |
104 | this.execute_cell_then(index, function(index){ |
|
104 | this.execute_cell_then(index, function(index){ | |
105 | this.test.assertEquals(this.get_output_cell(index).text, '1\n', // 0 based |
|
105 | this.test.assertEquals(this.get_output_cell(index).text, '1\n', // 0 based | |
106 | 'selected_index property updated with tab change.'); |
|
106 | 'selected_index property updated with tab change.'); | |
|
107 | ||||
|
108 | var is_collapsed = this.evaluate(function(s){ | |||
|
109 | return $(s + ' div.accordion-group:nth-child(2) a').hasClass('collapsed'); // 1 based | |||
|
110 | }, {s: multicontainer2_query}); | |||
|
111 | this.test.assertEquals(is_collapsed, false, 'Was tab actually opened?'); | |||
107 | }); |
|
112 | }); | |
108 | }); No newline at end of file |
|
113 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now