-
Notifications
You must be signed in to change notification settings - Fork 981
/
Copy pathview_edit.js
265 lines (211 loc) · 10.4 KB
/
view_edit.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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* 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 queryBar = getService('queryBar');
const opensearchArchiver = getService('opensearchArchiver');
const opensearchDashboardsServer = getService('opensearchDashboardsServer');
const dashboardAddPanel = getService('dashboardAddPanel');
const PageObjects = getPageObjects(['dashboard', 'header', 'common', 'visualize', 'timePicker']);
const dashboardName = 'dashboard with filter';
const filterBar = getService('filterBar');
describe('dashboard view edit mode', function viewEditModeTests() {
before(async () => {
await opensearchArchiver.load('dashboard/current/opensearch_dashboards');
await opensearchDashboardsServer.uiSettings.replace({
defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c',
});
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.preserveCrossAppState();
});
it('create new dashboard opens in edit mode', async function () {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.clickCancelOutOfEditMode();
});
it('existing dashboard opens in view mode', async function () {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.loadSavedDashboard(dashboardName);
const inViewMode = await PageObjects.dashboard.getIsInViewMode();
expect(inViewMode).to.equal(true);
});
describe('save', function () {
it('auto exits out of edit mode', async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
await PageObjects.dashboard.saveDashboard(dashboardName);
const isViewMode = await PageObjects.dashboard.getIsInViewMode();
expect(isViewMode).to.equal(true);
});
});
describe('shows lose changes warning', function () {
describe('and loses changes on confirmation', function () {
beforeEach(async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
});
it('when time changed is stored with dashboard', async function () {
await PageObjects.timePicker.setDefaultDataRange();
const originalTime = await PageObjects.timePicker.getTimeConfig();
await PageObjects.dashboard.saveDashboard(dashboardName, {
storeTimeWithDashboard: true,
});
await PageObjects.dashboard.switchToEditMode();
await PageObjects.timePicker.setAbsoluteRange(
'Sep 19, 2013 @ 06:31:44.000',
'Sep 19, 2013 @ 06:31:44.000'
);
await PageObjects.dashboard.clickCancelOutOfEditMode();
// confirm lose changes
await PageObjects.common.clickConfirmOnModal();
const newTime = await PageObjects.timePicker.getTimeConfig();
expect(newTime.start).to.equal(originalTime.start);
expect(newTime.end).to.equal(originalTime.end);
});
it('when the query is edited and applied', async function () {
const originalQuery = await queryBar.getQueryString();
await queryBar.setQuery(`${originalQuery}and extra stuff`);
await queryBar.submitQuery();
await PageObjects.dashboard.clickCancelOutOfEditMode();
// confirm lose changes
await PageObjects.common.clickConfirmOnModal();
const query = await queryBar.getQueryString();
expect(query).to.equal(originalQuery);
});
it('when a filter is deleted', async function () {
// This may seem like a pointless line but there was a bug that only arose when the dashboard
// was loaded initially
await PageObjects.dashboard.loadSavedDashboard(dashboardName);
await PageObjects.dashboard.switchToEditMode();
let hasFilter = await filterBar.hasFilter('animal', 'dog');
expect(hasFilter).to.be(true);
await filterBar.removeFilter('animal');
hasFilter = await filterBar.hasFilter('animal', 'dog');
expect(hasFilter).to.be(false);
await PageObjects.dashboard.clickCancelOutOfEditMode();
// confirm lose changes
await PageObjects.common.clickConfirmOnModal();
hasFilter = await filterBar.hasFilter('animal', 'dog');
expect(hasFilter).to.be(true);
});
it('when a new vis is added', async function () {
const originalPanelCount = await PageObjects.dashboard.getPanelCount();
await dashboardAddPanel.ensureAddPanelIsShowing();
await dashboardAddPanel.clickAddNewEmbeddableLink('visualization');
await PageObjects.visualize.clickAreaChart();
await PageObjects.visualize.clickNewSearch();
await PageObjects.visualize.saveVisualizationExpectSuccess('new viz panel', {
saveAsNew: false,
redirectToOrigin: true,
});
await PageObjects.dashboard.clickCancelOutOfEditMode();
// confirm lose changes
await PageObjects.common.clickConfirmOnModal();
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(originalPanelCount);
});
it('when an existing vis is added', async function () {
const originalPanelCount = await PageObjects.dashboard.getPanelCount();
await dashboardAddPanel.addVisualization('new viz panel');
await PageObjects.dashboard.clickCancelOutOfEditMode();
// confirm lose changes
await PageObjects.common.clickConfirmOnModal();
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(originalPanelCount);
});
});
describe('and preserves edits on cancel', function () {
it('when time changed is stored with dashboard', async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
await PageObjects.timePicker.setAbsoluteRange(
'Sep 19, 2013 @ 06:31:44.000',
'Sep 19, 2013 @ 06:31:44.000'
);
await PageObjects.dashboard.saveDashboard(dashboardName, true);
await PageObjects.dashboard.switchToEditMode();
await PageObjects.timePicker.setAbsoluteRange(
'Sep 19, 2015 @ 06:31:44.000',
'Sep 19, 2015 @ 06:31:44.000'
);
await PageObjects.dashboard.clickCancelOutOfEditMode();
await PageObjects.common.clickCancelOnModal();
await PageObjects.dashboard.saveDashboard(dashboardName, {
storeTimeWithDashboard: true,
});
await PageObjects.dashboard.loadSavedDashboard(dashboardName);
const time = await PageObjects.timePicker.getTimeConfig();
expect(time.start).to.equal('Sep 19, 2015 @ 06:31:44.000');
expect(time.end).to.equal('Sep 19, 2015 @ 06:31:44.000');
});
});
});
describe('and preserves edits on cancel', function () {
it('when time changed is stored with dashboard', async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
await PageObjects.timePicker.setDefaultDataRange();
await PageObjects.dashboard.saveDashboard(dashboardName, true);
await PageObjects.dashboard.switchToEditMode();
await PageObjects.timePicker.setAbsoluteRange(
'Sep 19, 2013 @ 06:31:44.000',
'Sep 19, 2013 @ 06:31:44.000'
);
const newTime = await PageObjects.timePicker.getTimeConfig();
await PageObjects.dashboard.clickCancelOutOfEditMode();
await PageObjects.common.clickCancelOnModal();
await PageObjects.dashboard.saveDashboard(dashboardName, { storeTimeWithDashboard: true });
await PageObjects.dashboard.loadSavedDashboard(dashboardName);
const time = await PageObjects.timePicker.getTimeConfig();
expect(time.start).to.equal(newTime.start);
expect(time.end).to.equal(newTime.end);
});
});
describe('Does not show lose changes warning', function () {
it('when time changed is not stored with dashboard', async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
await PageObjects.dashboard.saveDashboard(dashboardName, { storeTimeWithDashboard: false });
await PageObjects.dashboard.switchToEditMode();
await PageObjects.timePicker.setAbsoluteRange(
'Oct 19, 2014 @ 06:31:44.000',
'Dec 19, 2014 @ 06:31:44.000'
);
await PageObjects.dashboard.clickCancelOutOfEditMode();
await PageObjects.common.expectConfirmModalOpenState(false);
});
// See https://github.com/elastic/kibana/issues/10110 - this is intentional.
it('when the query is edited but not applied', async function () {
await PageObjects.dashboard.gotoDashboardEditMode(dashboardName);
const originalQuery = await queryBar.getQueryString();
await queryBar.setQuery(`${originalQuery}extra stuff`);
await PageObjects.dashboard.clickCancelOutOfEditMode();
await PageObjects.common.expectConfirmModalOpenState(false);
await PageObjects.dashboard.loadSavedDashboard(dashboardName);
const query = await queryBar.getQueryString();
expect(query).to.equal(originalQuery);
});
});
});
}