-
Notifications
You must be signed in to change notification settings - Fork 915
/
dashboard_saved_query.js
139 lines (125 loc) · 6.32 KB
/
dashboard_saved_query.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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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.
*/
import expect from '@osd/expect';
export default function ({ getService, getPageObjects }) {
const opensearchArchiver = getService('opensearchArchiver');
const opensearchDashboardsServer = getService('opensearchDashboardsServer');
const PageObjects = getPageObjects(['common', 'dashboard', 'timePicker']);
const browser = getService('browser');
const queryBar = getService('queryBar');
const savedQueryManagementComponent = getService('savedQueryManagementComponent');
const testSubjects = getService('testSubjects');
describe('dashboard saved queries', function describeIndexTests() {
before(async function () {
await opensearchArchiver.load('dashboard/current/opensearch_dashboards');
await opensearchDashboardsServer.uiSettings.replace({
defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c',
});
await PageObjects.common.navigateToApp('dashboard');
});
describe('saved query management component functionality', function () {
before(async () => {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();
});
it('should show the saved query management component when there are no saved queries', async () => {
await savedQueryManagementComponent.openSavedQueryManagementComponent();
const descriptionText = await testSubjects.getVisibleText('saved-query-management-popover');
expect(descriptionText).to.eql(
'SAVED QUERIES\nThere are no saved queries. Save query text and filters that you want to use again.\nSave current query'
);
});
it('should allow a query to be saved via the saved objects management component', async () => {
await queryBar.setQuery('response:200');
await savedQueryManagementComponent.saveNewQuery(
'OkResponse',
'200 responses for .jpg over 24 hours',
true,
true
);
await savedQueryManagementComponent.savedQueryExistOrFail('OkResponse');
await savedQueryManagementComponent.savedQueryTextExist('response:200');
});
it('reinstates filters and the time filter when a saved query has filters and a time filter included', async () => {
await PageObjects.timePicker.setDefaultAbsoluteRange();
await savedQueryManagementComponent.clearCurrentlyLoadedQuery();
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
const timePickerValues = await PageObjects.timePicker.getTimeConfigAsAbsoluteTimes();
expect(timePickerValues.start).to.not.eql(PageObjects.timePicker.defaultStartTime);
expect(timePickerValues.end).to.not.eql(PageObjects.timePicker.defaultEndTime);
});
it('preserves the currently loaded query when the page is reloaded', async () => {
await browser.refresh();
const timePickerValues = await PageObjects.timePicker.getTimeConfigAsAbsoluteTimes();
expect(timePickerValues.start).to.not.eql(PageObjects.timePicker.defaultStartTime);
expect(timePickerValues.end).to.not.eql(PageObjects.timePicker.defaultEndTime);
expect(await savedQueryManagementComponent.getCurrentlyLoadedQueryID()).to.be('OkResponse');
});
it('allows saving changes to a currently loaded query via the saved query management component', async () => {
await queryBar.setQuery('response:404');
await savedQueryManagementComponent.updateCurrentlyLoadedQuery(
'OkResponse',
'404 responses',
false,
false
);
await savedQueryManagementComponent.savedQueryExistOrFail('OkResponse');
await savedQueryManagementComponent.clearCurrentlyLoadedQuery();
expect(await queryBar.getQueryString()).to.eql('');
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
expect(await queryBar.getQueryString()).to.eql('response:404');
});
it('allows saving the currently loaded query as a new query', async () => {
await savedQueryManagementComponent.saveCurrentlyLoadedAsNewQuery(
'OkResponseCopy',
'200 responses',
false,
false
);
await savedQueryManagementComponent.savedQueryExistOrFail('OkResponseCopy');
});
it('allows deleting the currently loaded saved query in the saved query management component and clears the query', async () => {
await savedQueryManagementComponent.deleteSavedQuery('OkResponseCopy');
await savedQueryManagementComponent.savedQueryMissingOrFail('OkResponseCopy');
expect(await queryBar.getQueryString()).to.eql('');
});
it('resets any changes to a loaded query on reloading the same saved query', async () => {
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
await queryBar.setQuery('response:503');
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
expect(await queryBar.getQueryString()).to.eql('response:404');
});
it('allows clearing the currently loaded saved query', async () => {
await savedQueryManagementComponent.loadSavedQuery('OkResponse');
await savedQueryManagementComponent.clearCurrentlyLoadedQuery();
expect(await queryBar.getQueryString()).to.eql('');
});
});
});
}