/
saved_query_management_component.ts
238 lines (208 loc) · 8.56 KB
/
saved_query_management_component.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* 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 expect from '@kbn/expect';
import { FtrService } from '../ftr_provider_context';
export class SavedQueryManagementComponentService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly queryBar = this.ctx.getService('queryBar');
private readonly retry = this.ctx.getService('retry');
private readonly config = this.ctx.getService('config');
private readonly common = this.ctx.getPageObject('common');
public async getCurrentlyLoadedQueryID() {
await this.openSavedQueryManagementComponent();
try {
return await this.testSubjects.getVisibleText('savedQueryTitle');
} catch {
return undefined;
}
}
public async saveNewQuery(
name: string,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSaveCurrentQueryModal();
await this.submitSaveQueryForm(name, description, includeFilters, includeTimeFilter);
}
public async saveNewQueryWithNameError(name?: string) {
await this.openSaveCurrentQueryModal();
if (name) {
await this.testSubjects.setValue('saveQueryFormTitle', name);
}
// Form input validation only happens onBlur. Clicking the save button should de-focus the
// input element and the validation should prevent a save from actually happening if there's
// an error.
await this.testSubjects.click('savedQueryFormSaveButton');
await this.retry.waitForWithTimeout('save button to be disabled', 1000, async () => {
const saveQueryFormSaveButtonStatus = await this.testSubjects.isEnabled(
'savedQueryFormSaveButton'
);
return saveQueryFormSaveButtonStatus === false;
});
const contextMenuPanelTitleButton = await this.testSubjects.exists(
'contextMenuPanelTitleButton'
);
if (contextMenuPanelTitleButton) {
await this.testSubjects.click('contextMenuPanelTitleButton');
}
}
public async saveCurrentlyLoadedAsNewQuery(
name: string,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-save-button');
await this.submitSaveQueryForm(name, description, includeFilters, includeTimeFilter);
}
public async updateCurrentlyLoadedQuery(
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-save-changes-button');
await this.submitSaveQueryForm(null, description, includeFilters, includeTimeFilter);
}
public async loadSavedQuery(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-load-button');
await this.testSubjects.click(`~load-saved-query-${title}-button`);
await this.testSubjects.click('saved-query-management-apply-changes-button');
await this.retry.try(async () => {
await this.testSubjects.missingOrFail('queryBarMenuPanel');
});
await this.retry.try(async () => {
await this.openSavedQueryManagementComponent();
const selectedSavedQueryText = await this.testSubjects.getVisibleText('savedQueryTitle');
expect(selectedSavedQueryText).to.eql(title);
});
await this.closeSavedQueryManagementComponent();
}
public async deleteSavedQuery(title: string) {
await this.openSavedQueryManagementComponent();
const shouldClickLoadMenu = await this.testSubjects.exists(
'saved-query-management-load-button'
);
if (shouldClickLoadMenu) {
await this.testSubjects.click('saved-query-management-load-button');
}
await this.testSubjects.click(`~load-saved-query-${title}-button`);
await this.retry.waitFor('delete saved query', async () => {
await this.testSubjects.click(`delete-saved-query-button`);
const exists = await this.testSubjects.exists('confirmModalTitleText');
return exists === true;
});
await this.common.clickConfirmOnModal();
}
async clearCurrentlyLoadedQuery() {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('filter-sets-removeAllFilters');
await this.closeSavedQueryManagementComponent();
const queryString = await this.queryBar.getQueryString();
expect(queryString).to.be.empty();
}
async submitSaveQueryForm(
title: string | null,
description: string,
includeFilters: boolean,
includeTimeFilter: boolean
) {
if (title) {
await this.testSubjects.setValue('saveQueryFormTitle', title);
}
const currentIncludeFiltersValue =
(await this.testSubjects.getAttribute(
'saveQueryFormIncludeFiltersOption',
'aria-checked'
)) === 'true';
if (currentIncludeFiltersValue !== includeFilters) {
await this.testSubjects.click('saveQueryFormIncludeFiltersOption');
}
const currentIncludeTimeFilterValue =
(await this.testSubjects.getAttribute(
'saveQueryFormIncludeTimeFilterOption',
'aria-checked'
)) === 'true';
if (currentIncludeTimeFilterValue !== includeTimeFilter) {
await this.testSubjects.click('saveQueryFormIncludeTimeFilterOption');
}
await this.testSubjects.click('savedQueryFormSaveButton');
await this.retry.try(async () => {
await this.testSubjects.missingOrFail('saveQueryForm');
});
}
async savedQueryExist(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.click('saved-query-management-load-button');
const exists = await this.testSubjects.exists(`~load-saved-query-${title}-button`);
await this.closeSavedQueryManagementComponent();
return exists;
}
async savedQueryExistOrFail(title: string) {
await this.retry.waitFor('load saved query', async () => {
await this.openSavedQueryManagementComponent();
const shouldClickLoadMenu = await this.testSubjects.exists(
'saved-query-management-load-button'
);
return shouldClickLoadMenu === true;
});
await this.testSubjects.click('saved-query-management-load-button');
await this.testSubjects.existOrFail(`~load-saved-query-${title}-button`);
}
async savedQueryTextExist(text: string) {
await this.openSavedQueryManagementComponent();
const queryString = await this.queryBar.getQueryString();
expect(queryString).to.eql(text);
}
async savedQueryMissingOrFail(title: string) {
await this.retry.try(async () => {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail(`~load-saved-query-${title}-button`);
});
await this.closeSavedQueryManagementComponent();
}
async openSavedQueryManagementComponent() {
const isOpenAlready = await this.testSubjects.exists('queryBarMenuPanel');
if (isOpenAlready) return;
await this.testSubjects.click('showQueryBarMenu');
}
async closeSavedQueryManagementComponent() {
const isOpenAlready = await this.testSubjects.exists('queryBarMenuPanel');
if (!isOpenAlready) return;
await this.retry.try(async () => {
await this.testSubjects.click('showQueryBarMenu');
await this.testSubjects.missingOrFail('queryBarMenuPanel');
});
}
async openSaveCurrentQueryModal() {
await this.openSavedQueryManagementComponent();
await this.retry.try(async () => {
await this.testSubjects.click('saved-query-management-save-button');
await this.testSubjects.existOrFail('saveQueryForm', {
timeout: this.config.get('timeouts.waitForExists'),
});
});
}
async saveNewQueryMissingOrFail() {
await this.openSavedQueryManagementComponent();
const saveFilterSetBtn = await this.testSubjects.find('saved-query-management-save-button');
const isDisabled = await saveFilterSetBtn.getAttribute('disabled');
expect(isDisabled).to.equal('true');
}
async updateCurrentlyLoadedQueryMissingOrFail() {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail('saved-query-management-save-changes-button');
}
async deleteSavedQueryMissingOrFail(title: string) {
await this.openSavedQueryManagementComponent();
await this.testSubjects.missingOrFail(`delete-saved-query-${title}-button`);
}
}