/
outputContainerTest.js
174 lines (144 loc) · 5.91 KB
/
outputContainerTest.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
/*
* 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('(Groovy) Output Containers ', function () {
beforeAll(function () {
beakerxPO = new BeakerXPageObject();
beakerxPO.runNotebookByUrl('/test/ipynb/groovy/OutputContainersTest.ipynb');
});
afterAll(function () {
beakerxPO.closeAndHaltNotebook();
});
var cellIndex;
function widgetPlotIsVisible(widget){
return widget.isVisible('div#plotLegendContainer');
}
function widgetTableIsVisible(widget){
return widget.isVisible('div.p-Widget.p-DataGrid-viewport');
}
describe('(Groovy) OutputCell.HIDDEN ', function() {
it("Cell doesn't have output", function () {
cellIndex = 0;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
expect(beakerxPO.getAllOutputAreaChildren(codeCell).length).toBe(0);
});
});
describe('(Groovy) Stacked Output Containers ', function() {
it('Cell output contains 4 output containers ', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var outputs = beakerxPO.getAllOutputAreaChildren(codeCell);
expect(outputs.length).toBe(4);
expect(outputs[0].getText()).toMatch(/simplest example/);
expect(outputs[1].getText()).toMatch(/2, 3, 5, 7/);
expect(outputs[2].$('h1').getText()).toMatch(/title/);
expect(outputs[3].getText()).toMatch(/null/);
});
});
function clickOnTabByName(output, name){
output.click('div.p-TabBar-tabLabel=' + name);
}
function getTabLabelText(output, tabIndex){
return output.$$('div.p-TabBar-tabLabel')[tabIndex].getText();
}
describe('(Groovy) Tabbed Output Containers ', function() {
var output;
var widgets;
it('Cell contains Tabbed Output with 4 tabs ', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
output = beakerxPO.getAllOutputsWidget(codeCell)[0];
widgets = output.$$('div.widget-tab-contents > div.p-Widget > div');
expect(widgets.length).toBe(4);
expect(getTabLabelText(output, 0)).toMatch(/Scatter with History/);
expect(getTabLabelText(output, 1)).toMatch(/Short Term/);
expect(getTabLabelText(output, 2)).toMatch(/Long Term/);
expect(getTabLabelText(output, 3)).toMatch(/1990\/01/);
});
it('Tabbed Output contains 3 plots and 1 table ', function () {
clickOnTabByName(output, 'Scatter with History');
expect(widgetPlotIsVisible(widgets[0])).toBeTruthy();
clickOnTabByName(output, 'Short Term');
expect(widgetPlotIsVisible(widgets[1])).toBeTruthy();
clickOnTabByName(output, 'Long Term');
expect(widgetPlotIsVisible(widgets[2])).toBeTruthy();
clickOnTabByName(output, '1990/01');
expect(widgetTableIsVisible(widgets[3])).toBeTruthy();
});
});
describe('(Groovy) Grid Output Containers ', function() {
var widgets;
it('Cell contains Grid Output with 6 items ', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var output = beakerxPO.getAllOutputsWidget(codeCell)[0];
widgets = output.$$('div.widget-hbox > div.p-Widget > div');
expect(widgets.length).toBe(6);
});
it('Grid Output contains 5 plots and 1 table ', function () {
expect(widgetPlotIsVisible(widgets[0])).toBeTruthy();
expect(widgetPlotIsVisible(widgets[1])).toBeTruthy();
expect(widgetPlotIsVisible(widgets[2])).toBeTruthy();
expect(widgetPlotIsVisible(widgets[3])).toBeTruthy();
expect(widgetTableIsVisible(widgets[4])).toBeTruthy();
expect(widgetPlotIsVisible(widgets[5])).toBeTruthy();
});
});
function waitWidgetPlotIsVisible(output, lastId){
var widgetId;
browser.waitUntil(function() {
var widget = output.$('div.widget-box > div.p-Widget > div');
widgetId = widget.getAttribute('id');
return (lastId != widgetId) && widgetPlotIsVisible(widget);
});
return widgetId;
};
function waitWidgetTableIsVisible(output, lastId){
var widgetId;
browser.waitUntil(function() {
var widget = output.$('div.widget-box > div.p-Widget');
widgetId = widget.getAttribute('id');
return (lastId != widgetId) && widgetTableIsVisible(widget);
});
return widgetId;
};
describe('(Groovy) Cycling Output Container ', function() {
var output;
var time1, time2, time3;
it('Cell output contains widget container ', function () {
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
output = beakerxPO.getAllOutputsWidget(codeCell)[0];
expect(output.$('div.widget-container.widget-box').isVisible()).toBeTruthy();
});
it('Cycling Output contains 3 plots and 1 table ', function () {
var wdgId = waitWidgetPlotIsVisible(output, 'firstPlot');
wdgId = waitWidgetPlotIsVisible(output, wdgId);
time1 = new Date().getTime();
wdgId = waitWidgetTableIsVisible(output, wdgId);
time2 = new Date().getTime();
waitWidgetPlotIsVisible(output, wdgId);
time3 = new Date().getTime();
});
it('Cycling period approximately equals 3 seconds ', function () {
expect(time2 - time1).toBeGreaterThan(2500);
expect(time2 - time1).toBeLessThan(3500);
expect(time3 - time2).toBeGreaterThan(2500);
expect(time3 - time2).toBeLessThan(3500);
});
});
});