-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpage-environment-mocha.js
More file actions
220 lines (192 loc) · 10.9 KB
/
Copy pathpage-environment-mocha.js
File metadata and controls
220 lines (192 loc) · 10.9 KB
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
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
/* eslint-disable max-len */
const assert = require('assert');
const test = require('../mocha-index');
const {waitForTimeout} = require('../utils/puppeteerUtils.js');
describe('`pageEnvironment` test-suite', async () => {
let url;
let page;
let calls;
before(() => {
url = test.helpers.url;
page = test.page;
calls = test.helpers.calls;
page.on('dialog', async (dialog) => {
await dialog.accept();
});
});
beforeEach(() => {
// reset grpc calls
calls['controlEnvironment'] = undefined;
calls['getEnvironment'] = undefined;
calls['destroyEnvironment'] = undefined;
});
it('should successfully load and request data for environment', async () => {
await page.goto(url + '?page=environment&id=6f6d6387-6577-11e8-993a-f07959157220', {waitUntil: 'networkidle0'});
const location = await page.evaluate(() => window.location);
assert.strictEqual(location.search, '?page=environment&id=6f6d6387-6577-11e8-993a-f07959157220&panel=general');
assert.ok(calls['getEnvironment']);
});
it('should have one button for `Shutdown` environment with lock in possession', async () => {
const lockInPossession = await page.evaluate(() => window.model.lock.isLockedByCurrentUser('MID'));
assert.ok(lockInPossession, 'User is not in possession of lock');
await page.waitForSelector('#buttonToSHUTDOWN', {timeout: 5000});
const shutdownButton = await page.evaluate(() => document.querySelector('#buttonToSHUTDOWN').title);
assert.strictEqual(shutdownButton, 'Shutdown environment');
});
it('should have informative message when user without lock in possession even as admin', async () => {
await page.evaluate(() => {
window.model.lock.actionOnLock('MID', 'RELEASE', false);
});
const isLocked = await page.evaluate(() => {
window.model.lock.isLocked('MID');
});
assert.ok(!isLocked, 'Detector still appears as locked');
await page.waitForSelector('#missing_lock_ownership_to_control_message', {timeout: 5000});
const informationMessage = await page.evaluate(() => document.querySelector('#missing_lock_ownership_to_control_message').innerText);
assert.strictEqual(informationMessage, 'You do not own the necessary locks to control this environment.');
});
it('should not have button displayed if user is not admin or does not have the lock', async () => {
await page.evaluate(() => {
window.model.session.role = 2;
window.model.notify();
});
const shutdownButton = await page.$('#buttonToSHUTDOWN');
assert.ok(shutdownButton === null, 'button still exists');
// adds permissions and lock back
await page.evaluate(() => {
window.model.session.role = 1;
window.model.lock.actionOnLock('MID', 'TAKE', false);
window.model.notify();
});
});
describe('Check presence of buttons in CONFIGURED state', async () => {
it('should have one button for START in state CONFIGURED', async () => {
await page.waitForSelector('#buttonToSTART', {timeout: 5000});
const startButton = await page.evaluate(() => document.querySelector('#buttonToSTART').title);
assert.strictEqual(startButton, 'START');
});
it('should have one button hidden for STOP in state CONFIGURED', async () => {
await page.waitForSelector('#buttonToSTOP', {timeout: 5000});
const stopButtonTitle = await page.evaluate(() => document.querySelector('#buttonToSTOP').title);
const stopButtonStyle = await page.evaluate(() => document.querySelector('#buttonToSTOP').style);
assert.strictEqual(stopButtonTitle, `'STOP' cannot be used in state 'CONFIGURED'`);
assert.deepStrictEqual(stopButtonStyle, {0: 'display'});
});
it('should have one button hidden for CONFIGURE in state CONFIGURED', async () => {
await page.waitForSelector('#buttonToCONFIGURE', {timeout: 5000});
const configureButtonTitle = await page.evaluate(() => document.querySelector('#buttonToCONFIGURE').title);
const configureButtonStyle = await page.evaluate(() => document.querySelector('#buttonToCONFIGURE').style);
assert.strictEqual(configureButtonTitle, `'CONFIGURE' cannot be used in state 'CONFIGURED'`);
assert.deepStrictEqual(configureButtonStyle, {0: 'display'});
});
});
describe('Check transition from CONFIGURED to RUNNING and presence of buttons in RUNNING state', async () => {
it('should click START button to move states (CONFIGURED -> RUNNING)', async () => {
await page.waitForSelector('#buttonToSTART', {timeout: 5000});
// click STOP
await page.evaluate(() => document.querySelector('#buttonToSTART').click());
await waitForTimeout(1000);
const state = await page.evaluate(() => window.model.environment.item.payload.state);
assert.strictEqual(state, 'RUNNING');
assert.ok(calls['controlEnvironment']);
});
it('should have one button hidden for START in state RUNNING', async () => {
await page.waitForSelector('#buttonToSTART', {timeout: 5000});
const startButtonTitle = await page.evaluate(() => document.querySelector('#buttonToSTART').title);
const startButtonStyle = await page.evaluate(() => document.querySelector('#buttonToSTART').style);
assert.strictEqual(startButtonTitle, `'START' cannot be used in state 'RUNNING'`);
assert.deepStrictEqual(startButtonStyle, {0: 'display'});
});
it('should have one button for STOP in state RUNNING', async () => {
await page.waitForSelector('#buttonToSTOP', {timeout: 5000});
const stopButton = await page.evaluate(() => document.querySelector('#buttonToSTOP').title);
assert.strictEqual(stopButton, 'STOP');
});
it('should have one button hidden for CONFIGURE in state RUNNING', async () => {
await page.waitForSelector('#buttonToCONFIGURE', {timeout: 5000});
const configureButtonTitle = await page.evaluate(() => document.querySelector('#buttonToCONFIGURE').title);
const configureButtonStyle = await page.evaluate(() => document.querySelector('#buttonToCONFIGURE').style);
assert.strictEqual(configureButtonTitle, `'CONFIGURE' cannot be used in state 'RUNNING'`);
assert.deepStrictEqual(configureButtonStyle, {0: 'display'});
});
it('should have one button hidden for RESET in state RUNNING', async () => {
await page.waitForSelector('#buttonToRESET', {timeout: 5000});
const resetButtonTitle = await page.evaluate(() => document.querySelector('#buttonToRESET').title);
const resetButtonStyle = await page.evaluate(() => document.querySelector('#buttonToRESET').style);
assert.strictEqual(resetButtonTitle, `'RESET' cannot be used in state 'RUNNING'`);
assert.deepStrictEqual(resetButtonStyle, {0: 'display'});
});
});
describe('Check transition from RUNNING to CONFIGURED to DEPLOYED and presence of buttons', async () => {
it('should click STOP then RESET button states (RUNNING -> CONFIGURED -> DEPLOYED)', async () => {
await page.waitForSelector('#buttonToSTOP', {timeout: 5000});
// click STOP
await page.evaluate(() => document.querySelector('#buttonToSTOP').click());
await waitForTimeout(1000);
const configuredState = await page.evaluate(() => window.model.environment.item.payload.state);
assert.strictEqual(configuredState, 'CONFIGURED');
});
it('should display warning label for START button in state CONFIGURED', async () => {
await page.waitForSelector('#start_action_warning', { timeout: 5000 });
const startButtonWarning = await page.evaluate(() => document.querySelector('#start_action_warning').innerText);
assert.strictEqual(startButtonWarning, 'Environment was in RUNNING state once already');
});
it('should click RESET button to move states (CONFIGURED -> DEPLOYED)', async () => {
await page.evaluate(() => document.querySelector('#buttonToRESET').click());
await waitForTimeout(1000);
const standbyState = await page.evaluate(() => window.model.environment.item.payload.state);
assert.strictEqual(standbyState, 'DEPLOYED');
});
it('should display warning label for START button in state DEPLOYED', async () => {
await page.waitForSelector('#start_action_warning', { timeout: 5000 });
const startButtonWarning = await page.evaluate(() => document.querySelector('#start_action_warning').innerText);
assert.strictEqual(startButtonWarning, 'Environment was in RUNNING state once already');
});
it('should have one button hidden for STOP in state DEPLOYED', async () => {
await page.waitForSelector('#buttonToSTOP', {timeout: 5000});
const stopButtonTitle = await page.evaluate(() => document.querySelector('#buttonToSTOP').title);
const stopButtonStyle = await page.evaluate(() => document.querySelector('#buttonToSTOP').style);
assert.strictEqual(stopButtonTitle, `'STOP' cannot be used in state 'DEPLOYED'`);
assert.deepStrictEqual(stopButtonStyle, {0: 'display'});
});
it.skip('should have one button for CONFIGURE in state DEPLOYED', async () => {
// skipping due to OCTRL-628
await page.waitForSelector('#buttonToCONFIGURE', {timeout: 5000});
const configureButtonTitle = await page.evaluate(() => document.querySelector('#buttonToCONFIGURE').title);
assert.strictEqual(configureButtonTitle, `CONFIGURE`);
});
it('should have one button hidden for RESET in state DEPLOYED', async () => {
await page.waitForSelector('#buttonToRESET', {timeout: 5000});
const resetButtonTitle = await page.evaluate(() => document.querySelector('#buttonToRESET').title);
const resetButtonStyle = await page.evaluate(() => document.querySelector('#buttonToRESET').style);
assert.strictEqual(resetButtonTitle, `'RESET' cannot be used in state 'DEPLOYED'`);
assert.deepStrictEqual(resetButtonStyle, {0: 'display'});
});
});
describe('Check shutdown of environment and presence of buttons', async () => {
it('should successfully `Shutdown` environment and redirect to `pageEnvironments`', async () => {
page.on('dialog', async (dialog) => {
await dialog.accept();
});
await page.waitForSelector('#buttonToSHUTDOWN', {timeout: 5000});
await page.evaluate(() => document.querySelector('#buttonToSHUTDOWN').click());
await waitForTimeout(1000);
const location = await page.evaluate(() => window.location);
assert.strictEqual(location.search, '?page=environments');
assert.ok(calls['destroyEnvironment']);
});
});
});