##// END OF EJS Templates
Organized tests.
Jonathan Frederic -
Show More
@@ -0,0 +1,92 b''
1 // Test widget bool class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var bool_index = this.append_cell(
10 'bool_widget = widgets.BoolWidget(description="Title", value=True)\n' +
11 'display(bool_widget)\n'+
12 'display(bool_widget, view_name="ToggleButtonView")\n' +
13 'print("Success")');
14 this.execute_cell_then(bool_index, function(index){
15
16 this.test.assert(this.get_output_cell(index).text == 'Success\n',
17 'Create bool widget cell executed with correct output.');
18
19 this.test.assert(this.cell_element_exists(index,
20 '.widget-area .widget-subarea'),
21 'Widget subarea exists.');
22
23 this.test.assert(this.cell_element_exists(index,
24 '.widget-area .widget-subarea .widget-hbox-single input'),
25 'Checkbox exists.');
26
27 this.test.assert(this.cell_element_function(index,
28 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
29 'Checkbox is checked.');
30
31 this.test.assert(this.cell_element_exists(index,
32 '.widget-area .widget-subarea .widget-hbox-single .widget-hlabel'),
33 'Checkbox label exists.');
34
35 this.test.assert(this.cell_element_function(index,
36 '.widget-area .widget-subarea .widget-hbox-single .widget-hlabel', 'html')=="Title",
37 'Checkbox labeled correctly.');
38
39 this.test.assert(this.cell_element_exists(index,
40 '.widget-area .widget-subarea div button'),
41 'Toggle button exists.');
42
43 this.test.assert(this.cell_element_function(index,
44 '.widget-area .widget-subarea div button', 'html')=="Title",
45 'Toggle button labeled correctly.');
46
47 this.test.assert(this.cell_element_function(index,
48 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
49 'Toggle button is toggled.');
50
51 });
52
53 index = this.append_cell(
54 'bool_widget.value = False\n' +
55 'print("Success")');
56 this.execute_cell_then(index, function(index){
57
58 this.test.assert(this.get_output_cell(index).text == 'Success\n',
59 'Change bool widget value cell executed with correct output.');
60
61 this.test.assert(! this.cell_element_function(bool_index,
62 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
63 'Checkbox is not checked. (1)');
64
65 this.test.assert(! this.cell_element_function(bool_index,
66 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
67 'Toggle button is not toggled. (1)');
68
69 // Try toggling the bool by clicking on the toggle button.
70 this.cell_element_function(bool_index, '.widget-area .widget-subarea div button', 'click');
71
72 this.test.assert(this.cell_element_function(bool_index,
73 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
74 'Checkbox is checked. (2)');
75
76 this.test.assert(this.cell_element_function(bool_index,
77 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
78 'Toggle button is toggled. (2)');
79
80 // Try toggling the bool by clicking on the checkbox.
81 this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click');
82
83 this.test.assert(! this.cell_element_function(bool_index,
84 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
85 'Checkbox is not checked. (3)');
86
87 this.test.assert(! this.cell_element_function(bool_index,
88 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
89 'Toggle button is not toggled. (3)');
90
91 });
92 }); No newline at end of file
@@ -0,0 +1,55 b''
1 // Test widget button class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var button_index = this.append_cell(
10 'button = widgets.ButtonWidget(description="Title")\n' +
11 'display(button)\n'+
12 'print("Success")\n' +
13 'def handle_click(sender):\n' +
14 ' print("Clicked")\n' +
15 'button.on_click(handle_click)');
16 this.execute_cell_then(button_index, function(index){
17
18 this.test.assert(this.get_output_cell(index).text == 'Success\n',
19 'Create button cell executed with correct output.');
20
21 this.test.assert(this.cell_element_exists(index,
22 '.widget-area .widget-subarea'),
23 'Widget subarea exists.');
24
25 this.test.assert(this.cell_element_exists(index,
26 '.widget-area .widget-subarea button'),
27 'Widget button exists.');
28
29 this.test.assert(this.cell_element_function(index,
30 '.widget-area .widget-subarea button', 'html')=='Title',
31 'Set button description.');
32
33 this.cell_element_function(index,
34 '.widget-area .widget-subarea button', 'click');
35 });
36
37 this.wait(500); // Wait for click to execute in kernel and write output
38
39 this.then(function () {
40 this.test.assert(this.get_output_cell(button_index, 1).text == 'Clicked\n',
41 'Button click event fires.');
42 });
43
44 // Close the button widget asynchronisly.
45 index = this.append_cell('button.close()\n');
46 this.execute_cell(index);
47
48 this.wait(500); // Wait for the button to close.
49
50 this.then(function(){
51 this.test.assert(! this.cell_element_exists(button_index,
52 '.widget-area .widget-subarea button'),
53 'Widget button doesn\'t exists.');
54 });
55 }); No newline at end of file
@@ -0,0 +1,59 b''
1 // Test widget float class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
10
11 var float_index = this.append_cell(
12 'float_widget = widgets.FloatWidget()\n' +
13 'display(float_widget)\n' +
14 'float_widget.add_class("my-second-float-text")\n' +
15 'print("Success")\n');
16 this.execute_cell_then(float_index, function(index){
17
18 this.test.assert(this.get_output_cell(index).text == 'Success\n',
19 'Create float cell executed with correct output.');
20
21 this.test.assert(this.cell_element_exists(index,
22 '.widget-area .widget-subarea'),
23 'Widget subarea exists.');
24
25 this.test.assert(this.cell_element_exists(index, float_text_query_2),
26 'Widget float textbox exists.');
27
28 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
29 this.sendKeys(float_text_query_2, '1.05');
30 });
31
32 this.wait(500); // Wait for change to execute in kernel
33
34 index = this.append_cell('print(float_widget.value)\n');
35 this.execute_cell_then(index, function(index){
36 this.test.assert(this.get_output_cell(index).text == '1.05\n',
37 'Float textbox value set.');
38 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
39 this.sendKeys(float_text_query_2, '123456789.0');
40 });
41
42 this.wait(500); // Wait for change to execute in kernel
43
44 index = this.append_cell('print(float_widget.value)\n');
45 this.execute_cell_then(index, function(index){
46 this.test.assert(this.get_output_cell(index).text == '123456789.0\n',
47 'Long float textbox value set (probably triggers throttling).');
48 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
49 this.sendKeys(float_text_query_2, '12hello');
50 });
51
52 this.wait(500); // Wait for change to execute in kernel
53
54 index = this.append_cell('print(float_widget.value)\n');
55 this.execute_cell_then(index, function(index){
56 this.test.assert(this.get_output_cell(index).text == '12.0\n',
57 'Invald float textbox value caught and filtered.');
58 });
59 }); No newline at end of file
@@ -0,0 +1,92 b''
1 // Test float range class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
10 var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text';
11
12 var floatrange_index = this.append_cell(
13 'floatrange = widgets.FloatRangeWidget()\n' +
14 'display(floatrange)\n' +
15 'display(floatrange, view_name="FloatTextView")\n' +
16 'print("Success")\n');
17 this.execute_cell_then(floatrange_index, function(index){
18
19 this.test.assert(this.get_output_cell(index).text == 'Success\n',
20 'Create float range cell executed with correct output.');
21
22 this.test.assert(this.cell_element_exists(index,
23 '.widget-area .widget-subarea'),
24 'Widget subarea exists.');
25
26 this.test.assert(this.cell_element_exists(index, slider_query),
27 'Widget slider exists.');
28
29 this.test.assert(this.cell_element_exists(index, float_text_query),
30 'Widget float textbox exists.');
31 });
32
33 index = this.append_cell(
34 'floatrange.max = 50.0\n' +
35 'floatrange.min = -50.0\n' +
36 'floatrange.value = 25.0\n' +
37 'print("Success")\n');
38 this.execute_cell_then(index, function(index){
39
40 this.test.assert(this.get_output_cell(index).text == 'Success\n',
41 'Float range properties cell executed with correct output.');
42
43 this.test.assert(this.cell_element_exists(floatrange_index, slider_query),
44 'Widget slider exists.');
45
46 this.test.assert(this.cell_element_function(floatrange_index, slider_query,
47 'slider', ['value']) == 25.0,
48 'Slider set to Python value.');
49
50 this.test.assert(this.cell_element_function(floatrange_index, float_text_query,
51 'val') == 25.0, 'Float textbox set to Python value.');
52
53 // Clear the float textbox value and then set it to 1 by emulating
54 // keyboard presses.
55 this.cell_element_function(floatrange_index, float_text_query, 'val', ['']);
56 this.sendKeys(float_text_query, '1');
57 });
58
59 this.wait(500); // Wait for change to execute in kernel
60
61 index = this.append_cell('print(floatrange.value)\n');
62 this.execute_cell_then(index, function(index){
63 this.test.assert(this.get_output_cell(index).text == '1.0\n',
64 'Float textbox set float range value');
65
66 // Clear the float textbox value and then set it to 120 by emulating
67 // keyboard presses.
68 this.cell_element_function(floatrange_index, float_text_query, 'val', ['']);
69 this.sendKeys(float_text_query, '120');
70 });
71
72 this.wait(500); // Wait for change to execute in kernel
73
74 index = this.append_cell('print(floatrange.value)\n');
75 this.execute_cell_then(index, function(index){
76 this.test.assert(this.get_output_cell(index).text == '50.0\n',
77 'Float textbox value bound');
78
79 // Clear the float textbox value and then set it to 'hello world' by
80 // emulating keyboard presses. 'hello world' should get filtered...
81 this.cell_element_function(floatrange_index, float_text_query, 'val', ['']);
82 this.sendKeys(float_text_query, 'hello world');
83 });
84
85 this.wait(500); // Wait for change to execute in kernel
86
87 index = this.append_cell('print(floatrange.value)\n');
88 this.execute_cell_then(index, function(index){
89 this.test.assert(this.get_output_cell(index).text == '50.0\n',
90 'Invalid float textbox characters ignored');
91 });
92 }); No newline at end of file
@@ -0,0 +1,60 b''
1 // Test image class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 // Get the temporary directory that the test server is running in.
10 var cwd = '';
11 index = this.append_cell('!echo $(pwd)');
12 this.execute_cell_then(index, function(index){
13 cwd = this.get_output_cell(index).text.trim();
14 });
15
16 test_jpg = '/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wgARCAABAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAAA//EABUBAQEAAAAAAAAAAAAAAAAAAAME/9oADAMBAAIQAxAAAAECv//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQn//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z';
17 test_results = '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAyADIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDi6KKK+ZP3EKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//Z';
18
19 var image_index = this.append_cell(
20 'import base64\n' +
21 'data = base64.b64decode("' + test_jpg + '")\n' +
22 'image = widgets.ImageWidget()\n' +
23 'image.image_format = "jpeg"\n' +
24 'image.value = data\n' +
25 'image.width = "50px"\n' +
26 'image.height = "50px"\n' +
27 // Set css that will make the image render within the PhantomJS visible
28 // window. If we don't do this, the captured image will be black.
29 'image.set_css({"background": "blue", "z-index": "9999", "position": "fixed", "top": "0px", "left": "0px"})\n' +
30 'display(image)\n' +
31 'image.add_class("my-test-image")\n' +
32 'print("Success")\n');
33 this.execute_cell_then(image_index, function(index){
34
35 this.test.assert(this.get_output_cell(index).text == 'Success\n',
36 'Create image executed with correct output.');
37
38 this.test.assert(this.cell_element_exists(index,
39 '.widget-area .widget-subarea'),
40 'Widget subarea exists.');
41
42 this.test.assert(this.cell_element_exists(index,
43 '.widget-area .widget-subarea img'),
44 'Image exists.');
45
46 // Capture a screenshot of the img element as a base64 string.
47 var fs = require('fs');
48 capture_filename = cwd + fs.separator + 'captured.jpg';
49 this.captureSelector(capture_filename, '.my-test-image');
50 var stream = fs.open(capture_filename, 'rb');
51 var captured = btoa(stream.read());
52 stream.close()
53 fs.remove(capture_filename);
54
55 // Uncomment line below to output captured image data to a text file.
56 // fs.write('./captured.txt', captured, 'w');
57
58 this.test.assert(test_results==captured, "Red image data displayed correctly.");
59 });
60 }); No newline at end of file
@@ -0,0 +1,59 b''
1 // Test widget int class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var int_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
10
11 var int_index = this.append_cell(
12 'int_widget = widgets.IntWidget()\n' +
13 'display(int_widget)\n' +
14 'int_widget.add_class("my-second-int-text")\n' +
15 'print("Success")\n');
16 this.execute_cell_then(int_index, function(index){
17
18 this.test.assert(this.get_output_cell(index).text == 'Success\n',
19 'Create int cell executed with correct output.');
20
21 this.test.assert(this.cell_element_exists(index,
22 '.widget-area .widget-subarea'),
23 'Widget subarea exists.');
24
25 this.test.assert(this.cell_element_exists(index, int_text_query_2),
26 'Widget int textbox exists.');
27
28 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
29 this.sendKeys(int_text_query_2, '1.05');
30 });
31
32 this.wait(500); // Wait for change to execute in kernel
33
34 index = this.append_cell('print(int_widget.value)\n');
35 this.execute_cell_then(index, function(index){
36 this.test.assert(this.get_output_cell(index).text == '1\n',
37 'Int textbox value set.');
38 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
39 this.sendKeys(int_text_query_2, '123456789');
40 });
41
42 this.wait(500); // Wait for change to execute in kernel
43
44 index = this.append_cell('print(int_widget.value)\n');
45 this.execute_cell_then(index, function(index){
46 this.test.assert(this.get_output_cell(index).text == '123456789\n',
47 'Long int textbox value set (probably triggers throttling).');
48 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
49 this.sendKeys(int_text_query_2, '12hello');
50 });
51
52 this.wait(500); // Wait for change to execute in kernel
53
54 index = this.append_cell('print(int_widget.value)\n');
55 this.execute_cell_then(index, function(index){
56 this.test.assert(this.get_output_cell(index).text == '12\n',
57 'Invald int textbox value caught and filtered.');
58 });
59 }); No newline at end of file
@@ -0,0 +1,93 b''
1 // Test int range class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
10 var int_text_query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
11
12 var intrange_index = this.append_cell(
13 'intrange = widgets.IntRangeWidget()\n' +
14 'display(intrange, view_name="IntTextView")\n' +
15 'intrange.add_class("my-second-num-test-text")\n' +
16 'display(intrange)\n' +
17 'print("Success")\n');
18 this.execute_cell_then(intrange_index, function(index){
19
20 this.test.assert(this.get_output_cell(index).text == 'Success\n',
21 'Create int range cell executed with correct output.');
22
23 this.test.assert(this.cell_element_exists(index,
24 '.widget-area .widget-subarea'),
25 'Widget subarea exists.');
26
27 this.test.assert(this.cell_element_exists(index, slider_query),
28 'Widget slider exists.');
29
30 this.test.assert(this.cell_element_exists(index, int_text_query),
31 'Widget int textbox exists.');
32 });
33
34 index = this.append_cell(
35 'intrange.max = 50\n' +
36 'intrange.min = -50\n' +
37 'intrange.value = 25\n' +
38 'print("Success")\n');
39 this.execute_cell_then(index, function(index){
40
41 this.test.assert(this.get_output_cell(index).text == 'Success\n',
42 'Int range properties cell executed with correct output.');
43
44 this.test.assert(this.cell_element_exists(intrange_index, slider_query),
45 'Widget slider exists.');
46
47 this.test.assert(this.cell_element_function(intrange_index, slider_query,
48 'slider', ['value']) == 25,
49 'Slider set to Python value.');
50
51 this.test.assert(this.cell_element_function(intrange_index, int_text_query,
52 'val') == 25, 'Int textbox set to Python value.');
53
54 // Clear the int textbox value and then set it to 1 by emulating
55 // keyboard presses.
56 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
57 this.sendKeys(int_text_query, '1');
58 });
59
60 this.wait(500); // Wait for change to execute in kernel
61
62 index = this.append_cell('print(intrange.value)\n');
63 this.execute_cell_then(index, function(index){
64 this.test.assert(this.get_output_cell(index).text == '1\n',
65 'Int textbox set int range value');
66
67 // Clear the int textbox value and then set it to 120 by emulating
68 // keyboard presses.
69 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
70 this.sendKeys(int_text_query, '120');
71 });
72
73 this.wait(500); // Wait for change to execute in kernel
74
75 index = this.append_cell('print(intrange.value)\n');
76 this.execute_cell_then(index, function(index){
77 this.test.assert(this.get_output_cell(index).text == '50\n',
78 'Int textbox value bound');
79
80 // Clear the int textbox value and then set it to 'hello world' by
81 // emulating keyboard presses. 'hello world' should get filtered...
82 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
83 this.sendKeys(int_text_query, 'hello world');
84 });
85
86 this.wait(500); // Wait for change to execute in kernel
87
88 index = this.append_cell('print(intrange.value)\n');
89 this.execute_cell_then(index, function(index){
90 this.test.assert(this.get_output_cell(index).text == '50\n',
91 'Invalid int textbox characters ignored');
92 });
93 }); No newline at end of file
@@ -0,0 +1,106 b''
1 // Test multicontainer class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 // Test tab view
10 var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs';
11 var multicontainer1_index = this.append_cell(
12 'multicontainer = widgets.MulticontainerWidget()\n' +
13 'page1 = widgets.StringWidget(parent=multicontainer)\n' +
14 'page2 = widgets.StringWidget(parent=multicontainer)\n' +
15 'page3 = widgets.StringWidget(parent=multicontainer)\n' +
16 'display(multicontainer)\n' +
17 'multicontainer.selected_index = 0\n' +
18 'print("Success")\n');
19 this.execute_cell_then(multicontainer1_index, function(index){
20
21 this.test.assert(this.get_output_cell(index).text == 'Success\n',
22 'Create multicontainer cell executed with correct output. (1)');
23
24 this.test.assert(this.cell_element_exists(index,
25 '.widget-area .widget-subarea'),
26 'Widget subarea exists.');
27
28 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
29 'Widget tab list exists.');
30
31 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
32 'First widget tab list exists.');
33
34 // JQuery selector is 1 based
35 this.click(multicontainer1_query + ' li:nth-child(2) a')
36 });
37
38 this.wait(500); // Wait for change to execute in kernel
39
40 index = this.append_cell(
41 'print(multicontainer.selected_index)\n' +
42 'multicontainer.selected_index = 2'); // 0 based
43 this.execute_cell_then(index, function(index){
44 this.test.assert(this.get_output_cell(index).text == '1\n', // 0 based
45 'selected_index property updated with tab change.');
46
47 // JQuery selector is 1 based
48 this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(1)', 'hasClass', ['active']),
49 "Tab 1 is not selected.")
50 this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(2)', 'hasClass', ['active']),
51 "Tab 2 is not selected.")
52 this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(3)', 'hasClass', ['active']),
53 "Tab 3 is selected.")
54 });
55
56 index = this.append_cell('multicontainer.set_title(1, "hello")\nprint("Success")'); // 0 based
57 this.execute_cell_then(index, function(index){
58 this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query +
59 ' li:nth-child(2) a', 'html') == 'hello',
60 'Tab page title set (after display).');
61 });
62
63 // Test accordion view
64 var multicontainer2_query = '.widget-area .widget-subarea .accordion';
65 var multicontainer2_index = this.append_cell(
66 'multicontainer = widgets.MulticontainerWidget()\n' +
67 'page1 = widgets.StringWidget(parent=multicontainer)\n' +
68 'page2 = widgets.StringWidget(parent=multicontainer)\n' +
69 'page3 = widgets.StringWidget(parent=multicontainer)\n' +
70 'multicontainer.set_title(2, "good")\n' +
71 'display(multicontainer, view_name="AccordionView")\n' +
72 'multicontainer.selected_index = 0\n' +
73 'print("Success")\n');
74 this.execute_cell_then(multicontainer2_index, function(index){
75
76 this.test.assert(this.get_output_cell(index).text == 'Success\n',
77 'Create multicontainer cell executed with correct output. (2)');
78
79 this.test.assert(this.cell_element_exists(index,
80 '.widget-area .widget-subarea'),
81 'Widget subarea exists.');
82
83 this.test.assert(this.cell_element_exists(index, multicontainer2_query),
84 'Widget accordion exists.');
85
86 this.test.assert(this.cell_element_exists(index, multicontainer2_query +
87 ' .accordion-group:nth-child(1) .accordion-body'),
88 'First accordion page exists.');
89
90 // JQuery selector is 1 based
91 this.test.assert(this.cell_element_function(index, multicontainer2_query +
92 ' .accordion-group:nth-child(3) .accordion-heading .accordion-toggle',
93 'html')=='good', 'Accordion page title set (before display).');
94
95 // JQuery selector is 1 based
96 this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle');
97 });
98
99 this.wait(500); // Wait for change to execute in kernel
100
101 index = this.append_cell('print(multicontainer.selected_index)'); // 0 based
102 this.execute_cell_then(index, function(index){
103 this.test.assert(this.get_output_cell(index).text == '1\n', // 0 based
104 'selected_index property updated with tab change.');
105 });
106 }); No newline at end of file
@@ -0,0 +1,114 b''
1 // Test selection class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var combo_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group .widget-combo-btn'
10 var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]'
11 var radio_selector = '.widget-area .widget-subarea .widget-hbox .vbox'
12 var list_selector = '.widget-area .widget-subarea .widget-hbox .widget-listbox'
13
14 var selection_index;
15 var selection_values = 'abcd';
16 var check_state = function(context, index, state){
17 if (0 <= index && index < selection_values.length) {
18 var multibtn_state = context.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(' + (index + 1) + ')', 'hasClass', ['active']);
19 var radio_state = context.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(' + (index + 1) + ') input', 'prop', ['checked']);
20 var list_val = context.cell_element_function(selection_index, list_selector, 'val');
21 var combo_val = context.cell_element_function(selection_index, combo_selector, 'html');
22
23 var val = selection_values.charAt(index);
24 var list_state = (val == list_val);
25 var combo_state = (val == combo_val);
26
27 return multibtn_state == state &&
28 radio_state == state &&
29 list_state == state &&
30 combo_state == state;
31 }
32 return true;
33 }
34
35 var verify_selection = function(context, index){
36 for (var i = 0; i < selection_values.length; i++) {
37 if (!check_state(context, i, i==index)) {
38 return false;
39 }
40 }
41 return true;
42 }
43
44 selection_index = this.append_cell(
45 'selection = widgets.SelectionWidget(values=["' + selection_values + '"[i] for i in range(4)])\n' +
46 'display(selection)\n' +
47 'display(selection, view_name="ToggleButtonsView")\n' +
48 'display(selection, view_name="RadioButtonsView")\n' +
49 'display(selection, view_name="ListBoxView")\n' +
50 'print("Success")\n');
51 this.execute_cell_then(selection_index, function(index){
52 this.test.assert(this.get_output_cell(index).text == 'Success\n',
53 'Create selection cell executed with correct output.');
54
55 this.test.assert(this.cell_element_exists(index,
56 '.widget-area .widget-subarea'),
57 'Widget subarea exists.');
58
59 this.test.assert(this.cell_element_exists(index, combo_selector),
60 'Widget combobox exists.');
61
62 this.test.assert(this.cell_element_exists(index, multibtn_selector),
63 'Widget multibutton exists.');
64
65 this.test.assert(this.cell_element_exists(index, radio_selector),
66 'Widget radio buttons exists.');
67
68 this.test.assert(this.cell_element_exists(index, list_selector),
69 'Widget list exists.');
70
71 // Verify that no items are selected.
72 this.test.assert(verify_selection(this, -1), 'No items selected.');
73 });
74
75 index = this.append_cell(
76 'selection.value = "a"\n' +
77 'print("Success")\n');
78 this.execute_cell_then(index, function(index){
79 this.test.assert(this.get_output_cell(index).text == 'Success\n',
80 'Python select item executed with correct output.');
81
82 // Verify that the first item is selected.
83 this.test.assert(verify_selection(this, 0), 'Python selected');
84
85 // Verify that selecting a radio button updates all of the others.
86 this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click');
87 this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.');
88
89 // Verify that selecting a list option updates all of the others.
90 this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click');
91 this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.');
92
93 // Verify that selecting a multibutton option updates all of the others.
94 this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click');
95 this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.');
96
97 // Verify that selecting a combobox option updates all of the others.
98 this.cell_element_function(selection_index, '.widget-area .widget-subarea .widget-hbox-single .btn-group ul.dropdown-menu li:nth-child(3) a', 'click');
99 this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.');
100 });
101
102 this.wait(500); // Wait for change to execute in kernel
103
104 index = this.append_cell(
105 'print(selection.value)\n' +
106 'selection.values.append("z")\n' +
107 'selection.send_state()\n' +
108 'selection.value = "z"');
109 this.execute_cell_then(index, function(index){
110
111 // Verify that selecting a combobox option updates all of the others.
112 this.test.assert(verify_selection(this, 4), 'Item added to selection widget.');
113 });
114 }); No newline at end of file
@@ -0,0 +1,70 b''
1 // Test widget string class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var string_index = this.append_cell(
10 'string_widget = widgets.StringWidget()\n' +
11 'display(string_widget)\n'+
12 'display(string_widget, view_name="TextAreaView")\n' +
13 'display(string_widget, view_name="HTMLView")\n' +
14 'display(string_widget, view_name="LatexView")\n' +
15 'string_widget.value = "xyz"\n' +
16 'print("Success")');
17 this.execute_cell_then(string_index, function(index){
18
19 this.test.assert(this.get_output_cell(index).text == 'Success\n',
20 'Create string widget cell executed with correct output.');
21
22 this.test.assert(this.cell_element_exists(index,
23 '.widget-area .widget-subarea'),
24 'Widget subarea exists.');
25
26 this.test.assert(this.cell_element_exists(index,
27 '.widget-area .widget-subarea .widget-hbox-single input[type=text]'),
28 'Textbox exists.');
29
30 this.test.assert(this.cell_element_exists(index,
31 '.widget-area .widget-subarea .widget-hbox textarea'),
32 'Textarea exists.');
33
34 this.test.assert(this.cell_element_function(index,
35 '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='xyz',
36 'Python set textarea value.');
37
38 this.test.assert(this.cell_element_function(index,
39 '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='xyz',
40 'Python set textbox value.');
41
42 this.cell_element_function(index,
43 '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val', [''])
44 this.sendKeys('.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'abc');
45
46 this.test.assert(this.cell_element_function(index,
47 '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='abc',
48 'Textarea updated to textbox contents.');
49
50 this.cell_element_function(index,
51 '.widget-area .widget-subarea .widget-hbox textarea', 'val', ['']);
52 this.sendKeys('.widget-area .widget-subarea .widget-hbox textarea', '$\\LaTeX{}$');
53
54 this.test.assert(this.cell_element_function(index,
55 '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='$\\LaTeX{}$',
56 'Textbox updated to textarea contents.');
57 });
58
59 this.wait(500); // Wait for change to execute in kernel
60
61 index = this.append_cell('print(string_widget.value)');
62 this.execute_cell_then(index, function(index){
63 this.test.assert(this.get_output_cell(index).text == '$\\LaTeX{}$\n',
64 'Python updated with correct string widget value.');
65
66 this.test.assert(this.cell_element_exists(string_index,
67 '.widget-area .widget-subarea div span.MathJax_Preview'),
68 'MathJax parsed the LaTeX successfully.');
69 });
70 }); No newline at end of file
@@ -0,0 +1,79 b''
1 // Test container class
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var container_index = this.append_cell(
10 'container = widgets.ContainerWidget()\n' +
11 'button = widgets.ButtonWidget(parent=container)\n'+
12 'display(container)\n'+
13 'container.add_class("my-test-class")\n'+
14 'print("Success")\n');
15 this.execute_cell_then(container_index, function(index){
16
17 this.test.assert(this.get_output_cell(index).text == 'Success\n',
18 'Create container cell executed with correct output.');
19
20 this.test.assert(this.cell_element_exists(index,
21 '.widget-area .widget-subarea'),
22 'Widget subarea exists.');
23
24 this.test.assert(this.cell_element_exists(index,
25 '.widget-area .widget-subarea .widget-container'),
26 'Widget container exists.');
27
28 this.test.assert(this.cell_element_exists(index,
29 '.widget-area .widget-subarea .my-test-class'),
30 'add_class works.');
31
32 this.test.assert(this.cell_element_exists(index,
33 '.widget-area .widget-subarea .my-test-class button'),
34 'Container parent/child relationship works.');
35 });
36
37 index = this.append_cell(
38 'container.set_css("display", "none")\n'+
39 'print("Success")\n');
40 this.execute_cell_then(index, function(index){
41
42 this.test.assert(this.get_output_cell(index).text == 'Success\n',
43 'Set container class CSS cell executed with correct output.');
44
45 this.test.assert(this.cell_element_function(container_index,
46 '.widget-area .widget-subarea .my-test-class', 'css', ['display'])=='none',
47 'set_css works.');
48 });
49
50 index = this.append_cell(
51 'container.remove_class("my-test-class")\n'+
52 'print("Success")\n');
53 this.execute_cell_then(index, function(index){
54
55 this.test.assert(this.get_output_cell(index).text == 'Success\n',
56 'Remove container class cell executed with correct output.');
57
58 this.test.assert(! this.cell_element_exists(container_index,
59 '.widget-area .widget-subarea .my-test-class'),
60 'remove_class works.');
61 });
62
63 index = this.append_cell(
64 'display(button)\n'+
65 'print("Success")\n');
66 this.execute_cell_then(index, function(index){
67
68 this.test.assert(this.get_output_cell(index).text == 'Success\n',
69 'Display container child executed with correct output.');
70
71 this.test.assert(! this.cell_element_exists(index,
72 '.widget-area .widget-subarea .widget-container'),
73 'Parent container not displayed.');
74
75 this.test.assert(this.cell_element_exists(index,
76 '.widget-area .widget-subarea button'),
77 'Child displayed.');
78 });
79 }); No newline at end of file
This diff has been collapsed as it changes many lines, (810 lines changed) Show them Hide them
@@ -2,7 +2,6 b''
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 var index;
3 var index;
4
4
5 // Test widget dependencies ////////////////////////////////////////////////
6 this.then(function () {
5 this.then(function () {
7
6
8 // Check if the WidgetManager class is defined.
7 // Check if the WidgetManager class is defined.
@@ -26,7 +25,6 b' casper.notebook_test(function () {'
26 }), 'Notebook widget manager instanciated');
25 }), 'Notebook widget manager instanciated');
27 });
26 });
28
27
29 // Check widget mapping ////////////////////////////////////////////////////
30 index = this.append_cell(
28 index = this.append_cell(
31 'names = [name for name in dir(widgets)' +
29 'names = [name for name in dir(widgets)' +
32 ' if name.endswith("Widget") and name!= "Widget"]\n' +
30 ' if name.endswith("Widget") and name!= "Widget"]\n' +
@@ -76,813 +74,7 b' casper.notebook_test(function () {'
76 }
74 }
77 }
75 }
78 });
76 });
79
77
80 // Test bool widget ////////////////////////////////////////////////////////
81 var bool_index = this.append_cell(
82 'bool_widget = widgets.BoolWidget(description="Title", value=True)\n' +
83 'display(bool_widget)\n'+
84 'display(bool_widget, view_name="ToggleButtonView")\n' +
85 'print("Success")');
86 this.execute_cell_then(bool_index, function(index){
87
88 this.test.assert(this.get_output_cell(index).text == 'Success\n',
89 'Create bool widget cell executed with correct output.');
90
91 this.test.assert(this.cell_element_exists(index,
92 '.widget-area .widget-subarea'),
93 'Widget subarea exists.');
94
95 this.test.assert(this.cell_element_exists(index,
96 '.widget-area .widget-subarea .widget-hbox-single input'),
97 'Checkbox exists.');
98
99 this.test.assert(this.cell_element_function(index,
100 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
101 'Checkbox is checked.');
102
103 this.test.assert(this.cell_element_exists(index,
104 '.widget-area .widget-subarea .widget-hbox-single .widget-hlabel'),
105 'Checkbox label exists.');
106
107 this.test.assert(this.cell_element_function(index,
108 '.widget-area .widget-subarea .widget-hbox-single .widget-hlabel', 'html')=="Title",
109 'Checkbox labeled correctly.');
110
111 this.test.assert(this.cell_element_exists(index,
112 '.widget-area .widget-subarea div button'),
113 'Toggle button exists.');
114
115 this.test.assert(this.cell_element_function(index,
116 '.widget-area .widget-subarea div button', 'html')=="Title",
117 'Toggle button labeled correctly.');
118
119 this.test.assert(this.cell_element_function(index,
120 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
121 'Toggle button is toggled.');
122
123 });
124
125 index = this.append_cell(
126 'bool_widget.value = False\n' +
127 'print("Success")');
128 this.execute_cell_then(index, function(index){
129
130 this.test.assert(this.get_output_cell(index).text == 'Success\n',
131 'Change bool widget value cell executed with correct output.');
132
133 this.test.assert(! this.cell_element_function(bool_index,
134 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
135 'Checkbox is not checked. (1)');
136
137 this.test.assert(! this.cell_element_function(bool_index,
138 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
139 'Toggle button is not toggled. (1)');
140
141 // Try toggling the bool by clicking on the toggle button.
142 this.cell_element_function(bool_index, '.widget-area .widget-subarea div button', 'click');
143
144 this.test.assert(this.cell_element_function(bool_index,
145 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
146 'Checkbox is checked. (2)');
147
148 this.test.assert(this.cell_element_function(bool_index,
149 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
150 'Toggle button is toggled. (2)');
151
152 // Try toggling the bool by clicking on the checkbox.
153 this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click');
154
155 this.test.assert(! this.cell_element_function(bool_index,
156 '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']),
157 'Checkbox is not checked. (3)');
158
159 this.test.assert(! this.cell_element_function(bool_index,
160 '.widget-area .widget-subarea div button', 'hasClass', ['active']),
161 'Toggle button is not toggled. (3)');
162
163 });
164
165 // Test button widget //////////////////////////////////////////////////////
166
167 var button_index = this.append_cell(
168 'button = widgets.ButtonWidget(description="Title")\n' +
169 'display(button)\n'+
170 'print("Success")\n' +
171 'def handle_click(sender):\n' +
172 ' print("Clicked")\n' +
173 'button.on_click(handle_click)');
174 this.execute_cell_then(button_index, function(index){
175
176 this.test.assert(this.get_output_cell(index).text == 'Success\n',
177 'Create button cell executed with correct output.');
178
179 this.test.assert(this.cell_element_exists(index,
180 '.widget-area .widget-subarea'),
181 'Widget subarea exists.');
182
183 this.test.assert(this.cell_element_exists(index,
184 '.widget-area .widget-subarea button'),
185 'Widget button exists.');
186
187 this.test.assert(this.cell_element_function(index,
188 '.widget-area .widget-subarea button', 'html')=='Title',
189 'Set button description.');
190
191 this.cell_element_function(index,
192 '.widget-area .widget-subarea button', 'click');
193 });
194
195 this.wait(500); // Wait for click to execute in kernel and write output
196
197 this.then(function () {
198 this.test.assert(this.get_output_cell(button_index, 1).text == 'Clicked\n',
199 'Button click event fires.');
200 });
201
202 // Close the button widget asynchronisly.
203 index = this.append_cell('button.close()\n');
204 this.execute_cell(index);
205
206 this.wait(500); // Wait for the button to close.
207
208 this.then(function(){
209 this.test.assert(! this.cell_element_exists(button_index,
210 '.widget-area .widget-subarea button'),
211 'Widget button doesn\'t exists.');
212 });
213
214 // Test container widget ///////////////////////////////////////////////////
215 var container_index = this.append_cell(
216 'container = widgets.ContainerWidget()\n' +
217 'button = widgets.ButtonWidget(parent=container)\n'+
218 'display(container)\n'+
219 'container.add_class("my-test-class")\n'+
220 'print("Success")\n');
221 this.execute_cell_then(container_index, function(index){
222
223 this.test.assert(this.get_output_cell(index).text == 'Success\n',
224 'Create container cell executed with correct output.');
225
226 this.test.assert(this.cell_element_exists(index,
227 '.widget-area .widget-subarea'),
228 'Widget subarea exists.');
229
230 this.test.assert(this.cell_element_exists(index,
231 '.widget-area .widget-subarea .widget-container'),
232 'Widget container exists.');
233
234 this.test.assert(this.cell_element_exists(index,
235 '.widget-area .widget-subarea .my-test-class'),
236 'add_class works.');
237
238 this.test.assert(this.cell_element_exists(index,
239 '.widget-area .widget-subarea .my-test-class button'),
240 'Container parent/child relationship works.');
241 });
242
243 index = this.append_cell(
244 'container.set_css("display", "none")\n'+
245 'print("Success")\n');
246 this.execute_cell_then(index, function(index){
247
248 this.test.assert(this.get_output_cell(index).text == 'Success\n',
249 'Set container class CSS cell executed with correct output.');
250
251 this.test.assert(this.cell_element_function(container_index,
252 '.widget-area .widget-subarea .my-test-class', 'css', ['display'])=='none',
253 'set_css works.');
254 });
255
256 index = this.append_cell(
257 'container.remove_class("my-test-class")\n'+
258 'print("Success")\n');
259 this.execute_cell_then(index, function(index){
260
261 this.test.assert(this.get_output_cell(index).text == 'Success\n',
262 'Remove container class cell executed with correct output.');
263
264 this.test.assert(! this.cell_element_exists(container_index,
265 '.widget-area .widget-subarea .my-test-class'),
266 'remove_class works.');
267 });
268
269 index = this.append_cell(
270 'display(button)\n'+
271 'print("Success")\n');
272 this.execute_cell_then(index, function(index){
273
274 this.test.assert(this.get_output_cell(index).text == 'Success\n',
275 'Display container child executed with correct output.');
276
277 this.test.assert(! this.cell_element_exists(index,
278 '.widget-area .widget-subarea .widget-container'),
279 'Parent container not displayed.');
280
281 this.test.assert(this.cell_element_exists(index,
282 '.widget-area .widget-subarea button'),
283 'Child displayed.');
284 });
285
286 // Test float range widget /////////////////////////////////////////////////
287 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
288 var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text';
289
290 var floatrange_index = this.append_cell(
291 'floatrange = widgets.FloatRangeWidget()\n' +
292 'display(floatrange)\n' +
293 'display(floatrange, view_name="FloatTextView")\n' +
294 'print("Success")\n');
295 this.execute_cell_then(floatrange_index, function(index){
296
297 this.test.assert(this.get_output_cell(index).text == 'Success\n',
298 'Create float range cell executed with correct output.');
299
300 this.test.assert(this.cell_element_exists(index,
301 '.widget-area .widget-subarea'),
302 'Widget subarea exists.');
303
304 this.test.assert(this.cell_element_exists(index, slider_query),
305 'Widget slider exists.');
306
307 this.test.assert(this.cell_element_exists(index, float_text_query),
308 'Widget float textbox exists.');
309 });
310
311 index = this.append_cell(
312 'floatrange.max = 50.0\n' +
313 'floatrange.min = -50.0\n' +
314 'floatrange.value = 25.0\n' +
315 'print("Success")\n');
316 this.execute_cell_then(index, function(index){
317
318 this.test.assert(this.get_output_cell(index).text == 'Success\n',
319 'Float range properties cell executed with correct output.');
320
321 this.test.assert(this.cell_element_exists(floatrange_index, slider_query),
322 'Widget slider exists.');
323
324 this.test.assert(this.cell_element_function(floatrange_index, slider_query,
325 'slider', ['value']) == 25.0,
326 'Slider set to Python value.');
327
328 this.test.assert(this.cell_element_function(floatrange_index, float_text_query,
329 'val') == 25.0, 'Float textbox set to Python value.');
330
331 // Clear the float textbox value and then set it to 1 by emulating
332 // keyboard presses.
333 this.cell_element_function(floatrange_index, float_text_query, 'val', ['']);
334 this.sendKeys(float_text_query, '1');
335 });
336
337 this.wait(500); // Wait for change to execute in kernel
338
339 index = this.append_cell('print(floatrange.value)\n');
340 this.execute_cell_then(index, function(index){
341 this.test.assert(this.get_output_cell(index).text == '1.0\n',
342 'Float textbox set float range value');
343
344 // Clear the float textbox value and then set it to 120 by emulating
345 // keyboard presses.
346 this.cell_element_function(floatrange_index, float_text_query, 'val', ['']);
347 this.sendKeys(float_text_query, '120');
348 });
349
350 this.wait(500); // Wait for change to execute in kernel
351
352 index = this.append_cell('print(floatrange.value)\n');
353 this.execute_cell_then(index, function(index){
354 this.test.assert(this.get_output_cell(index).text == '50.0\n',
355 'Float textbox value bound');
356
357 // Clear the float textbox value and then set it to 'hello world' by
358 // emulating keyboard presses. 'hello world' should get filtered...
359 this.cell_element_function(floatrange_index, float_text_query, 'val', ['']);
360 this.sendKeys(float_text_query, 'hello world');
361 });
362
363 this.wait(500); // Wait for change to execute in kernel
364
365 index = this.append_cell('print(floatrange.value)\n');
366 this.execute_cell_then(index, function(index){
367 this.test.assert(this.get_output_cell(index).text == '50.0\n',
368 'Invalid float textbox characters ignored');
369 });
370
371 // Test float widget ///////////////////////////////////////////////////////
372 var float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
373
374 var float_index = this.append_cell(
375 'float_widget = widgets.FloatWidget()\n' +
376 'display(float_widget)\n' +
377 'float_widget.add_class("my-second-float-text")\n' +
378 'print("Success")\n');
379 this.execute_cell_then(float_index, function(index){
380
381 this.test.assert(this.get_output_cell(index).text == 'Success\n',
382 'Create float cell executed with correct output.');
383
384 this.test.assert(this.cell_element_exists(index,
385 '.widget-area .widget-subarea'),
386 'Widget subarea exists.');
387
388 this.test.assert(this.cell_element_exists(index, float_text_query_2),
389 'Widget float textbox exists.');
390
391 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
392 this.sendKeys(float_text_query_2, '1.05');
393 });
394
395 this.wait(500); // Wait for change to execute in kernel
396
397 index = this.append_cell('print(float_widget.value)\n');
398 this.execute_cell_then(index, function(index){
399 this.test.assert(this.get_output_cell(index).text == '1.05\n',
400 'Float textbox value set.');
401 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
402 this.sendKeys(float_text_query_2, '123456789.0');
403 });
404
405 this.wait(500); // Wait for change to execute in kernel
406
407 index = this.append_cell('print(float_widget.value)\n');
408 this.execute_cell_then(index, function(index){
409 this.test.assert(this.get_output_cell(index).text == '123456789.0\n',
410 'Long float textbox value set (probably triggers throttling).');
411 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
412 this.sendKeys(float_text_query_2, '12hello');
413 });
414
415 this.wait(500); // Wait for change to execute in kernel
416
417 index = this.append_cell('print(float_widget.value)\n');
418 this.execute_cell_then(index, function(index){
419 this.test.assert(this.get_output_cell(index).text == '12.0\n',
420 'Invald float textbox value caught and filtered.');
421 });
422
423 // Test image widget ///////////////////////////////////////////////////////
424
425 // Get the temporary directory that the test server is running in.
426 var cwd = '';
427 index = this.append_cell('!echo $(pwd)');
428 this.execute_cell_then(index, function(index){
429 cwd = this.get_output_cell(index).text.trim();
430 });
431
432 test_jpg = '/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wgARCAABAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAAA//EABUBAQEAAAAAAAAAAAAAAAAAAAME/9oADAMBAAIQAxAAAAECv//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQn//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z';
433 test_results = '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAyADIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDi6KKK+ZP3EKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//Z';
434
435 var image_index = this.append_cell(
436 'import base64\n' +
437 'data = base64.b64decode("' + test_jpg + '")\n' +
438 'image = widgets.ImageWidget()\n' +
439 'image.image_format = "jpeg"\n' +
440 'image.value = data\n' +
441 'image.width = "50px"\n' +
442 'image.height = "50px"\n' +
443 // Set css that will make the image render within the PhantomJS visible
444 // window. If we don't do this, the captured image will be black.
445 'image.set_css({"background": "blue", "z-index": "9999", "position": "fixed", "top": "0px", "left": "0px"})\n' +
446 'display(image)\n' +
447 'image.add_class("my-test-image")\n' +
448 'print("Success")\n');
449 this.execute_cell_then(image_index, function(index){
450
451 this.test.assert(this.get_output_cell(index).text == 'Success\n',
452 'Create image executed with correct output.');
453
454 this.test.assert(this.cell_element_exists(index,
455 '.widget-area .widget-subarea'),
456 'Widget subarea exists.');
457
458 this.test.assert(this.cell_element_exists(index,
459 '.widget-area .widget-subarea img'),
460 'Image exists.');
461
462 // Capture a screenshot of the img element as a base64 string.
463 var fs = require('fs');
464 capture_filename = cwd + fs.separator + 'captured.jpg';
465 this.captureSelector(capture_filename, '.my-test-image');
466 var stream = fs.open(capture_filename, 'rb');
467 var captured = btoa(stream.read());
468 stream.close()
469 fs.remove(capture_filename);
470
471 // Uncomment line below to output captured image data to a text file.
472 // fs.write('./captured.txt', captured, 'w');
473
474 this.test.assert(test_results==captured, "Red image data displayed correctly.");
475 });
476
477 // Test int range widget /////////////////////////////////////////////////
478 var int_text_query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
479
480 var intrange_index = this.append_cell(
481 'intrange = widgets.IntRangeWidget()\n' +
482 'display(intrange, view_name="IntTextView")\n' +
483 'intrange.add_class("my-second-num-test-text")\n' +
484 'display(intrange)\n' +
485 'print("Success")\n');
486 this.execute_cell_then(intrange_index, function(index){
487
488 this.test.assert(this.get_output_cell(index).text == 'Success\n',
489 'Create int range cell executed with correct output.');
490
491 this.test.assert(this.cell_element_exists(index,
492 '.widget-area .widget-subarea'),
493 'Widget subarea exists.');
494
495 this.test.assert(this.cell_element_exists(index, slider_query),
496 'Widget slider exists.');
497
498 this.test.assert(this.cell_element_exists(index, int_text_query),
499 'Widget int textbox exists.');
500 });
501
502 index = this.append_cell(
503 'intrange.max = 50\n' +
504 'intrange.min = -50\n' +
505 'intrange.value = 25\n' +
506 'print("Success")\n');
507 this.execute_cell_then(index, function(index){
508
509 this.test.assert(this.get_output_cell(index).text == 'Success\n',
510 'Int range properties cell executed with correct output.');
511
512 this.test.assert(this.cell_element_exists(intrange_index, slider_query),
513 'Widget slider exists.');
514
515 this.test.assert(this.cell_element_function(intrange_index, slider_query,
516 'slider', ['value']) == 25,
517 'Slider set to Python value.');
518
519 this.test.assert(this.cell_element_function(intrange_index, int_text_query,
520 'val') == 25, 'Int textbox set to Python value.');
521
522 // Clear the int textbox value and then set it to 1 by emulating
523 // keyboard presses.
524 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
525 this.sendKeys(int_text_query, '1');
526 });
527
528 this.wait(500); // Wait for change to execute in kernel
529
530 index = this.append_cell('print(intrange.value)\n');
531 this.execute_cell_then(index, function(index){
532 this.test.assert(this.get_output_cell(index).text == '1\n',
533 'Int textbox set int range value');
534
535 // Clear the int textbox value and then set it to 120 by emulating
536 // keyboard presses.
537 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
538 this.sendKeys(int_text_query, '120');
539 });
540
541 this.wait(500); // Wait for change to execute in kernel
542
543 index = this.append_cell('print(intrange.value)\n');
544 this.execute_cell_then(index, function(index){
545 this.test.assert(this.get_output_cell(index).text == '50\n',
546 'Int textbox value bound');
547
548 // Clear the int textbox value and then set it to 'hello world' by
549 // emulating keyboard presses. 'hello world' should get filtered...
550 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
551 this.sendKeys(int_text_query, 'hello world');
552 });
553
554 this.wait(500); // Wait for change to execute in kernel
555
556 index = this.append_cell('print(intrange.value)\n');
557 this.execute_cell_then(index, function(index){
558 this.test.assert(this.get_output_cell(index).text == '50\n',
559 'Invalid int textbox characters ignored');
560 });
561
562 // Test int widget ///////////////////////////////////////////////////////
563 var int_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
564
565 var int_index = this.append_cell(
566 'int_widget = widgets.IntWidget()\n' +
567 'display(int_widget)\n' +
568 'int_widget.add_class("my-second-int-text")\n' +
569 'print("Success")\n');
570 this.execute_cell_then(int_index, function(index){
571
572 this.test.assert(this.get_output_cell(index).text == 'Success\n',
573 'Create int cell executed with correct output.');
574
575 this.test.assert(this.cell_element_exists(index,
576 '.widget-area .widget-subarea'),
577 'Widget subarea exists.');
578
579 this.test.assert(this.cell_element_exists(index, int_text_query_2),
580 'Widget int textbox exists.');
581
582 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
583 this.sendKeys(int_text_query_2, '1.05');
584 });
585
586 this.wait(500); // Wait for change to execute in kernel
587
588 index = this.append_cell('print(int_widget.value)\n');
589 this.execute_cell_then(index, function(index){
590 this.test.assert(this.get_output_cell(index).text == '1\n',
591 'Int textbox value set.');
592 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
593 this.sendKeys(int_text_query_2, '123456789');
594 });
595
596 this.wait(500); // Wait for change to execute in kernel
597
598 index = this.append_cell('print(int_widget.value)\n');
599 this.execute_cell_then(index, function(index){
600 this.test.assert(this.get_output_cell(index).text == '123456789\n',
601 'Long int textbox value set (probably triggers throttling).');
602 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
603 this.sendKeys(int_text_query_2, '12hello');
604 });
605
606 this.wait(500); // Wait for change to execute in kernel
607
608 index = this.append_cell('print(int_widget.value)\n');
609 this.execute_cell_then(index, function(index){
610 this.test.assert(this.get_output_cell(index).text == '12\n',
611 'Invald int textbox value caught and filtered.');
612 });
613
614
615 // Test multicontainer widget ////////////////////////////////////////////
616
617 // Test tab view
618 var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs';
619 var multicontainer1_index = this.append_cell(
620 'multicontainer = widgets.MulticontainerWidget()\n' +
621 'page1 = widgets.StringWidget(parent=multicontainer)\n' +
622 'page2 = widgets.StringWidget(parent=multicontainer)\n' +
623 'page3 = widgets.StringWidget(parent=multicontainer)\n' +
624 'display(multicontainer)\n' +
625 'multicontainer.selected_index = 0\n' +
626 'print("Success")\n');
627 this.execute_cell_then(multicontainer1_index, function(index){
628
629 this.test.assert(this.get_output_cell(index).text == 'Success\n',
630 'Create multicontainer cell executed with correct output. (1)');
631
632 this.test.assert(this.cell_element_exists(index,
633 '.widget-area .widget-subarea'),
634 'Widget subarea exists.');
635
636 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
637 'Widget tab list exists.');
638
639 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
640 'First widget tab list exists.');
641
642 // JQuery selector is 1 based
643 this.click(multicontainer1_query + ' li:nth-child(2) a')
644 });
645
646 this.wait(500); // Wait for change to execute in kernel
647
648 index = this.append_cell(
649 'print(multicontainer.selected_index)\n' +
650 'multicontainer.selected_index = 2'); // 0 based
651 this.execute_cell_then(index, function(index){
652 this.test.assert(this.get_output_cell(index).text == '1\n', // 0 based
653 'selected_index property updated with tab change.');
654
655 // JQuery selector is 1 based
656 this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(1)', 'hasClass', ['active']),
657 "Tab 1 is not selected.")
658 this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(2)', 'hasClass', ['active']),
659 "Tab 2 is not selected.")
660 this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(3)', 'hasClass', ['active']),
661 "Tab 3 is selected.")
662 });
663
664 index = this.append_cell('multicontainer.set_title(1, "hello")\nprint("Success")'); // 0 based
665 this.execute_cell_then(index, function(index){
666 this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query +
667 ' li:nth-child(2) a', 'html') == 'hello',
668 'Tab page title set (after display).');
669 });
670
671 // Test accordion view
672 var multicontainer2_query = '.widget-area .widget-subarea .accordion';
673 var multicontainer2_index = this.append_cell(
674 'multicontainer = widgets.MulticontainerWidget()\n' +
675 'page1 = widgets.StringWidget(parent=multicontainer)\n' +
676 'page2 = widgets.StringWidget(parent=multicontainer)\n' +
677 'page3 = widgets.StringWidget(parent=multicontainer)\n' +
678 'multicontainer.set_title(2, "good")\n' +
679 'display(multicontainer, view_name="AccordionView")\n' +
680 'multicontainer.selected_index = 0\n' +
681 'print("Success")\n');
682 this.execute_cell_then(multicontainer2_index, function(index){
683
684 this.test.assert(this.get_output_cell(index).text == 'Success\n',
685 'Create multicontainer cell executed with correct output. (2)');
686
687 this.test.assert(this.cell_element_exists(index,
688 '.widget-area .widget-subarea'),
689 'Widget subarea exists.');
690
691 this.test.assert(this.cell_element_exists(index, multicontainer2_query),
692 'Widget accordion exists.');
693
694 this.test.assert(this.cell_element_exists(index, multicontainer2_query +
695 ' .accordion-group:nth-child(1) .accordion-body'),
696 'First accordion page exists.');
697
698 // JQuery selector is 1 based
699 this.test.assert(this.cell_element_function(index, multicontainer2_query +
700 ' .accordion-group:nth-child(3) .accordion-heading .accordion-toggle',
701 'html')=='good', 'Accordion page title set (before display).');
702
703 // JQuery selector is 1 based
704 this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle');
705 });
706
707 this.wait(500); // Wait for change to execute in kernel
708
709 index = this.append_cell('print(multicontainer.selected_index)'); // 0 based
710 this.execute_cell_then(index, function(index){
711 this.test.assert(this.get_output_cell(index).text == '1\n', // 0 based
712 'selected_index property updated with tab change.');
713 });
714
715 // Test selection widget /////////////////////////////////////////////////
716 var combo_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group .widget-combo-btn'
717 var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]'
718 var radio_selector = '.widget-area .widget-subarea .widget-hbox .vbox'
719 var list_selector = '.widget-area .widget-subarea .widget-hbox .widget-listbox'
720
721 var selection_index;
722 var selection_values = 'abcd';
723 var check_state = function(context, index, state){
724 if (0 <= index && index < selection_values.length) {
725 var multibtn_state = context.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(' + (index + 1) + ')', 'hasClass', ['active']);
726 var radio_state = context.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(' + (index + 1) + ') input', 'prop', ['checked']);
727 var list_val = context.cell_element_function(selection_index, list_selector, 'val');
728 var combo_val = context.cell_element_function(selection_index, combo_selector, 'html');
729
730 var val = selection_values.charAt(index);
731 var list_state = (val == list_val);
732 var combo_state = (val == combo_val);
733
734 return multibtn_state == state &&
735 radio_state == state &&
736 list_state == state &&
737 combo_state == state;
738 }
739 return true;
740 }
741
742 var verify_selection = function(context, index){
743 for (var i = 0; i < selection_values.length; i++) {
744 if (!check_state(context, i, i==index)) {
745 return false;
746 }
747 }
748 return true;
749 }
750
751 selection_index = this.append_cell(
752 'selection = widgets.SelectionWidget(values=["' + selection_values + '"[i] for i in range(4)])\n' +
753 'display(selection)\n' +
754 'display(selection, view_name="ToggleButtonsView")\n' +
755 'display(selection, view_name="RadioButtonsView")\n' +
756 'display(selection, view_name="ListBoxView")\n' +
757 'print("Success")\n');
758 this.execute_cell_then(selection_index, function(index){
759 this.test.assert(this.get_output_cell(index).text == 'Success\n',
760 'Create selection cell executed with correct output.');
761
762 this.test.assert(this.cell_element_exists(index,
763 '.widget-area .widget-subarea'),
764 'Widget subarea exists.');
765
766 this.test.assert(this.cell_element_exists(index, combo_selector),
767 'Widget combobox exists.');
768
769 this.test.assert(this.cell_element_exists(index, multibtn_selector),
770 'Widget multibutton exists.');
771
772 this.test.assert(this.cell_element_exists(index, radio_selector),
773 'Widget radio buttons exists.');
774
775 this.test.assert(this.cell_element_exists(index, list_selector),
776 'Widget list exists.');
777
778 // Verify that no items are selected.
779 this.test.assert(verify_selection(this, -1), 'No items selected.');
780 });
781
782 index = this.append_cell(
783 'selection.value = "a"\n' +
784 'print("Success")\n');
785 this.execute_cell_then(index, function(index){
786 this.test.assert(this.get_output_cell(index).text == 'Success\n',
787 'Python select item executed with correct output.');
788
789 // Verify that the first item is selected.
790 this.test.assert(verify_selection(this, 0), 'Python selected');
791
792 // Verify that selecting a radio button updates all of the others.
793 this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click');
794 this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.');
795
796 // Verify that selecting a list option updates all of the others.
797 this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click');
798 this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.');
799
800 // Verify that selecting a multibutton option updates all of the others.
801 this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click');
802 this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.');
803
804 // Verify that selecting a combobox option updates all of the others.
805 this.cell_element_function(selection_index, '.widget-area .widget-subarea .widget-hbox-single .btn-group ul.dropdown-menu li:nth-child(3) a', 'click');
806 this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.');
807 });
808
809 this.wait(500); // Wait for change to execute in kernel
810
811 index = this.append_cell(
812 'print(selection.value)\n' +
813 'selection.values.append("z")\n' +
814 'selection.send_state()\n' +
815 'selection.value = "z"');
816 this.execute_cell_then(index, function(index){
817
818 // Verify that selecting a combobox option updates all of the others.
819 this.test.assert(verify_selection(this, 4), 'Item added to selection widget.');
820 });
821
822 // Test string widget //////////////////////////////////////////////////////
823 var string_index = this.append_cell(
824 'string_widget = widgets.StringWidget()\n' +
825 'display(string_widget)\n'+
826 'display(string_widget, view_name="TextAreaView")\n' +
827 'display(string_widget, view_name="HTMLView")\n' +
828 'display(string_widget, view_name="LatexView")\n' +
829 'string_widget.value = "xyz"\n' +
830 'print("Success")');
831 this.execute_cell_then(string_index, function(index){
832
833 this.test.assert(this.get_output_cell(index).text == 'Success\n',
834 'Create string widget cell executed with correct output.');
835
836 this.test.assert(this.cell_element_exists(index,
837 '.widget-area .widget-subarea'),
838 'Widget subarea exists.');
839
840 this.test.assert(this.cell_element_exists(index,
841 '.widget-area .widget-subarea .widget-hbox-single input[type=text]'),
842 'Textbox exists.');
843
844 this.test.assert(this.cell_element_exists(index,
845 '.widget-area .widget-subarea .widget-hbox textarea'),
846 'Textarea exists.');
847
848 this.test.assert(this.cell_element_function(index,
849 '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='xyz',
850 'Python set textarea value.');
851
852 this.test.assert(this.cell_element_function(index,
853 '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='xyz',
854 'Python set textbox value.');
855
856 this.cell_element_function(index,
857 '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val', [''])
858 this.sendKeys('.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'abc');
859
860 this.test.assert(this.cell_element_function(index,
861 '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='abc',
862 'Textarea updated to textbox contents.');
863
864 this.cell_element_function(index,
865 '.widget-area .widget-subarea .widget-hbox textarea', 'val', ['']);
866 this.sendKeys('.widget-area .widget-subarea .widget-hbox textarea', '$\\LaTeX{}$');
867
868 this.test.assert(this.cell_element_function(index,
869 '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='$\\LaTeX{}$',
870 'Textbox updated to textarea contents.');
871 });
872
873 this.wait(500); // Wait for change to execute in kernel
874
875 index = this.append_cell('print(string_widget.value)');
876 this.execute_cell_then(index, function(index){
877 this.test.assert(this.get_output_cell(index).text == '$\\LaTeX{}$\n',
878 'Python updated with correct string widget value.');
879
880 this.test.assert(this.cell_element_exists(string_index,
881 '.widget-area .widget-subarea div span.MathJax_Preview'),
882 'MathJax parsed the LaTeX successfully.');
883 });
884
885 // Test throttling /////////////////////////////////////////////////////////
886 throttle_index = this.append_cell(
78 throttle_index = this.append_cell(
887 'import time\n' +
79 'import time\n' +
888 'textbox = widgets.StringWidget()\n' +
80 'textbox = widgets.StringWidget()\n' +
General Comments 0
You need to be logged in to leave comments. Login now