-
Notifications
You must be signed in to change notification settings - Fork 8k
/
menu_toggle.ts
61 lines (51 loc) · 1.94 KB
/
menu_toggle.ts
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { FtrService } from '../ftr_provider_context';
interface Options {
name: string;
menuTestSubject: string;
toggleButtonTestSubject: string;
}
export class MenuToggleService extends FtrService {
private readonly log = this.ctx.getService('log');
private readonly retry = this.ctx.getService('retry');
private readonly testSubjects = this.ctx.getService('testSubjects');
create(options: Options) {
const { log, retry, testSubjects } = this;
const { name, menuTestSubject, toggleButtonTestSubject } = options;
async function setState(expectedState: boolean) {
log.debug(
`setting menu open state [name=${name}] [state=${expectedState ? 'open' : 'closed'}]`
);
await retry.try(async () => {
// if the menu is clearly in the expected state already, bail out quickly if so
const isOpen = await testSubjects.exists(menuTestSubject, { timeout: 1000 });
if (isOpen === expectedState) {
return;
}
// toggle the view state by clicking the button
await testSubjects.click(toggleButtonTestSubject);
if (expectedState === true) {
// wait for up to 10 seconds for the menu to show up, otherwise fail and retry
await testSubjects.existOrFail(menuTestSubject, { timeout: 10000 });
} else {
// wait for the form to hide, otherwise fail and retry
await testSubjects.waitForDeleted(menuTestSubject);
}
});
}
return {
async open() {
await setState(true);
},
async close() {
await setState(false);
},
};
}
}