/
plotGroovyTest.js
254 lines (221 loc) · 9.13 KB
/
plotGroovyTest.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var BeakerXPageObject = require('../beakerx.po.js');
var PlotHelperObject = require('../plot.helper.js');
var beakerxPO;
var plotHelper;
describe('Plot groovy js', function () {
beforeAll(function () {
beakerxPO = new BeakerXPageObject();
plotHelper = new PlotHelperObject();
beakerxPO.runNotebookByUrl('/test/ipynb/groovy/PlotGroovyTest.ipynb');
});
afterAll(function () {
beakerxPO.closeAndHaltNotebook();
});
var cellIndex;
describe('Run "Title and Axis Labels" cell. ', function () {
var dtContainer;
it('Widget area has dtcontainer', function () {
cellIndex = 0;
dtContainer = beakerxPO.runCellToGetDtContainer(cellIndex);
expect(dtContainer.isEnabled()).toBeTruthy();
});
it('Plot has Title and Axes Labels', function () {
plotHelper.checkPlotTitle(dtContainer, 'We Will Control the Title');
plotHelper.checkXLabel(dtContainer, 'Horizontal');
plotHelper.checkYLabel(dtContainer, 'Vertical');
});
});
describe('Run cells with lines', function(){
it('Plot has line', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getLineByGIndex(svgElement, 0).getAttribute('d')).not.toBeNull();
});
it('Should specify color, width and style of line', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
var plotLine = plotHelper.getLineByGIndex(svgElement, 3);
expect(plotLine.getCssProperty('stroke').value).toEqual('rgb(212,57,59)');
expect(plotLine.getCssProperty('stroke-width').value).toEqual('2px');
expect(plotLine.getCssProperty('stroke-dasharray').value).toEqual('2px, 2px');
});
});
describe('Run cell with stems', function(){
it('Plot has 6 stems', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllGStemLines(svgElement, 0).length).toEqual(6);
});
it('Should set the base of stems', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
var baseY1 = Math.round(svgElement.$('#gridline_y_0').getAttribute('y1'));
var stemY1 = Math.round(plotHelper.getStemByGAndLineIndexes(svgElement, 0, 1).getAttribute('y1'));
expect(baseY1).toEqual(stemY1);
});
});
describe('Run cell with bars', function(){
it('Plot has 5 bars', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllGBarRects(svgElement, 0).length).toEqual(5);
});
});
describe('Run cell with points', function(){
it('Plot has points', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllPointsByGIndexAndType(svgElement, 0, 'rect').length).toBeGreaterThan(0);
});
it('Should sets point colors using lists', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('rect#i0_0').getCssProperty('fill').value).toEqual('rgb(0,0,0)');
expect(svgElement.$('rect#i0_1').getCssProperty('fill').value).toEqual('rgb(255,0,0)');
});
});
describe('Run cell with areas', function(){
it('Plot has 2 areas', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllAreas(svgElement).length).toEqual(2);
});
it('Plot has area with base', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllAreas(svgElement).length).toEqual(1);
});
});
describe('Run cell with stacking', function(){
it('Plot has 2 areas', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllAreas(svgElement).length).toEqual(2);
});
});
describe('Run cell with constant lines', function(){
it('Plot has 4 constant lines', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllConstLines(svgElement).length).toEqual(4);
});
});
describe('Run cell with constant bands', function(){
it('Plot has constant band', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllConstBands(svgElement).length).toBeGreaterThan(0);
});
it('Should sets constant band color', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('#i1.plot-constband').getCssProperty('fill').value).toEqual('rgb(128,128,128)');
});
});
describe('Run cell with text', function(){
it('Plot has 8 text elements', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllTexts(svgElement).length).toEqual(8);
});
});
describe('Run cell with crosshair', function(){
it('Plot has crosshair', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
var pointElement = svgElement.$('rect#i2_0');
pointElement.scroll();
pointElement.click();
svgElement.moveToObject('rect#i2_1');
var divPlot = beakerxPO.getCodeCellByIndex(cellIndex).$('#svgg');
expect(divPlot.$('#cursor_xlabel').isVisible()).toBeTruthy();
expect(divPlot.$('#cursor_ylabel').isVisible()).toBeTruthy();
});
});
describe('Run "Simple Time Plot" cell', function(){
it('Time Plot has points elements', function(){
cellIndex += 2;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.kernelIdleIcon.waitForEnabled();
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('#i0.plot-point').isVisible()).toBeTruthy();
expect(svgElement.$('#i1.plot-point').isVisible()).toBeTruthy();
});
});
describe('Run "Second Y Axis" cell', function(){
it('Plot has second Y Axis', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('#yrlabel').isVisible()).toBeTruthy();
expect(svgElement.$('#label_yr_1').isVisible()).toBeTruthy();
});
});
describe('Run "Logarithmic Scale" cells', function(){
it('Plot has 2 lines', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllLines(svgElement).length).toEqual(2);
cellIndex += 1;
svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllLines(svgElement).length).toEqual(2);
});
});
describe('Run "Date Objects for the Time Coordinate" cell', function(){
it('Plot has points elements', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('#i0.plot-point').isVisible()).toBeTruthy();
expect(svgElement.$('#i1.plot-point').isVisible()).toBeTruthy();
});
});
describe('Run "Nanosecond Resolution" cell', function(){
it('Plot has points elements', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('#i0.plot-point').isVisible()).toBeTruthy();
});
});
describe('Run "Formating control" cells', function(){
it("Plot doesn't have tick labels", function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$$('g#labelg > text.plot-label').length).toEqual(0);
});
it("Plot has advanced styling", function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$$('g#labelg > text.plot-label')[0].getCssProperty('fill').value).toEqual('rgb(0,128,0)');
});
});
describe('Run "Raster" cell', function(){
it('Plot has 3 raster elements', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllRasters(svgElement).length).toBeGreaterThan(0);
});
});
describe('Run cell with axis bounds', function(){
it('Plot has 2 axis bounds', function(){
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(svgElement.$('text#label_y_0').getText()).toEqual('1\.0');
expect(svgElement.$('text#label_yr_0').getText()).toEqual('3\.0');
});
});
});