-
Notifications
You must be signed in to change notification settings - Fork 115
/
transforms_spec.js
293 lines (228 loc) · 8.92 KB
/
transforms_spec.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { BASE_PATH, IM_PLUGIN_NAME } from '../../../utils/constants';
import sampleTransform from '../../../fixtures/plugins/index-management-dashboards-plugin/sample_transform';
const TRANSFORM_ID = 'test_transform_id';
describe('Transforms', () => {
before(() => {
// Delete all indices
cy.deleteAllIndices();
cy.deleteIMJobs();
// Load ecommerce data
cy.request({
method: 'POST',
url: `${BASE_PATH}/api/sample_data/ecommerce`,
headers: {
'osd-xsrf': true,
},
}).then((response) => {
expect(response.status).equal(200);
});
});
beforeEach(() => {
// delete test transform and index
cy.request('DELETE', `${Cypress.env('openSearchUrl')}/test_transform*`);
cy.request({
method: 'POST',
url: `${Cypress.env(
'openSearchUrl'
)}/_plugins/_transform/${TRANSFORM_ID}/_stop`,
failOnStatusCode: false,
});
cy.request({
method: 'DELETE',
url: `${Cypress.env(
'openSearchUrl'
)}/_plugins/_transform/${TRANSFORM_ID} `,
failOnStatusCode: false,
});
// Set welcome screen tracking to test_transform_target
localStorage.setItem('home:welcome:show', true);
// Visit ISM Transforms Dashboard
cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/transforms`);
// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains('Create transform', { timeout: 60000 });
});
describe('can be created', () => {
it('successfully', () => {
// Confirm we loaded empty state
cy.contains(
'Transform jobs help you create a materialized view on top of existing data.'
);
// Route to create transform page
cy.contains('Create transform').click({ force: true });
// Type in transform ID
cy.get(`input[placeholder="my-transformjob1"]`).type(TRANSFORM_ID, {
force: true,
});
// Get description input box
cy.get(`textarea[data-test-subj="description"]`)
.focus()
.type('some description');
// Enter source index
cy.get(`div[data-test-subj="sourceIndexCombobox"]`)
.find(`input[data-test-subj="comboBoxSearchInput"]`)
.focus()
.type('opensearch_dashboards_sample_data_ecommerce{enter}');
// Enter target index
cy.get(`div[data-test-subj="targetIndexCombobox"]`)
.find(`input[data-test-subj="comboBoxSearchInput"]`)
.focus()
.type('test_transform{enter}');
// Click the next button
cy.get('button').contains('Next').click({ force: true });
// Confirm that we got to step 2 of creation page
cy.contains('Select fields to transform');
cy.get(`button[data-test-subj="category.keywordOptionsPopover"]`).click({
force: true,
});
cy.contains('Group by terms').click({ force: true });
// Confirm group was added
cy.contains('category.keyword_terms');
// Add aggregable field
cy.contains('50 columns hidden').click({ force: true });
cy.contains('taxless_total_price').click({ force: true });
// Click out of the window
cy.contains('Select fields to transform').click({ force: true });
cy.get(
`button[data-test-subj="taxless_total_priceOptionsPopover"]`
).click({ force: true });
cy.contains('Aggregate by avg').click({ force: true });
// Confirm agg was added
cy.contains('avg_taxless_total_price');
// Click the next button
cy.get('button').contains('Next').click({ force: true });
// Confirm that we got to step 3 of creation page
cy.contains('Job enabled by default');
// Click the next button
cy.get('button').contains('Next').click({ force: true });
// Confirm that we got to step 4 of creation page
cy.contains('Review and create');
// Click the create button
cy.get('button').contains('Create').click({ force: true });
// Verify that sample data is add by checking toast notification
cy.contains(`Transform job "${TRANSFORM_ID}" successfully created.`);
cy.location('hash').should('contain', 'transforms');
cy.get(`button[data-test-subj="transformLink_${TRANSFORM_ID}"]`);
});
});
describe('can be edited', () => {
beforeEach(() => {
cy.createTransform(TRANSFORM_ID, sampleTransform);
cy.reload();
});
it('successfully', () => {
// Confirm we have our initial transform
cy.contains(TRANSFORM_ID);
// Select checkbox for our transform
cy.get(`#_selection_column_${TRANSFORM_ID}-checkbox`).check({
force: true,
});
// Click on Actions popover menu
cy.get(`[data-test-subj="actionButton"]`).click({ force: true });
// Click Edit button
cy.get(`[data-test-subj="editButton"]`).click({ force: true });
// Wait for initial transform job to load
cy.contains('Test transform');
cy.get(`textArea[data-test-subj="description"]`)
.focus()
.clear()
.type('A new description');
// Click Save changes button
cy.get(`[data-test-subj="editTransformSaveButton"]`).click({
force: true,
});
// Extra wait required for page data to load, otherwise "Enable" button will be disabled
cy.wait(2000);
// Confirm we get toaster saying changes saved
cy.contains(`Changes to transform saved`);
// Click into transform job details page
cy.get(`[data-test-subj="transformLink_${TRANSFORM_ID}"]`).click({
force: true,
});
// Confirm new description shows in details page
cy.contains('A new description');
});
});
describe('can be deleted', () => {
beforeEach(() => {
cy.createTransform(TRANSFORM_ID, sampleTransform);
cy.reload();
});
it('successfully', () => {
// Confirm we have our initial transform
cy.contains(TRANSFORM_ID);
// Disable transform
cy.get(`#_selection_column_${TRANSFORM_ID}-checkbox`).check({
force: true,
});
cy.get(`[data-test-subj="disableButton"]`).click({ force: true });
cy.contains(`"${TRANSFORM_ID}" is disabled`);
// Select checkbox for our transform job
cy.get(`#_selection_column_${TRANSFORM_ID}-checkbox`).check({
force: true,
});
// Click on Actions popover menu
cy.get(`[data-test-subj="actionButton"]`).click({ force: true });
// Click Delete button
cy.get(`[data-test-subj="deleteButton"]`).click({ force: true });
// Type "delete" to confirm deletion
cy.get(`input[placeholder="delete"]`).type('delete', { force: true });
// Click the delete confirmation button in modal
cy.get(`[data-test-subj="confirmModalConfirmButton"]`).click();
// Confirm we got deleted toaster
cy.contains(`"${TRANSFORM_ID}" successfully deleted`);
// Confirm showing empty loading state
cy.contains(
'Transform jobs help you create a materialized view on top of existing data.'
);
});
});
describe('can be enabled and disabled', () => {
beforeEach(() => {
cy.createTransform(TRANSFORM_ID, sampleTransform);
cy.reload();
});
it('successfully', () => {
// Confirm we have our initial transform
cy.contains(TRANSFORM_ID);
// Intercept different transform requests endpoints to wait before clicking disable and enable buttons
cy.intercept(`/api/ism/transforms/${TRANSFORM_ID}`).as('getTransform');
cy.intercept(`/api/ism/transforms/${TRANSFORM_ID}/_stop`).as(
'stopTransform'
);
// Click into transform job details page
cy.get(`[data-test-subj="transformLink_${TRANSFORM_ID}"]`).click({
force: true,
});
cy.contains(`${TRANSFORM_ID}`);
/* Wait required for page data to load, otherwise "Disable" button will
* appear greyed out and unavailable. Cypress automatically retries,
* but only after menu is open, doesn't re-render.
*/
cy.wait('@getTransform').wait(2000);
// Click into Actions menu
cy.get(`[data-test-subj="actionButton"]`).click({ force: true });
// Click Disable button
cy.get(`[data-test-subj="disableButton"]`)
.should('not.be.disabled')
.click();
cy.wait('@stopTransform');
cy.wait('@getTransform');
// Confirm we get toaster saying transform job is disabled
cy.contains(`"${TRANSFORM_ID}" is disabled`);
// Extra wait required for page data to load, otherwise "Enable" button will be disabled
cy.wait(2000);
// Click into Actions menu
cy.get(`[data-test-subj="actionButton"]`).click({ force: true });
// Click Enable button
cy.get(`[data-test-subj="enableButton"]`)
.should('not.be.disabled')
.click({ force: true });
// Confirm we get toaster saying transform job is enabled
cy.contains(`"${TRANSFORM_ID}" is enabled`);
});
});
});