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

[Backport main] Merge 2.5 changes to 2.x #557

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
119 changes: 119 additions & 0 deletions cypress/integration/aliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { PLUGIN_NAME } from "../support/constants";

const SAMPLE_INDEX_PREFIX = "index-for-alias-test";
const SAMPLE_ALIAS_PREFIX = "alias-for-test";
const CREATE_ALIAS = "create-alias";
const EDIT_INDEX = "index-edit-index-for-alias-test";

describe("Aliases", () => {
before(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");
cy.deleteAllIndices();
for (let i = 0; i < 11; i++) {
cy.createIndex(`${SAMPLE_INDEX_PREFIX}-${i}`, null);
}
cy.createIndex(EDIT_INDEX, null);
for (let i = 0; i < 30; i++) {
cy.addAlias(`${SAMPLE_ALIAS_PREFIX}-${i}`, `${SAMPLE_INDEX_PREFIX}-${i % 11}`);
}
cy.removeAlias(`${SAMPLE_ALIAS_PREFIX}-0`);
cy.addAlias(`${SAMPLE_ALIAS_PREFIX}-0`, `${SAMPLE_INDEX_PREFIX}-*`);
});

beforeEach(() => {
// Visit ISM OSD
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/aliases`);

// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains("Rows per page", { timeout: 60000 });
});

describe("can be searched / sorted / paginated", () => {
it("successfully", () => {
cy.get('[data-test-subj="pagination-button-1"]').should("exist");
cy.get('[placeholder="Search..."]').type("alias-for-test-0{enter}");
cy.contains("alias-for-test-0");
cy.get(".euiTableRow").should("have.length", 1);
cy.get('[data-test-subj="comboBoxSearchInput"]').type("closed{enter}");

cy.contains("There are no aliases matching your applied filters. Reset your filters to view your aliases.");
});
});

describe("shows more modal", () => {
it("successfully", () => {
cy.get('[placeholder="Search..."]').type("alias-for-test-0{enter}");
cy.contains("alias-for-test-0");
cy.get(".euiTableRow").should("have.length", 1);
cy.get('.euiTableRowCell [data-test-subj="8 more"]')
.click()
.get('[data-test-subj="indices-table"] .euiTableRow')
.should("have.length", 10);
});
});

describe("can create a alias with wildcard and specific name", () => {
it("successfully", () => {
cy.get('[data-test-subj="Create AliasButton"]').click();
cy.get('[data-test-subj="form-name-alias"]').type(CREATE_ALIAS);
cy.get('[data-test-subj="form-name-indexArray"] [data-test-subj="comboBoxSearchInput"]').type(
`${EDIT_INDEX}{enter}${SAMPLE_INDEX_PREFIX}-*{enter}`
);
cy.get(".euiModalFooter .euiButton--fill").click({ force: true }).get('[data-test-subj="9 more"]').should("exist");
});
});

describe("can edit / delete a alias", () => {
it("successfully", () => {
cy.get('[placeholder="Search..."]').type(`${SAMPLE_ALIAS_PREFIX}-0{enter}`);
cy.contains(`${SAMPLE_ALIAS_PREFIX}-0`);
cy.get('[data-test-subj="moreAction"] button')
.click()
.get('[data-test-subj="editAction"]')
.should("be.disabled")
.get(`#_selection_column_${SAMPLE_ALIAS_PREFIX}-0-checkbox`)
.click()
.get('[data-test-subj="moreAction"] button')
.click()
.get('[data-test-subj="editAction"]')
.click()
.get('[data-test-subj="form-name-indexArray"] [data-test-subj="comboBoxInput"]')
.click()
.type(`${EDIT_INDEX}{enter}`)
.get(`[title="${SAMPLE_INDEX_PREFIX}-0"] button`)
.click()
.get(`[title="${SAMPLE_INDEX_PREFIX}-1"] button`)
.click()
.get(".euiModalFooter .euiButton--fill")
.click({ force: true })
.end();

cy.get('[data-test-subj="7 more"]').should("exist");

cy.get('[data-test-subj="moreAction"] button').click().get('[data-test-subj="deleteAction"]').click();
// The confirm button should be disabled
cy.get('[data-test-subj="deleteConfirmButton"]').should("be.disabled");
// type delete
cy.wait(500).get('[data-test-subj="deleteInput"]').type("delete");
cy.get('[data-test-subj="deleteConfirmButton"]').should("not.be.disabled");
// click to delete
cy.get('[data-test-subj="deleteConfirmButton"]').click();
// the alias should not exist
cy.wait(500);
cy.get(`#_selection_column_${SAMPLE_ALIAS_PREFIX}-0-checkbox`).should("not.exist");
});
});

after(() => {
cy.deleteAllIndices();
for (let i = 0; i < 30; i++) {
cy.removeAlias(`${SAMPLE_ALIAS_PREFIX}-${i}`);
}
cy.removeAlias(CREATE_ALIAS);
});
});
257 changes: 257 additions & 0 deletions cypress/integration/create_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/*
* 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();

// 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();

cy.get('[aria-controls="accordionForCreateIndexSettings"]')
.click()
.end()
.get(".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,
})
.blur();

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

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

cy.get(".ace_text-input")
.focus()
.clear({ force: true })
.type('{ "index.blocks.write": true, "index.number_of_shards": "3" }', { parseSpecialCharSequences: false, force: true })
.end()
.wait(1000)
.get('[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"] input').should("have.value", "2");
});

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

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="editorTypeJsonEditor"]')
.click()
.end()
.get(".ace_text-input")
.focus()
.clear({ force: true })
.type('{ "dynamic": true }', { parseSpecialCharSequences: false, force: true })
.blur()
.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="previousMappingsJsonButton"]')
.click()
.end()
.get('[data-test-subj="previousMappingsJsonModal"] [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