Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge index management to index-operation-common #509

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 273 additions & 0 deletions cypress/integration/create_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { PLUGIN_NAME } from "../support/constants";

const SAMPLE_INDEX = "index-specific-index";

describe("Create Index", () => {
before(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");
cy.deleteAllIndices();
cy.deleteTemplate("index-common-template");
cy.deleteTemplate("index-specific-template");
cy.createIndexTemplate("index-common-template", {
index_patterns: ["index-*"],
template: {
aliases: {
alias_for_common_1: {},
alias_for_common_2: {},
},
settings: {
number_of_shards: 2,
number_of_replicas: 1,
},
},
});
cy.createIndexTemplate("index-specific-template", {
index_patterns: ["index-specific-*"],
priority: 1,
template: {
aliases: {
alias_for_specific_1: {},
},
settings: {
number_of_shards: 3,
number_of_replicas: 2,
},
mappings: {
properties: {
text: {
type: "text",
},
},
},
},
});
});

describe("can be created and updated", () => {
beforeEach(() => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/indices`);
cy.contains("Rows per page", { timeout: 60000 });
});

it("Create a 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(SAMPLE_INDEX).blur();

cy.wait(1000);

cy.get('[data-test-subj="comboBoxSearchInput"]').get('[title="alias_for_specific_1"]').should("exist");

cy.get('[data-test-subj="comboBoxSearchInput"]').type("some_test_alias{enter}");

cy.get('[data-test-subj="editorTypeJsonEditor"]').click().end();

cy.get('[data-test-subj="mappingsJsonEditorFormRow"] [data-test-subj="jsonEditor-valueDisplay"]').should(($editor) => {
expect(JSON.parse($editor.val())).to.deep.equal({
properties: {
text: {
type: "text",
},
},
});
});

cy.get('[data-test-subj="mappingsJsonEditorFormRow"] .ace_text-input')
.focus()
.clear({ force: true })
.type(
JSON.stringify({
properties: {
text: {
type: "text",
},
},
dynamic: true,
}),
{ parseSpecialCharSequences: false, force: true }
)
.end()
.wait(1000)
.get('[data-test-subj="editorTypeVisualEditor"]')
.click()
.end();

// add a field
cy.get('[data-test-subj="createIndexAddFieldButton"]').click().end();
cy.get('[data-test-subj="mapping-visual-editor-1-field-name"]').type("text_mappings");

// click create
cy.get('[data-test-subj="createIndexCreateButton"]').click({ force: true });

// The index should exist
cy.get(`#_selection_column_${SAMPLE_INDEX}-checkbox`).should("have.exist");

// check the index detail
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/create-index/${SAMPLE_INDEX}`);

// index name and alias should exist
cy.get(`[title="${SAMPLE_INDEX}"]`)
.should("have.exist")
.end()
.get('[title="some_test_alias"]')
.should("have.exist")
.end()
.get('[data-test-subj="mapping-visual-editor-0-field-type"]')
.should("have.attr", "title", "text")
.end()
.get('[data-test-subj="mapping-visual-editor-1-field-name"]')
.should("have.attr", "title", "text_mappings")
.end()
.get('[data-test-subj="editorTypeJsonEditor"]')
.click()
.end()
.get('[data-test-subj="mappingsJsonEditorFormRow"] [data-test-subj="jsonEditor-valueDisplay"]')
.should(($editor) => {
expect(JSON.parse($editor.val())).to.deep.equal({
dynamic: "true",
properties: {},
});
});
});

it("Update alias successfully", () => {
cy.get(`[data-test-subj="viewIndexDetailButton-${SAMPLE_INDEX}"]`)
.click()
.get("#indexDetailModalAlias")
.click()
.get('[data-test-subj="detailModalEdit"]')
.click()
.end();

// add a alias and remove the exist alias
cy.get('[data-test-subj="comboBoxSearchInput"]')
.type("some_new_test_alias{enter}")
.end()
.get('[title="some_test_alias"] .euiBadge__iconButton')
.click()
.end()
.get('[data-test-subj="createIndexCreateButton"]')
.click({ force: true })
.end();

cy.get('[title="some_test_alias"]').should("not.exist").end().get('[title="some_new_test_alias"]').should("exist").end();
});

it("Update settings successfully", () => {
cy.get(`[data-test-subj="viewIndexDetailButton-${SAMPLE_INDEX}"]`)
.click()
.get("#indexDetailModalSettings")
.click()
.get('[data-test-subj="detailModalEdit"]')
.click()
.end();

cy.get('[data-test-subj="index-form-in-index-detail"] [aria-controls="accordionForCreateIndexSettings"]')
.click()
.end()
.get('[data-test-subj="index-form-in-index-detail"] .ace_text-input')
.focus()
.clear({ force: true })
.type('{ "index.blocks.write": true, "index.number_of_shards": 2, "index.number_of_replicas": 3 }', {
parseSpecialCharSequences: false,
force: true,
});

cy.get('[data-test-subj="createIndexCreateButton"]').click({ force: true });

cy.contains(`Can't update non dynamic settings`).should("exist");

cy.get('[data-test-subj="index-form-in-index-detail"] .ace_text-input')
.focus()
.clear({ force: true })
.type('{ "index.blocks.write": true }', { parseSpecialCharSequences: false, force: true })
.end()
.wait(1000)
.get('[data-test-subj="index-form-in-index-detail"] [placeholder="The number of replica shards each primary shard should have."]')
.clear()
.type(2)
.end();

cy.get('[data-test-subj="createIndexCreateButton"]').click({ force: true });

cy.wait(1000).get('[data-test-subj="form-name-index.number_of_replicas"] .euiText').should("have.text", "2");
});

it("Update mappings successfully", () => {
cy.get(`[data-test-subj="viewIndexDetailButton-${SAMPLE_INDEX}"]`)
.click()
.get("#indexDetailModalMappings")
.click()
.get('[data-test-subj="detailModalEdit"]')
.click()
.end();

cy.get('[data-test-subj="createIndexAddFieldButton"]')
.click()
.end()
.get('[data-test-subj="mapping-visual-editor-2-field-name"]')
.type("text_mappings_2")
.end()
.get('[data-test-subj="createIndexCreateButton"]')
.click({ force: true });

cy.get('[data-test-subj="mapping-visual-editor-2-field-type"]').should("have.attr", "title", "text").end();

cy.get('[data-test-subj="detailModalEdit"]')
.click()
.end()
.get('[data-test-subj="index-form-in-index-detail"] [data-test-subj="editorTypeJsonEditor"]')
.click()
.end()
.get('[data-test-subj="index-form-in-index-detail"] .ace_text-input')
.focus()
.clear({ force: true })
.type('{ "dynamic": true }', { parseSpecialCharSequences: false, force: true })
.end()
.wait(1000)
.get('[data-test-subj="createIndexCreateButton"]')
.click({ force: true });

cy.wait(1000)
.get('[data-test-subj="editorTypeJsonEditor"]')
.click()
.end()
.get('[data-test-subj="jsonEditor-valueDisplay"]')
.should(
"have.text",
JSON.stringify(
{
dynamic: "true",
properties: {
text: {
type: "text",
},
text_mappings: {
type: "text",
},
text_mappings_2: {
type: "text",
},
},
},
null,
2
)
);
});
});

after(() => {
cy.deleteTemplate("index-common-template");
cy.deleteTemplate("index-specific-template");
});
});
Loading