-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
share_page.ts
98 lines (85 loc) · 3.42 KB
/
share_page.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
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
/*
* 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';
export class SharePageObject extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly find = this.ctx.getService('find');
private readonly log = this.ctx.getService('log');
private readonly retry = this.ctx.getService('retry');
/**
* @description attempt to close the share modal, if it's open
*/
async closeShareModal() {
if (await this.isShareModalOpen()) {
await this.find.clickByCssSelector(
'[data-test-subj="shareContextModal"] button[aria-label*="Close"]'
);
}
}
async clickTab(content: string) {
if (!(await this.isShareModalOpen())) {
await this.clickShareTopNavButton();
}
await (await this.find.byButtonText(content)).click();
}
async isShareMenuOpen() {
return await this.testSubjects.exists('shareContextMenu');
}
async isShareModalOpen() {
return await this.testSubjects.exists('shareContextModal');
}
async clickShareTopNavButton() {
return this.testSubjects.click('shareTopNavButton');
}
async openShareModalItem(itemTitle: 'link' | 'export' | 'embed') {
this.log.debug(`openShareModalItem title: ${itemTitle}`);
const isShareModalOpen = await this.isShareModalOpen();
if (!isShareModalOpen) {
await this.clickShareTopNavButton();
}
await this.testSubjects.click(itemTitle);
}
async openShareMenuItem(itemTitle: string) {
this.log.debug(`openShareMenuItem title:${itemTitle}`);
const isShareMenuOpen = await this.isShareMenuOpen();
if (!isShareMenuOpen) {
await this.clickShareTopNavButton();
} else {
// there is no easy way to ensure the menu is at the top level
// so just close the existing menu
await this.clickShareTopNavButton();
// and then re-open the menu
await this.clickShareTopNavButton();
}
const menuPanel = await this.find.byCssSelector('div.euiContextMenuPanel');
await this.testSubjects.click(`sharePanel-${itemTitle.replace(' ', '')}`);
await this.testSubjects.waitForDeleted(menuPanel);
}
/**
* if there are more entries in the share menu, the permalinks entry has to be clicked first
* else the selection isn't displayed. this happens if you're testing against an instance
* with xpack features enabled, where there's also a csv sharing option
* in a pure OSS environment, the permalinks sharing panel is displayed initially
*/
async checkOldVersion() {
await this.clickShareTopNavButton();
if (await this.testSubjects.find('shareContextModal')) {
this.log.debug('This is the new share context modal');
await this.closeShareModal();
return false;
}
return true;
}
async getSharedUrl(): Promise<string> {
await this.retry.waitFor('wait for share url creation', async () => {
await this.testSubjects.click('copyShareUrlButton');
return Boolean(await this.testSubjects.getAttribute('copyShareUrlButton', 'data-share-url'));
});
return (await this.testSubjects.getAttribute('copyShareUrlButton', 'data-share-url'))!;
}
}