-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
multiselect.js
100 lines (83 loc) · 3.81 KB
/
multiselect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Test
casper.notebook_test(function () {
var that = this;
var a = 'print("a")';
var index = this.append_cell(a);
var b = 'print("b")';
index = this.append_cell(b);
var c = 'print("c")';
index = this.append_cell(c);
this.then(function () {
var selectedIndex = this.evaluate(function () {
Jupyter.notebook.select(0);
return Jupyter.notebook.get_selected_index();
});
this.test.assertEquals(this.evaluate(function() {
return Jupyter.notebook.get_selected_cells().length;
}), 1, 'only one cell is selected programmatically');
this.test.assertEquals(this.evaluate(function() {
return $('.cell.jupyter-soft-selected, .cell.selected').length;
}), 1, 'one cell is selected');
this.test.assertEquals(this.evaluate(function() {
Jupyter.notebook.extend_selection_by(1);
return Jupyter.notebook.get_selected_cells().length;
}), 2, 'extend selection by one');
this.test.assertEquals(this.evaluate(function() {
Jupyter.notebook.extend_selection_by(-1);
return Jupyter.notebook.get_selected_cells().length;
}), 1, 'contract selection by one');
this.test.assertEquals(this.evaluate(function() {
Jupyter.notebook.select(1);
Jupyter.notebook.extend_selection_by(-1);
return Jupyter.notebook.get_selected_cells().length;
}), 2, 'extend selection by one up');
// Test multiple markdown conversions.
var cell_types = this.evaluate(function() {
Jupyter.notebook.select(0);
Jupyter.notebook.extend_selection_by(2);
var indices = Jupyter.notebook.get_selected_cells_indices();
Jupyter.notebook.cells_to_markdown();
return indices.map(function(i) {
return Jupyter.notebook.get_cell(i).cell_type;
});
});
this.test.assert(cell_types.every(function(cell_type) {
return cell_type === 'markdown';
}), 'selected cells converted to markdown');
this.test.assertEquals(this.evaluate(function() {
return Jupyter.notebook.get_selected_cells_indices();
}).length, 1, 'one cell selected after convert');
// Test multiple raw conversions.
cell_types = this.evaluate(function() {
Jupyter.notebook.select(0);
Jupyter.notebook.extend_selection_by(2);
var indices = Jupyter.notebook.get_selected_cells_indices();
Jupyter.notebook.cells_to_raw();
return indices.map(function(i) {
return Jupyter.notebook.get_cell(i).cell_type;
});
});
this.test.assert(cell_types.every(function(cell_type) {
return cell_type === 'raw';
}), 'selected cells converted to raw');
this.test.assertEquals(this.evaluate(function() {
return Jupyter.notebook.get_selected_cells_indices();
}).length, 1, 'one cell selected after convert');
// Test multiple code conversions.
cell_types = this.evaluate(function() {
Jupyter.notebook.select(0);
Jupyter.notebook.extend_selection_by(2);
var indices = Jupyter.notebook.get_selected_cells_indices();
Jupyter.notebook.cells_to_code();
return indices.map(function(i) {
return Jupyter.notebook.get_cell(i).cell_type;
});
});
this.test.assert(cell_types.every(function(cell_type) {
return cell_type === 'code';
}), 'selected cells converted to code');
this.test.assertEquals(this.evaluate(function() {
return Jupyter.notebook.get_selected_cells_indices();
}).length, 1, 'one cell selected after convert');
});
});