-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: suzhou <[email protected]>
- Loading branch information
1 parent
f3fb5d9
commit e457cc8
Showing
26 changed files
with
2,589 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("You have no aliases."); | ||
}); | ||
}); | ||
|
||
describe("shows more flyout", () => { | ||
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(".euiFlyoutFooter .euiButton--fill").click().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(".euiFlyoutFooter .euiButton--fill") | ||
.click() | ||
.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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
public/pages/Aliases/components/IndexControls/IndexControls.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from "react"; | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import { render, waitFor } from "@testing-library/react"; | ||
// @ts-ignore | ||
import userEvent from "@testing-library/user-event"; | ||
import IndexControls from "./IndexControls"; | ||
|
||
describe("<IndexControls /> spec", () => { | ||
it("renders the component", async () => { | ||
const { container } = render(<IndexControls value={{ search: "testing", status: "1" }} onSearchChange={() => {}} />); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("onChange with right data", async () => { | ||
const onSearchChangeMock = jest.fn(); | ||
const { getByTestId, getByPlaceholderText } = render( | ||
<IndexControls value={{ search: "", status: "" }} onSearchChange={onSearchChangeMock} /> | ||
); | ||
|
||
userEvent.type(getByTestId("comboBoxSearchInput"), "closed{enter}"); | ||
expect(onSearchChangeMock).toBeCalledTimes(1); | ||
expect(onSearchChangeMock).toBeCalledWith({ | ||
search: "", | ||
status: "closed", | ||
}); | ||
userEvent.type(getByPlaceholderText("Search..."), "test"); | ||
await waitFor(() => { | ||
expect(onSearchChangeMock).toBeCalledTimes(5); | ||
expect(onSearchChangeMock).toBeCalledWith({ | ||
search: "test", | ||
status: "closed", | ||
}); | ||
}); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
public/pages/Aliases/components/IndexControls/IndexControls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useEffect, useState } from "react"; | ||
import { EuiComboBox, EuiFieldSearch, EuiFlexGroup, EuiFlexItem } from "@elastic/eui"; | ||
import { ALIAS_STATUS_OPTIONS } from "../../../../utils/constants"; | ||
|
||
export interface SearchControlsProps { | ||
value: { | ||
search: string; | ||
status: string; | ||
}; | ||
onSearchChange: (args: SearchControlsProps["value"]) => void; | ||
} | ||
|
||
export default function SearchControls(props: SearchControlsProps) { | ||
const [state, setState] = useState<SearchControlsProps["value"]>(props.value); | ||
const onChange = <T extends keyof SearchControlsProps["value"]>(field: T, value: SearchControlsProps["value"][T]) => { | ||
const payload = { | ||
...state, | ||
[field]: value, | ||
}; | ||
setState(payload); | ||
props.onSearchChange(payload); | ||
}; | ||
useEffect(() => { | ||
setState(props.value); | ||
}, [props.value]); | ||
return ( | ||
<EuiFlexGroup style={{ padding: "0px 5px" }} alignItems="center"> | ||
<EuiFlexItem> | ||
<EuiFieldSearch fullWidth placeholder="Search..." value={state.search} onChange={(e) => onChange("search", e.target.value)} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiComboBox | ||
style={{ | ||
width: 150, | ||
}} | ||
singleSelection={{ | ||
asPlainText: true, | ||
}} | ||
placeholder="Status" | ||
options={ALIAS_STATUS_OPTIONS} | ||
selectedOptions={state.status ? [{ label: state.status }] : []} | ||
onChange={(val) => onChange("status", val[0]?.label)} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
Oops, something went wrong.