diff --git a/.github/actions/run-cypress-tests/action.yaml b/.github/actions/run-cypress-tests/action.yaml index c33d13cdf..692fe942a 100644 --- a/.github/actions/run-cypress-tests/action.yaml +++ b/.github/actions/run-cypress-tests/action.yaml @@ -127,7 +127,7 @@ runs: if: ${{ inputs.with-security == 'false' }} with: working-directory: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin - command: yarn run cypress run --config-file cypress.config.js + command: yarn run cypress run wait-on: 'http://localhost:5601' browser: chrome - name: Cypress tests @@ -135,7 +135,7 @@ runs: if: ${{ inputs.with-security == 'true' }} with: working-directory: OpenSearch-Dashboards/plugins/index-management-dashboards-plugin - command: yarn run cypress run --config-file cypress.config.js --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,WAIT_FOR_LOADER_BUFFER_MS=500 + command: yarn run cypress run --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,WAIT_FOR_LOADER_BUFFER_MS=500 wait-on: 'http://localhost:5601' browser: chrome # Screenshots are only captured on failure, will change this once we do visual regression tests diff --git a/babel.config.js b/babel.config.js index 7c654bfa6..8c445f1b0 100644 --- a/babel.config.js +++ b/babel.config.js @@ -11,9 +11,17 @@ module.exports = function (api) { // Common plugins for all environments const commonPlugins = [require("@babel/plugin-proposal-nullish-coalescing-operator")]; + // Common configuration for all environments + const commonConfig = { + generatorOpts: { + maxSize: 1000000, // Increased size limit to handle larger files + }, + }; + // Test-specific configuration if (isTest) { return { + ...commonConfig, // Spread the common configuration presets: [require("@babel/preset-env"), require("@babel/preset-react"), require("@babel/preset-typescript")], plugins: [ [require("@babel/plugin-transform-runtime"), { regenerator: true }], @@ -27,6 +35,7 @@ module.exports = function (api) { // Build/dev configuration return { + ...commonConfig, // Spread the common configuration plugins: commonPlugins, }; }; diff --git a/cypress/e2e/plugins/index-management-dashboards-plugin/a_split_index.js b/cypress/e2e/plugins/index-management-dashboards-plugin/a_split_index.js new file mode 100644 index 000000000..8f64fe80e --- /dev/null +++ b/cypress/e2e/plugins/index-management-dashboards-plugin/a_split_index.js @@ -0,0 +1,93 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { IM_PLUGIN_NAME, BASE_PATH } from "../../../utils/constants"; + +const sampleIndex = "index-split"; +const sampleAlias = "alias-split"; +let splitNumber = 2; +let replicaNumber = 1; + +describe("Split Index", () => { + before(() => { + cy.window().then((win) => { + win.localStorage.clear(); + win.sessionStorage.clear(); + win.localStorage.setItem("home:welcome:show", "false"); + }); + }); + + describe("can be created and updated", () => { + beforeEach(() => { + // Clear session data between tests + Cypress.session.clearCurrentSessionData(); + + cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/indices`, { + timeout: 30000, + onBeforeLoad: (win) => { + win.sessionStorage.clear(); + win.localStorage.clear(); + }, + }); + + // Wait for page load with proper assertion + cy.contains("Rows per page", { timeout: 20000 }).should("be.visible"); + }); + + it("Create an index successfully", () => { + // enter create page + cy.get('[data-test-subj="Create IndexButton"]').click(); + cy.contains("Create index"); + + // type field name + cy.get('[placeholder="Specify a name for the new index."]').type(sampleIndex).blur(); + + cy.wait(1000); + + cy.get('[data-test-subj="comboBoxSearchInput"]').focus().type(`${sampleAlias}{enter}`).end(); + + // click create + cy.get('[data-test-subj="createIndexCreateButton"]').click().end(); + + // The index should exist + cy.get(`#_selection_column_${sampleIndex}-checkbox`).should("have.exist").end(); + + cy.get(`[data-test-subj="viewIndexDetailButton-${sampleIndex}"]`).click().end(); + cy.get("#indexDetailModalSettings").click().end(); + + cy.get('[data-test-subj="form-name-index.number_of_shards"] .euiText').then(($shardNumber) => { + splitNumber = $shardNumber.attr("title") * 2; + }); + + cy.get("#indexDetailModalAlias").click().end(); + cy.get(`[title="${sampleAlias}"]`).should("exist").end(); + + // Update Index status to blocks write otherwise we can't apply split operation on it + cy.updateIndexSettings(sampleIndex, { + "index.blocks.write": "true", + }).end(); + }); //create the index + + it("Split successfully", () => { + const targetIndex = `${sampleIndex}` + "-target"; + cy.get(`[data-test-subj="checkboxSelectRow-${sampleIndex}"]`).click().end(); + + cy.wait(3000); + cy.get('[data-test-subj="moreAction"]').click().end().get('[data-test-subj="Split Action"]').click().end(); + // Target Index Name is required + cy.get('[data-test-subj="targetIndexNameInput"]').type(`${targetIndex}`).end(); + // Number of shards after split is required + cy.get('[data-test-subj="numberOfShardsInput"]').type(`${splitNumber}{downArrow}{enter}`).end(); + cy.get('[data-test-subj="numberOfReplicasInput"]').clear().type(`${replicaNumber}`).end(); + cy.get('[data-test-subj="splitButton"]').click().end(); + + cy.wait(3000); + + cy.get(`[data-test-subj="viewIndexDetailButton-${targetIndex}"]`).click().end(); + cy.get("#indexDetailModalSettings").click().end(); + cy.get('[data-test-subj="form-name-index.number_of_shards"] .euiText').should("have.text", `${splitNumber}`).end(); + cy.get('[data-test-subj="form-name-index.number_of_replicas"] input').should("have.value", `${replicaNumber}`).end(); + }); // Split + }); +}); diff --git a/cypress/e2e/plugins/index-management-dashboards-plugin/split_index.js b/cypress/e2e/plugins/index-management-dashboards-plugin/split_index.js deleted file mode 100644 index 676537174..000000000 --- a/cypress/e2e/plugins/index-management-dashboards-plugin/split_index.js +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ -import { IM_PLUGIN_NAME, BASE_PATH } from "../../../utils/constants"; - -const sampleIndex = "index-split"; -const sampleAlias = "alias-split"; - -describe("Split Index", () => { - before(() => { - // Set welcome screen tracking to false - localStorage.setItem("home:welcome:show", "false"); - cy.deleteAllIndices(); - //let api call complete and delete all indices - cy.wait(6000); - }); - - describe("can be created and updated", () => { - beforeEach(() => { - // Visit ISM OSD - cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/indices`); - cy.contains("Rows per page", { timeout: 60000 }); - }); - - let splitNumber = 2; - let replicaNumber = 1; - it("Create an index successfully", () => { - // enter create page - cy.get('[data-test-subj="Create IndexButton"]').click(); - cy.contains("Create index"); - - // type field name - cy.get('[placeholder="Specify a name for the new index."]').type(sampleIndex).end(); - - cy.get('[data-test-subj="comboBoxSearchInput"]').focus().type(`${sampleAlias}`).end(); - - // click create - cy.get('[data-test-subj="createIndexCreateButton"]').click({ force: true }).end(); - - // The index should exist - cy.get(`#_selection_column_${sampleIndex}-checkbox`).should("have.exist").end(); - - cy.get(`[data-test-subj="viewIndexDetailButton-${sampleIndex}"]`, { timeout: 10000 }).click().end(); - cy.get("#indexDetailModalSettings").click().end(); - - cy.get('[data-test-subj="form-name-index.number_of_shards"] .euiText').then(($shardNumber) => { - splitNumber = $shardNumber.attr("title") * 2; - }); - - cy.get("#indexDetailModalAlias").click().end(); - cy.get(`[title="${sampleAlias}"]`).should("exist").end(); - - // Update Index status to blocks write otherwise we can't apply split operation on it - cy.updateIndexSettings(sampleIndex, { - "index.blocks.write": "true", - }).end(); - }); // create index - - it("Split successfully", () => { - const targetIndex = `${sampleIndex}` + "-target"; - cy.get(`[data-test-subj="checkboxSelectRow-${sampleIndex}"]`) - .click() - .end() - .get('[data-test-subj="moreAction"]') - .click() - .end() - .get('[data-test-subj="Split Action"]') - .click() - .end() - // Target Index Name is required - .get('[data-test-subj="targetIndexNameInput"]') - .type(`${targetIndex}`) - .end() - // Number of shards after split is required - .get('[data-test-subj="numberOfShardsInput"]') - .type(`${splitNumber}{downArrow}{enter}`) - .end() - .get('[data-test-subj="numberOfReplicasInput"]') - .clear() - .type(`${replicaNumber}`) - .end() - .get('[data-test-subj="splitButton"]', { timeout: 10000 }) - .click() - .end(); - - cy.wait(3000).reload(); - - cy.get(`[data-test-subj="viewIndexDetailButton-${targetIndex}"]`, { timeout: 12000 }).click().end(); - cy.get("#indexDetailModalSettings").click().end(); - cy.get('[data-test-subj="form-name-index.number_of_shards"] .euiText').should("have.text", `${splitNumber}`).end(); - cy.get('[data-test-subj="form-name-index.number_of_replicas"] input').should("have.value", `${replicaNumber}`).end(); - }); // Split - - it("Split successfully with advanced setting", () => { - const targetIndex = `${sampleIndex}` + "-setting"; - cy.get(`[data-test-subj="checkboxSelectRow-${sampleIndex}"]`) - .click() - .end() - .get('[data-test-subj="moreAction"]') - .click() - .end() - .get('[data-test-subj="Split Action"]') - .click() - .end() - .get("[data-test-subj=targetIndexNameInput]") - .type(`${targetIndex}`) - .end() - // Instead of input shard number at shard field, another option is to populate it in advanced setting - .get('[aria-controls="accordionForCreateIndexSettings"]') - .click() - .end() - .get('[data-test-subj="codeEditorContainer"] textarea') - .focus() - // Need to remove the default {} in advanced setting - .clear() - .type(`{"index.number_of_shards": "${splitNumber}", "index.number_of_replicas": "${replicaNumber}"}`, { - parseSpecialCharSequences: false, - }) - .end() - .get('[data-test-subj="splitButton"]', { timeout: 10000 }) - .click() - .end(); - - cy.wait(3000).reload(); - - cy.get(`[data-test-subj="viewIndexDetailButton-${targetIndex}"]`, { timeout: 10000 }).click().end(); - cy.get("#indexDetailModalSettings").click().end(); - cy.get('[data-test-subj="form-name-index.number_of_shards"] .euiText').should("have.text", `${splitNumber}`).end(); - cy.get('[data-test-subj="form-name-index.number_of_replicas"] input').should("have.value", `${replicaNumber}`).end(); - }); // advanced setting - - it("Split successfully with alias", () => { - const targetIndex = `${sampleIndex}` + "-alias"; - const newAlias = "alias-new"; - cy.get(`[data-test-subj="checkboxSelectRow-${sampleIndex}"]`) - .click() - .end() - .get('[data-test-subj="moreAction"]') - .click() - .end() - .get('[data-test-subj="Split Action"]') - .click() - .end() - .get("[data-test-subj=targetIndexNameInput]") - .type(`${targetIndex}`) - .end() - .get('[data-test-subj="numberOfShardsInput"]') - .type(`${splitNumber}{downArrow}{enter}`) - .end() - // Assign to an existing alias and a new alias - .get('[data-test-subj="form-name-aliases"] [data-test-subj="comboBoxSearchInput"]') - .type(`${sampleAlias}{enter}${newAlias}{enter}`) - .end() - .get('[data-test-subj="splitButton"]', { timeout: 10000 }) - .click() - .end(); - - cy.wait(3000).reload(); - - cy.get(`[data-test-subj="viewIndexDetailButton-${targetIndex}"]`, { timeout: 10000 }).click().end(); - // Verify alias associated with the new index - cy.get("#indexDetailModalAlias").click().end(); - cy.get(`[title="${newAlias}"]`).should("exist").end(); - cy.get(`[title="${sampleAlias}"]`).should("exist").end(); - }); // Create with alias - - it("Update blocks write to true", () => { - // Set index to not blocks write - cy.updateIndexSettings(sampleIndex, { - "index.blocks.write": "false", - }).end(); - cy.get(`[data-test-subj="checkboxSelectRow-${sampleIndex}"]`) - .click() - .end() - .get('[data-test-subj="moreAction"]') - .click() - .end() - .get('[data-test-subj="Split Action"]') - .click() - .end() - // Index can't be split if it's blocks write status is not true - .get('[data-test-subj="splitButton"]', { timeout: 10000 }) - .should("have.class", "euiButton-isDisabled") - .end() - .wait(1000) - // Set index to blocks write - .get('[data-test-subj="set-indexsetting-button"]') - .click() - .end() - .get('[data-test-subj="splitButton"]', { timeout: 13000 }) - .click() - .end(); - }); // Blocks write - }); -});