Show More
@@ -0,0 +1,118 | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | var that = this; | |||
|
5 | var cell_is_deletable = function (index) { | |||
|
6 | // Get the deletable status of a cell. | |||
|
7 | return that.evaluate(function (index) { | |||
|
8 | var cell = IPython.notebook.get_cell(index); | |||
|
9 | return cell.is_deletable(); | |||
|
10 | }, index); | |||
|
11 | }; | |||
|
12 | ||||
|
13 | var a = 'print("a")'; | |||
|
14 | var index = this.append_cell(a); | |||
|
15 | ||||
|
16 | var b = 'print("b")'; | |||
|
17 | index = this.append_cell(b); | |||
|
18 | ||||
|
19 | var c = 'print("c")'; | |||
|
20 | index = this.append_cell(c); | |||
|
21 | ||||
|
22 | this.thenEvaluate(function() { | |||
|
23 | IPython.notebook.get_cell(1).metadata.deletable = false; | |||
|
24 | IPython.notebook.get_cell(2).metadata.deletable = 0; | |||
|
25 | IPython.notebook.get_cell(3).metadata.deletable = true; | |||
|
26 | }); | |||
|
27 | ||||
|
28 | this.then(function () { | |||
|
29 | // Check deletable status of the cells | |||
|
30 | this.test.assert(cell_is_deletable(0), 'Cell 0 is deletable'); | |||
|
31 | this.test.assert(!cell_is_deletable(1), 'Cell 1 is not deletable'); | |||
|
32 | this.test.assert(!cell_is_deletable(2), 'Cell 2 is not deletable'); | |||
|
33 | this.test.assert(cell_is_deletable(3), 'Cell 3 is deletable'); | |||
|
34 | }); | |||
|
35 | ||||
|
36 | // Try to delete cell 0 (should succeed) | |||
|
37 | this.then(function () { | |||
|
38 | this.select_cell(0); | |||
|
39 | this.trigger_keydown('esc'); | |||
|
40 | this.trigger_keydown('d', 'd'); | |||
|
41 | this.test.assertEquals(this.get_cells_length(), 3, 'Delete cell 0: There are now 3 cells'); | |||
|
42 | this.test.assertEquals(this.get_cell_text(0), a, 'Delete cell 0: Cell 1 is now cell 0'); | |||
|
43 | this.test.assertEquals(this.get_cell_text(1), b, 'Delete cell 0: Cell 2 is now cell 1'); | |||
|
44 | this.test.assertEquals(this.get_cell_text(2), c, 'Delete cell 0: Cell 3 is now cell 2'); | |||
|
45 | this.validate_notebook_state('dd', 'command', 0); | |||
|
46 | }); | |||
|
47 | ||||
|
48 | // Try to delete cell 0 (should fail) | |||
|
49 | this.then(function () { | |||
|
50 | this.select_cell(0); | |||
|
51 | this.trigger_keydown('d', 'd'); | |||
|
52 | this.test.assertEquals(this.get_cells_length(), 3, 'Delete cell 0: There are still 3 cells'); | |||
|
53 | this.test.assertEquals(this.get_cell_text(0), a, 'Delete cell 0: Cell 0 was not deleted'); | |||
|
54 | this.test.assertEquals(this.get_cell_text(1), b, 'Delete cell 0: Cell 1 was not affected'); | |||
|
55 | this.test.assertEquals(this.get_cell_text(2), c, 'Delete cell 0: Cell 2 was not affected'); | |||
|
56 | this.validate_notebook_state('dd', 'command', 0); | |||
|
57 | }); | |||
|
58 | ||||
|
59 | // Try to delete cell 1 (should fail) | |||
|
60 | this.then(function () { | |||
|
61 | this.select_cell(1); | |||
|
62 | this.trigger_keydown('d', 'd'); | |||
|
63 | this.test.assertEquals(this.get_cells_length(), 3, 'Delete cell 1: There are still 3 cells'); | |||
|
64 | this.test.assertEquals(this.get_cell_text(0), a, 'Delete cell 1: Cell 0 was not affected'); | |||
|
65 | this.test.assertEquals(this.get_cell_text(1), b, 'Delete cell 1: Cell 1 was not deleted'); | |||
|
66 | this.test.assertEquals(this.get_cell_text(2), c, 'Delete cell 1: Cell 2 was not affected'); | |||
|
67 | this.validate_notebook_state('dd', 'command', 1); | |||
|
68 | }); | |||
|
69 | ||||
|
70 | // Try to delete cell 2 (should succeed) | |||
|
71 | this.then(function () { | |||
|
72 | this.select_cell(2); | |||
|
73 | this.trigger_keydown('d', 'd'); | |||
|
74 | this.test.assertEquals(this.get_cells_length(), 2, 'Delete cell 2: There are now 2 cells'); | |||
|
75 | this.test.assertEquals(this.get_cell_text(0), a, 'Delete cell 2: Cell 0 was not affected'); | |||
|
76 | this.test.assertEquals(this.get_cell_text(1), b, 'Delete cell 2: Cell 1 was not affected'); | |||
|
77 | this.validate_notebook_state('dd', 'command', 1); | |||
|
78 | }); | |||
|
79 | ||||
|
80 | // Change the deletable status of the last two cells | |||
|
81 | this.thenEvaluate(function() { | |||
|
82 | IPython.notebook.get_cell(0).metadata.deletable = true; | |||
|
83 | IPython.notebook.get_cell(1).metadata.deletable = true; | |||
|
84 | }); | |||
|
85 | ||||
|
86 | this.then(function () { | |||
|
87 | // Check deletable status of the cells | |||
|
88 | this.test.assert(cell_is_deletable(0), 'Cell 0 is deletable'); | |||
|
89 | this.test.assert(cell_is_deletable(1), 'Cell 1 is deletable'); | |||
|
90 | ||||
|
91 | // Try to delete cell 1 (should succeed) | |||
|
92 | this.select_cell(1); | |||
|
93 | this.trigger_keydown('d', 'd'); | |||
|
94 | this.test.assertEquals(this.get_cells_length(), 1, 'Delete cell 1: There is now 1 cell'); | |||
|
95 | this.test.assertEquals(this.get_cell_text(0), a, 'Delete cell 1: Cell 0 was not affected'); | |||
|
96 | this.validate_notebook_state('dd', 'command', 0); | |||
|
97 | ||||
|
98 | // Try to delete the last cell (should succeed) | |||
|
99 | this.select_cell(0); | |||
|
100 | this.trigger_keydown('d', 'd'); | |||
|
101 | this.test.assertEquals(this.get_cells_length(), 1, 'Delete last cell: There is still 1 cell'); | |||
|
102 | this.test.assertEquals(this.get_cell_text(0), "", 'Delete last cell: Cell 0 was deleted'); | |||
|
103 | this.validate_notebook_state('dd', 'command', 0); | |||
|
104 | }); | |||
|
105 | ||||
|
106 | // Make sure copied cells are deletable | |||
|
107 | this.thenEvaluate(function() { | |||
|
108 | IPython.notebook.get_cell(0).metadata.deletable = false; | |||
|
109 | }); | |||
|
110 | this.then(function () { | |||
|
111 | this.select_cell(0); | |||
|
112 | this.trigger_keydown('c', 'v'); | |||
|
113 | this.test.assertEquals(this.get_cells_length(), 2, 'Copy cell: There are 2 cells'); | |||
|
114 | this.test.assert(!cell_is_deletable(0), 'Cell 0 is not deletable'); | |||
|
115 | this.test.assert(cell_is_deletable(1), 'Cell 1 is deletable'); | |||
|
116 | this.validate_notebook_state('cv', 'command', 1); | |||
|
117 | }); | |||
|
118 | }); |
@@ -1,6 +1,33 | |||||
1 |
|
1 | |||
2 | // Test |
|
2 | // Test | |
3 | casper.notebook_test(function () { |
|
3 | casper.notebook_test(function () { | |
|
4 | var a = 'ab\ncd'; | |||
|
5 | var b = 'print("b")'; | |||
|
6 | var c = 'print("c")'; | |||
|
7 | ||||
|
8 | var that = this; | |||
|
9 | var cell_is_mergeable = function (index) { | |||
|
10 | // Get the mergeable status of a cell. | |||
|
11 | return that.evaluate(function (index) { | |||
|
12 | var cell = IPython.notebook.get_cell(index); | |||
|
13 | return cell.is_mergeable(); | |||
|
14 | }, index); | |||
|
15 | }; | |||
|
16 | ||||
|
17 | var cell_is_splittable = function (index) { | |||
|
18 | // Get the splittable status of a cell. | |||
|
19 | return that.evaluate(function (index) { | |||
|
20 | var cell = IPython.notebook.get_cell(index); | |||
|
21 | return cell.is_splittable(); | |||
|
22 | }, index); | |||
|
23 | }; | |||
|
24 | ||||
|
25 | var close_dialog = function () { | |||
|
26 | this.evaluate(function(){ | |||
|
27 | $('div.modal-footer button.btn-default').click(); | |||
|
28 | }, {}); | |||
|
29 | }; | |||
|
30 | ||||
4 | this.then(function () { |
|
31 | this.then(function () { | |
5 | // Split and merge cells |
|
32 | // Split and merge cells | |
6 | this.select_cell(0); |
|
33 | this.select_cell(0); | |
@@ -16,6 +43,93 casper.notebook_test(function () { | |||||
16 | this.select_cell(0); // Move up to cell 0 |
|
43 | this.select_cell(0); // Move up to cell 0 | |
17 | this.trigger_keydown('shift-m'); // Merge |
|
44 | this.trigger_keydown('shift-m'); // Merge | |
18 | this.validate_notebook_state('merge', 'command', 0); |
|
45 | this.validate_notebook_state('merge', 'command', 0); | |
19 |
this.test.assertEquals(this.get_cell_text(0), |
|
46 | this.test.assertEquals(this.get_cell_text(0), a, 'merge; Verify that cell 0 has the merged contents.'); | |
|
47 | }); | |||
|
48 | ||||
|
49 | // add some more cells and test splitting/merging when a cell is not deletable | |||
|
50 | this.then(function () { | |||
|
51 | this.append_cell(b); | |||
|
52 | this.append_cell(c); | |||
|
53 | }); | |||
|
54 | ||||
|
55 | this.thenEvaluate(function() { | |||
|
56 | IPython.notebook.get_cell(1).metadata.deletable = false; | |||
|
57 | }); | |||
|
58 | ||||
|
59 | // Check that merge/split status are correct | |||
|
60 | this.then(function () { | |||
|
61 | this.test.assert(cell_is_splittable(0), 'Cell 0 is splittable'); | |||
|
62 | this.test.assert(cell_is_mergeable(0), 'Cell 0 is mergeable'); | |||
|
63 | this.test.assert(!cell_is_splittable(1), 'Cell 1 is not splittable'); | |||
|
64 | this.test.assert(!cell_is_mergeable(1), 'Cell 1 is not mergeable'); | |||
|
65 | this.test.assert(cell_is_splittable(2), 'Cell 2 is splittable'); | |||
|
66 | this.test.assert(cell_is_mergeable(2), 'Cell 2 is mergeable'); | |||
|
67 | }); | |||
|
68 | ||||
|
69 | // Try to merge cell 0 below with cell 1 | |||
|
70 | this.then(function () { | |||
|
71 | this.select_cell(0); | |||
|
72 | this.trigger_keydown('esc'); | |||
|
73 | this.trigger_keydown('shift-m'); | |||
|
74 | this.test.assertEquals(this.get_cells_length(), 3, 'Merge cell 0 down: There are still 3 cells'); | |||
|
75 | this.test.assertEquals(this.get_cell_text(0), a, 'Merge cell 0 down: Cell 0 is unchanged'); | |||
|
76 | this.test.assertEquals(this.get_cell_text(1), b, 'Merge cell 0 down: Cell 1 is unchanged'); | |||
|
77 | this.test.assertEquals(this.get_cell_text(2), c, 'Merge cell 0 down: Cell 2 is unchanged'); | |||
|
78 | this.validate_notebook_state('shift-m', 'command', 0); | |||
|
79 | }); | |||
|
80 | ||||
|
81 | // Try to merge cell 1 above with cell 0 | |||
|
82 | this.then(function () { | |||
|
83 | this.select_cell(1); | |||
|
84 | }); | |||
|
85 | this.thenEvaluate(function () { | |||
|
86 | IPython.notebook.merge_cell_above(); | |||
|
87 | }); | |||
|
88 | this.then(function () { | |||
|
89 | this.test.assertEquals(this.get_cells_length(), 3, 'Merge cell 1 up: There are still 3 cells'); | |||
|
90 | this.test.assertEquals(this.get_cell_text(0), a, 'Merge cell 1 up: Cell 0 is unchanged'); | |||
|
91 | this.test.assertEquals(this.get_cell_text(1), b, 'Merge cell 1 up: Cell 1 is unchanged'); | |||
|
92 | this.test.assertEquals(this.get_cell_text(2), c, 'Merge cell 1 up: Cell 2 is unchanged'); | |||
|
93 | this.validate_notebook_state('merge up', 'command', 1); | |||
|
94 | }); | |||
|
95 | ||||
|
96 | // Try to split cell 1 | |||
|
97 | this.then(function () { | |||
|
98 | this.select_cell(1); | |||
|
99 | this.trigger_keydown('enter'); | |||
|
100 | this.set_cell_editor_cursor(1, 0, 2); | |||
|
101 | this.trigger_keydown('ctrl-shift-subtract'); // Split | |||
|
102 | this.test.assertEquals(this.get_cells_length(), 3, 'Split cell 1: There are still 3 cells'); | |||
|
103 | this.test.assertEquals(this.get_cell_text(0), a, 'Split cell 1: Cell 0 is unchanged'); | |||
|
104 | this.test.assertEquals(this.get_cell_text(1), b, 'Split cell 1: Cell 1 is unchanged'); | |||
|
105 | this.test.assertEquals(this.get_cell_text(2), c, 'Split cell 1: Cell 2 is unchanged'); | |||
|
106 | this.validate_notebook_state('ctrl-shift-subtract', 'edit', 1); | |||
|
107 | }); | |||
|
108 | ||||
|
109 | // Try to merge cell 1 down | |||
|
110 | this.then(function () { | |||
|
111 | this.select_cell(1); | |||
|
112 | this.trigger_keydown('esc'); | |||
|
113 | this.trigger_keydown('shift-m'); | |||
|
114 | this.test.assertEquals(this.get_cells_length(), 3, 'Merge cell 1 down: There are still 3 cells'); | |||
|
115 | this.test.assertEquals(this.get_cell_text(0), a, 'Merge cell 1 down: Cell 0 is unchanged'); | |||
|
116 | this.test.assertEquals(this.get_cell_text(1), b, 'Merge cell 1 down: Cell 1 is unchanged'); | |||
|
117 | this.test.assertEquals(this.get_cell_text(2), c, 'Merge cell 1 down: Cell 2 is unchanged'); | |||
|
118 | this.validate_notebook_state('shift-m', 'command', 1); | |||
|
119 | }); | |||
|
120 | ||||
|
121 | // Try to merge cell 2 above with cell 1 | |||
|
122 | this.then(function () { | |||
|
123 | this.select_cell(2); | |||
|
124 | }); | |||
|
125 | this.thenEvaluate(function () { | |||
|
126 | IPython.notebook.merge_cell_above(); | |||
|
127 | }); | |||
|
128 | this.then(function () { | |||
|
129 | this.test.assertEquals(this.get_cells_length(), 3, 'Merge cell 2 up: There are still 3 cells'); | |||
|
130 | this.test.assertEquals(this.get_cell_text(0), a, 'Merge cell 2 up: Cell 0 is unchanged'); | |||
|
131 | this.test.assertEquals(this.get_cell_text(1), b, 'Merge cell 2 up: Cell 1 is unchanged'); | |||
|
132 | this.test.assertEquals(this.get_cell_text(2), c, 'Merge cell 2 up: Cell 2 is unchanged'); | |||
|
133 | this.validate_notebook_state('merge up', 'command', 2); | |||
20 | }); |
|
134 | }); | |
21 | }); No newline at end of file |
|
135 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now