/
plotPythonTest.js
194 lines (165 loc) · 7.58 KB
/
plotPythonTest.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
/*
* 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 beakerxPO;
describe('Testing of Plot (python)', function () {
beforeAll(function () {
beakerxPO = new BeakerXPageObject();
beakerxPO.runNotebookByUrl('/test/ipynb/python/PlotPythonTest.ipynb');
}, 2);
afterAll(function () {
beakerxPO.closeAndHaltNotebook();
});
describe('Plot (python)', function () {
it('Plot has Title and Axes Labels', function () {
var dtContainer = beakerxPO.runCellToGetDtContainer(0);
expect(dtContainer.$('#plotTitle').getText()).toEqual('test title');
expect(dtContainer.$('#xlabel').getText()).toEqual('x label');
expect(dtContainer.$('#ylabel').getText()).toEqual('y label');
});
it('Plot has 3 Bars', function () {
var svgElement = beakerxPO.runCellToGetSvgElement(1);
expect(svgElement.$('g.plot-bar').isVisible()).toBeTruthy();
expect(svgElement.$$('rect.plot-resp').length).toEqual(3);
});
it('Plot has Line', function () {
var svgElement = beakerxPO.runCellToGetSvgElement(2);
expect(svgElement.$$('circle.plot-resp').length).toEqual(3);
expect(svgElement.$('path.plot-line').isVisible()).toBeTruthy();
});
it('Plot has 5 Points', function () {
var svgElement = beakerxPO.runCellToGetSvgElement(3);
expect(svgElement.$('g.plot-point').isVisible()).toBeTruthy();
expect(svgElement.$$('polygon.plot-resp').length).toEqual(5);
});
it('Plot has 4 Stems', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(4);
expect(svgElement.$('g.plot-stem').isVisible()).toBeTruthy();
expect(svgElement.$$('line.plot-resp.normal').length).toEqual(4);
});
it('Plot has Area', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(5);
expect(svgElement.$('polygon.plot-area').isVisible()).toBeTruthy();
});
it('Plot has Crosshair', function(){
var svgElement = beakerxPO.getCodeCellByIndex(5).$('#svgg');
var rectElement = svgElement.$('rect#i0_0');
rectElement.scroll();
rectElement.click();
svgElement.moveToObject('rect#i2_1');
var divPlot = beakerxPO.getCodeCellByIndex(5).$('#svgg');
expect(divPlot.$('#cursor_xlabel').isVisible()).toBeTruthy();
expect(divPlot.$('#cursor_ylabel').isVisible()).toBeTruthy();
});
it('Plot has 3 ConstantLines', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(6);
expect(svgElement.$$('g.plot-constline').length).toEqual(2);
expect(svgElement.$$('g.plot-constline > line').length).toEqual(3)
});
it('Plot has 2 ConstantBands', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(7);
expect(svgElement.$('g.plot-constband').isVisible()).toBeTruthy();
expect(svgElement.$$('g.plot-constband > rect').length).toEqual(2);
});
it('Plot has 4 text elements', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(8);
expect(svgElement.$$('g.plot-text').length).toEqual(4);
expect(svgElement.$$('g.plot-text > line').length).toEqual(4);
expect(svgElement.$('text#i1_0').getText()).toEqual('test');
});
});
describe('Pandas library', function () {
it('Plot has Bars', function () {
var svgElement = beakerxPO.runCellToGetSvgElement(9);
expect(svgElement.$('g.plot-bar').isVisible()).toBeTruthy();
expect(svgElement.$$('rect.plot-resp').length).toBeGreaterThan(0);
});
it('Plot has Line', function () {
var svgElement = beakerxPO.runCellToGetSvgElement(10);
expect(svgElement.$$('circle.plot-resp').length).toEqual(7);
expect(svgElement.$('path.plot-line').isVisible()).toBeTruthy();
});
});
describe('Plot Stacking', function(){
it('Plot has 2 Areas', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(11);
expect(svgElement.$$('g > polygon.plot-area').length).toEqual(2);
expect(svgElement.getLocation('rect#i0_0', 'y')).toBeGreaterThan(svgElement.getLocation('rect#i1_0', 'y'));
expect(svgElement.getLocation('rect#i0_0', 'x')).toBe(svgElement.getLocation('rect#i1_0', 'x'));
});
});
describe('Simple Time Plot', function(){
it('Time Plot has 2 lines and time axis', function(){
beakerxPO.kernelIdleIcon.waitForEnabled();
var svgElement = beakerxPO.runCellToGetSvgElement(12);
expect(svgElement.$$('g#i0 > circle').length).toBeGreaterThan(0);
expect(svgElement.$$('g#i1 > circle').length).toBeGreaterThan(0);
expect(svgElement.$('g#i0 > path.plot-line').isVisible()).toBeTruthy();
expect(svgElement.$('g#i1 > path.plot-line').isVisible()).toBeTruthy();
expect(svgElement.$('text#label_x_0').getText()).toEqual('1990');
});
it('Time Plot has millisecond resolution', function(){
beakerxPO.kernelIdleIcon.waitForEnabled();
var dtContainer = beakerxPO.runCellToGetDtContainer(13);
var svgElement = dtContainer.$('#svgg');
svgElement.$('rect#i0_0').click();
var tipElement = dtContainer.$('div#tip_i0_0');
expect(tipElement.getText()).toMatch('x: 2017 Oct 09 Mon, 05:26:41 .624');
});
it('Time Plot has nanosecond resolution', function(){
beakerxPO.kernelIdleIcon.waitForEnabled();
var dtContainer = beakerxPO.runCellToGetDtContainer(14);
var svgElement = dtContainer.$('#svgg');
svgElement.$('rect#i0_1').click();
var tipElement = dtContainer.$('div#tip_i0_1');
expect(tipElement.getText()).toMatch('x: 2017 Oct 09 Mon, 09:26:41.624000007');
});
});
describe('Second Y Axis', function(){
it('Plot has second Y Axis', function(){
var svgElement = beakerxPO.runCellToGetSvgElement(15);
expect(svgElement.$('text#yrlabel').getText()).toEqual('Test y axis');
expect(svgElement.$('text#label_yr_0').getText()).toEqual('10');
expect(svgElement.$('line#tick_yr_0').isEnabled()).toBeTruthy();
});
});
function getCircleAttr(elem, index, attribute){
return elem.$('circle#' + index).getAttribute(attribute)
}
function getMaingG(elem, index){
return elem.$$('div.dtcontainer')[index].$('g#i0');
}
describe('Logarithmic Scale', function(){
var combPlot;
it('Combined plot has 3 plots', function(){
combPlot = beakerxPO.runCodeCellByIndex(16).$('div.combplot-plotcontainer');
expect(combPlot.isVisible()).toBeTruthy();
expect(combPlot.$$('div.dtcontainer').length).toEqual(3);
});
it('Second plot has Log Y axis', function(){
var g0 = getMaingG(combPlot, 0);
var g1 = getMaingG(combPlot, 1);
expect(getCircleAttr(g0, 'i0_0', 'cy')).toBe(getCircleAttr(g1, 'i0_0', 'cy'));
expect(getCircleAttr(g0, 'i0_50', 'cy')).toBeGreaterThan(getCircleAttr(g1, 'i0_50', 'cy'));
});
it('Third plot has Log X axis', function(){
var g0 = getMaingG(combPlot, 0);
var g2 = getMaingG(combPlot, 2);
expect(getCircleAttr(g0, 'i0_0', 'cx')).toBe(getCircleAttr(g2, 'i0_0', 'cx'));
expect(getCircleAttr(g0, 'i0_50', 'cx')).toBeLessThan(getCircleAttr(g2, 'i0_50', 'cx'));
});
});
});