|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + * |
| 8 | + * Modifications Copyright OpenSearch Contributors. See |
| 9 | + * GitHub history for details. |
| 10 | + */ |
| 11 | + |
| 12 | +import { PLUGIN_NAME } from "../support/constants"; |
| 13 | +import sampleTransform from "../fixtures/sample_transform"; |
| 14 | + |
| 15 | +const TRANSFORM_ID = "test_transform_id"; |
| 16 | + |
| 17 | +describe("Transforms", () => { |
| 18 | + before(() => { |
| 19 | + // Delete all indices |
| 20 | + cy.deleteAllIndices(); |
| 21 | + |
| 22 | + // Load ecommerce data |
| 23 | + cy.request({ |
| 24 | + method: 'POST', |
| 25 | + url:`${Cypress.env("opensearch_dashboards")}/api/sample_data/ecommerce`, |
| 26 | + headers: { |
| 27 | + 'osd-xsrf': true |
| 28 | + } |
| 29 | + }).then((response) => { |
| 30 | + expect(response.status).equal(200); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + beforeEach(() => { |
| 35 | + // delete test transform and index |
| 36 | + cy.request("DELETE", `${Cypress.env("opensearch")}/test_transform*`); |
| 37 | + cy.request({ |
| 38 | + method: 'POST', |
| 39 | + url: `${Cypress.env("opensearch")}/_plugins/_transform/${TRANSFORM_ID}/_stop`, |
| 40 | + failOnStatusCode: false |
| 41 | + }); |
| 42 | + cy.request({ |
| 43 | + method: 'DELETE', |
| 44 | + url: `${Cypress.env("opensearch")}/_plugins/_transform/${TRANSFORM_ID} `, |
| 45 | + failOnStatusCode: false |
| 46 | + }); |
| 47 | + |
| 48 | + // Set welcome screen tracking to test_transform_target |
| 49 | + localStorage.setItem("home:welcome:show", true); |
| 50 | + |
| 51 | + // Visit ISM Transforms Dashboard |
| 52 | + cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/transforms`); |
| 53 | + |
| 54 | + // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load |
| 55 | + cy.contains("Create transform", { timeout: 60000 }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe("can be created", () => { |
| 59 | + it("successfully", () => { |
| 60 | + // Confirm we loaded empty state |
| 61 | + cy.contains( |
| 62 | + "Transform jobs help you create a materialized view on top of existing data." |
| 63 | + ); |
| 64 | + |
| 65 | + // Route to create transform page |
| 66 | + cy.contains("Create transform").click({ force: true }); |
| 67 | + |
| 68 | + // Type in transform ID |
| 69 | + cy.get(`input[placeholder="my-transformjob1"]`).type(TRANSFORM_ID, { force: true }); |
| 70 | + |
| 71 | + // Get description input box |
| 72 | + cy.get(`textarea[data-test-subj="description"]`).focus().type("some description"); |
| 73 | + |
| 74 | + // Enter source index |
| 75 | + cy.get(`div[data-test-subj="sourceIndexCombobox"]`) |
| 76 | + .find(`input[data-test-subj="comboBoxSearchInput"]`) |
| 77 | + .focus() |
| 78 | + .type("opensearch_dashboards_sample_data_ecommerce{enter}"); |
| 79 | + |
| 80 | + // Enter target index |
| 81 | + cy.get(`div[data-test-subj="targetIndexCombobox"]`) |
| 82 | + .find(`input[data-test-subj="comboBoxSearchInput"]`) |
| 83 | + .focus() |
| 84 | + .type("test_transform{enter}"); |
| 85 | + |
| 86 | + // Click the next button |
| 87 | + cy.get("button").contains("Next").click({ force: true }); |
| 88 | + |
| 89 | + // Confirm that we got to step 2 of creation page |
| 90 | + cy.contains("Select fields to transform"); |
| 91 | + |
| 92 | + cy.get(`button[data-test-subj="category.keywordOptionsPopover"]`) |
| 93 | + .click({ force: true }); |
| 94 | + |
| 95 | + cy.contains("Group by terms").click({ force: true }); |
| 96 | + |
| 97 | + // Confirm group was added |
| 98 | + cy.contains("category.keyword_terms"); |
| 99 | + |
| 100 | + // Add aggregable field |
| 101 | + cy.contains("50 columns hidden").click({ force: true }); |
| 102 | + cy.contains("taxless_total_price").click({ force: true }); |
| 103 | + // Click out of the window |
| 104 | + cy.contains("Select fields to transform").click({ force: true }); |
| 105 | + |
| 106 | + cy.get(`button[data-test-subj="taxless_total_priceOptionsPopover"]`) |
| 107 | + .click({ force: true }); |
| 108 | + |
| 109 | + cy.contains("Aggregate by avg").click({ force: true }); |
| 110 | + |
| 111 | + // Confirm agg was added |
| 112 | + cy.contains("avg_taxless_total_price"); |
| 113 | + |
| 114 | + // Click the next button |
| 115 | + cy.get("button").contains("Next").click({ force: true }); |
| 116 | + |
| 117 | + // Confirm that we got to step 3 of creation page |
| 118 | + cy.contains("Job enabled by default"); |
| 119 | + |
| 120 | + // Click the next button |
| 121 | + cy.get("button").contains("Next").click({ force: true }); |
| 122 | + |
| 123 | + // Confirm that we got to step 4 of creation page |
| 124 | + cy.contains("Review and create"); |
| 125 | + |
| 126 | + // Click the create button |
| 127 | + cy.get("button").contains("Create").click({ force: true }); |
| 128 | + |
| 129 | + // Verify that sample data is add by checking toast notification |
| 130 | + cy.contains(`Transform job "${TRANSFORM_ID}" successfully created.`); |
| 131 | + cy.location('hash').should('contain', 'transforms'); |
| 132 | + cy.get(`button[data-test-subj="transformLink_${TRANSFORM_ID}"]`); |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + describe("can be edited", () => { |
| 137 | + beforeEach(() => { |
| 138 | + cy.createTransform(TRANSFORM_ID, sampleTransform); |
| 139 | + cy.reload(); |
| 140 | + }); |
| 141 | + |
| 142 | + it("successfully", () => { |
| 143 | + // Confirm we have our initial transform |
| 144 | + cy.contains(TRANSFORM_ID); |
| 145 | + |
| 146 | + // Select checkbox for our transform |
| 147 | + cy.get(`#_selection_column_${TRANSFORM_ID}-checkbox`) |
| 148 | + .check({ force: true }); |
| 149 | + |
| 150 | + // Click on Actions popover menu |
| 151 | + cy.get(`[data-test-subj="actionButton"]`).click({ force: true }); |
| 152 | + |
| 153 | + // Click Edit button |
| 154 | + cy.get(`[data-test-subj="editButton"]`).click({ force: true }); |
| 155 | + |
| 156 | + // Wait for initial transform job to load |
| 157 | + cy.contains("Test transform"); |
| 158 | + |
| 159 | + cy.get(`textArea[data-test-subj="description"]`).focus().clear().type("A new description"); |
| 160 | + |
| 161 | + // Click Save changes button |
| 162 | + cy.get(`[data-test-subj="editTransformSaveButton"]`).click({ force: true }); |
| 163 | + |
| 164 | + // Confirm we get toaster saying changes saved |
| 165 | + cy.contains(`Changes to transform saved`); |
| 166 | + |
| 167 | + // Click into transform job details page |
| 168 | + cy.get(`[data-test-subj="transformLink_${TRANSFORM_ID}"]`).click({ force: true }); |
| 169 | + |
| 170 | + // Confirm new description shows in details page |
| 171 | + cy.contains("A new description"); |
| 172 | + }); |
| 173 | + }); |
| 174 | + |
| 175 | + describe("can be deleted", () => { |
| 176 | + beforeEach(() => { |
| 177 | + cy.createTransform(TRANSFORM_ID, sampleTransform); |
| 178 | + cy.reload(); |
| 179 | + }); |
| 180 | + |
| 181 | + it("successfully", () => { |
| 182 | + // Confirm we have our initial transform |
| 183 | + cy.contains(TRANSFORM_ID); |
| 184 | + |
| 185 | + // Disable transform |
| 186 | + cy.get(`#_selection_column_${TRANSFORM_ID}-checkbox`).check({ force: true }); |
| 187 | + cy.get(`[data-test-subj="disableButton"]`).click({ force: true }); |
| 188 | + cy.contains(`"${TRANSFORM_ID}" is disabled`); |
| 189 | + |
| 190 | + // Select checkbox for our transform job |
| 191 | + cy.get(`#_selection_column_${TRANSFORM_ID}-checkbox`).check({ force: true }); |
| 192 | + |
| 193 | + // Click on Actions popover menu |
| 194 | + cy.get(`[data-test-subj="actionButton"]`).click({ force: true }); |
| 195 | + |
| 196 | + // Click Delete button |
| 197 | + cy.get(`[data-test-subj="deleteButton"]`).click({ force: true }); |
| 198 | + |
| 199 | + // Type "delete" to confirm deletion |
| 200 | + cy.get(`input[placeholder="delete"]`).type("delete", { force: true }); |
| 201 | + |
| 202 | + // Click the delete confirmation button in modal |
| 203 | + cy.get(`[data-test-subj="confirmModalConfirmButton"]`).click(); |
| 204 | + |
| 205 | + // Confirm we got deleted toaster |
| 206 | + cy.contains(`"${TRANSFORM_ID}" successfully deleted`); |
| 207 | + |
| 208 | + // Confirm showing empty loading state |
| 209 | + cy.contains( |
| 210 | + "Transform jobs help you create a materialized view on top of existing data." |
| 211 | + ); |
| 212 | + }); |
| 213 | + }); |
| 214 | + |
| 215 | + describe("can be enabled and disabled", () => { |
| 216 | + beforeEach(() => { |
| 217 | + cy.createTransform(TRANSFORM_ID, sampleTransform); |
| 218 | + cy.reload(); |
| 219 | + }); |
| 220 | + |
| 221 | + it("successfully", () => { |
| 222 | + // Confirm we have our initial transform |
| 223 | + cy.contains(TRANSFORM_ID); |
| 224 | + |
| 225 | + // Click into transform job details page |
| 226 | + cy.get(`[data-test-subj="transformLink_${TRANSFORM_ID}"]`).click({ force: true }); |
| 227 | + |
| 228 | + cy.contains(`${TRANSFORM_ID}`); |
| 229 | + |
| 230 | + /* Wait required for page data to load, otherwise "Disable" button will |
| 231 | + * appear greyed out and unavailable. Cypress automatically retries, |
| 232 | + * but only after menu is open, doesn't re-render. |
| 233 | + */ |
| 234 | + cy.wait(1000); |
| 235 | + |
| 236 | + // Click into Actions menu |
| 237 | + cy.get(`[data-test-subj="actionButton"]`).click({ force: true }); |
| 238 | + |
| 239 | + // Click Disable button |
| 240 | + cy.get(`[data-test-subj="disableButton"]`).click(); |
| 241 | + |
| 242 | + // Confirm we get toaster saying transform job is disabled |
| 243 | + cy.contains(`"${TRANSFORM_ID}" is disabled`); |
| 244 | + |
| 245 | + cy.wait(1000); |
| 246 | + |
| 247 | + // Click into Actions menu |
| 248 | + cy.get(`[data-test-subj="actionButton"]`).click({ force: true }); |
| 249 | + |
| 250 | + // Click Enable button |
| 251 | + cy.get(`[data-test-subj="enableButton"]`).click({ force: true }); |
| 252 | + |
| 253 | + // Confirm we get toaster saying transform job is enabled |
| 254 | + cy.contains(`"${TRANSFORM_ID}" is enabled`); |
| 255 | + }); |
| 256 | + }) |
| 257 | +}); |
0 commit comments