Skip to content

Commit

Permalink
Add/update tests, update help text links and icons, add Restore activ…
Browse files Browse the repository at this point in the history
…ities panel (opensearch-project#277)

* Change alignment of Snapshot Management panels in pages/Main/Main.tsx

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Unify vertical button alignment across panels, ContentPanel.tsx

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Update jest snapshots, add ROUTE_STYLE variable

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add placeholder restore button to Snapshots panel

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Comment out line 20 rollups_spec.js in cypress/integration/

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove unused code and comment cypress/integration/rollups_spec.js

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Starting adaptation/use of existing code for Restore functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Adapt Snapshots.tsx to include RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add restoreSnapshot method to SMservice,RestoreSnapshotResponse int

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement RestoreSnapshotFlyout open/close

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Make Snapshot name appear on RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add/adapt restoreSnapshot to server/SnapshotManagementService

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add route for restoreSnapshot in server/routes.ts

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Rudimentary restore from snapshot functionality reached, buggy

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix index list-snapshot restore, restrict restore to single selection

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove console.logs, commented out code

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Create Advanced options accordion for Snapshot restore.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Currently only visually functional. TODO - make it apply the options

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add initial restore/rename options to ui. Only visual functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Resolve radio button events not firing

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Split radio buttons into SnapshotRestoreOption and SnapshotRenameOptions

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Move 'restore' button between 'delete' and 'take snapshot'

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Set default rename option to 'add prefix'

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add AddPrefixInput, remove unused component RestoreSnapshotInitialOptions

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix issues with restore specific indices

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Implement first 4 Advanced restore options functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Begin cypress testing for snapshots

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Passing tests for create repo and create snapshot

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Begin cypress testing Snapshots. Create repo and Create snapshot done

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement add_prefix functionality for snapshot restore

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement rename indices option for restore snapshot

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove console.logs, unusted variables in SnapshotFlyout, SMservice

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add full stop to help text/errors, add RESTORE_OPTIONS enum

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Progress on custom index settings, ignore index settings

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement custom index settings functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Successfully implement/debug custom index settings/ignore index settings.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add back line 20 in rollups_spec, required by changes in 2.3 release.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix bug when both custom settings and ignore settings chosen

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove unused getRepos func, add repo prop, trim state in RestoreFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add increment to 2.3.0

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove index settings from options if none entered, RestoreFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add rel="noopener noreferrer" to links in IndexList, add CatSnapshotIndex interface

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Current progress, cypress testing

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add unit testing for AddPrefixInput, RenameInput components

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add unit tests for SnapshotRenameOptions component

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add unit tests for SnapshotRestoreOption component

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add unit tests for SnapshotIndicesInput component

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Change anchor tags to EuiLinks, IndexSettings

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add rel attribute to EuiLink, IndexSettingsInput

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Version bump 2.3.0 to 2.3 1

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add version bump 2.3.1 for OS in cypress-workflow.yml

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove 2.3.1 bump

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Small mods to rollups_spec and snapshots_spec

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Change snapshots_spec in effort to pass E2E. Passes locally

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix spelling of 'index' line67, snapshots_spec

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Version bump 2.4

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Make sure 2.4 applied, add TODO in rollups_spec

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Change 2.4 back to 2.x again cypress, unit_test workflows

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Remove one more 'wait' from snapshots_spec

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add "cy.wait" back line 56 snapshots_spec

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add '0' to OSD version,  opensearch_dashboards.json.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Remove redundant 'cleanup()' from AddPrefixInput.jest.js

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Signed-off-by: Chris Hesterman <phestech@amazon.com>
  • Loading branch information
phestecAMZN authored Oct 18, 2022
1 parent a0bc52a commit 0aac214
Show file tree
Hide file tree
Showing 22 changed files with 987 additions and 60 deletions.
8 changes: 7 additions & 1 deletion cypress/integration/rollups_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ describe("Rollups", () => {

cy.wait(10000)

// Click on "Sample data" tab
// TODO determine why line 25 and/or line 28 are needed occasionally for rollups_spec to pass.
// When the source of the issue is determined they will be removed/uncommented.

//Click on "Sample data" tab
cy.contains("Sample data").click({ force: true });

// Click on "Add data" tab
// cy.contains("Add data").click({ force: true });

// Load sample eCommerce data
cy.get(`button[data-test-subj="addSampleDataSetecommerce"]`).click({ force: true });

Expand Down
113 changes: 68 additions & 45 deletions cypress/integration/snapshots_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,6 @@ import { PLUGIN_NAME } from "../support/constants";

describe("Snapshots", () => {
before(() => {
// Delete any existing indices
cy.deleteAllIndices();

// Load ecommerce data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/ecommerce`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});

// Load flight data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/flights`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});

// Load web log data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/logs`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});
});

beforeEach(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");

Expand Down Expand Up @@ -79,24 +41,85 @@ describe("Snapshots", () => {

describe("Snapshot can be created", () => {
it("successfully creates a new snapshot", () => {
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/snapshots`);

// delete any existing indices
cy.deleteAllIndices();

// create test indices
cy.createIndex("test_index_1");
cy.createIndex("test_index_2");
cy.createIndex("test_index_3");

// wait needed here to enable cypress to find "Take snapshot" button. Timeout
// cannot be used with cy.createIndex
cy.wait(5000);

// Click Take snapshot button
cy.get("button").contains("Take snapshot").click({ force: true });

// Confirm test_repo exists and is in the Select repo field
cy.contains("test_repo");

// Type in Snapshot name
cy.get(`input[data-test-subj="snapshotNameInput"]`).type("test_snapshot{enter}");

// Select indexes to be included
cy.get(`[data-test-subj="indicesComboBoxInput"]`).type("open*{enter}");
// Select all indexes to be included
cy.get(`[data-test-subj="indicesComboBoxInput"]`).type("test_index_1{enter}");
cy.get(`[data-test-subj="indicesComboBoxInput"]`).type("test_index_2{enter}");
cy.get(`[data-test-subj="indicesComboBoxInput"]`).type("test_index_3{enter}");


// Confirm test_repo exists
cy.contains("test_repo");

// Click 'Add' button to create snapshot
cy.get("button").contains("Add").click({ force: true });
cy.get("button").contains("Add", { timeout: 3000 }).click({ force: true });

// check for success status and snapshot name
cy.contains("In_progress");
cy.contains("test_snapshot");
cy.get("button").contains("Refresh").click({ force: true });

cy.contains("Success");

// remove all indices
cy.deleteAllIndices();
});
});

describe("Snapshot can be restored", () => {
it("Successfully restores indices from snapshot", () => {
// Select test snapshot
cy.get(`[data-test-subj="checkboxSelectRow-test_repo:test_snapshot"]`).check({ force: true });

// click "Restore" button
cy.get(`[data-test-subj="restoreButton"]`).click({ force: true });

// Check for restore flyout
cy.contains("Restore snapshot");

// enter a prefix
cy.get(`input[data-test-subj="prefixInput"]`).type("restored_");

// Click restore snapshot button
cy.get("button").contains("Restore snapshot").click({ force: true });

// Check for success toast
cy.contains("Restored snapshot test_snapshot to repository test_repo");
});
});

describe("Snapshot can be deleted", () => {
it("deletes snapshot successfully", async () => {
// Select test snapshot
cy.get(`[data-test-subj="checkboxSelectRow-test_repo:test_snapshot"]`).check({ force: true });

// click "Delete" button
cy.get("button").contains("Delete", { timeout: 3000 }).click({ force: true });

// click "Delete snapshot" button on modal
cy.get("button").contains("Delete snapshot").click({ force: true });

cy.contains("Deleted snapshot");
cy.contains("No items found");

});
})
});
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "indexManagementDashboards",
"version": "2.4.0.0",
"opensearchDashboardsVersion": "2.4",
"opensearchDashboardsVersion": "2.4.0",
"configPath": [
"opensearch_index_management"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensearch_index_management_dashboards",
"version": "2.4.0.0",
"version": "2.4.0",
"description": "Opensearch Dashboards plugin for Index Management",
"main": "index.js",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render, screen, cleanup } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import AddPrefixInput from "./AddPrefixInput";


const testProps = { getPrefix: jest.fn() };

beforeEach(() => {
render(<AddPrefixInput {...testProps} />);
});

afterEach(() => {
cleanup();
});

describe("AddPrefixInput component", () => {
it("renders without error", () => {
expect(screen.getByText("Specify prefix for restored index names")).toBeInTheDocument();
expect(screen.getByTestId("prefixInput")).toBeInTheDocument();

const { container } = render(<AddPrefixInput {...testProps} />);

expect(container).toMatchSnapshot();
});

it("accepts user input", () => {
userEvent.type(screen.getByTestId("prefixInput"), "test_prefix_");

expect(screen.getByTestId("prefixInput")).toHaveValue("test_prefix_");
});

it("sends user input to parent component via getPrefix", () => {
userEvent.type(screen.getByTestId("prefixInput"), "four");

// getPrefix is prop sent from parent component to retrieve user input
expect(testProps.getPrefix).toBeCalledTimes(4);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const AddPrefixesInput = ({ getPrefix }: AddPrefixesInputProps) => {

<CustomLabel title="Specify prefix for restored index names" helpText="A prefix will be added to any restored index names." />
<EuiFormRow>
<EuiFieldText value={prefix} onChange={onPrefixChange} />
<EuiFieldText value={prefix} onChange={onPrefixChange} data-test-subj="prefixInput" />
</EuiFormRow>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AddPrefixInput component renders without error 1`] = `
<div>
<div
class="euiSpacer euiSpacer--l"
/>
<div
class="euiFlexGroup euiFlexGroup--gutterExtraSmall euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
class="euiText euiText--extraSmall"
>
<h4>
Specify prefix for restored index names
</h4>
</div>
</div>
</div>
<span
style="font-weight: 200; font-size: 12px;"
>
A prefix will be added to any restored index names.
</span>
<div
class="euiSpacer euiSpacer--s"
/>
<div
class="euiFormRow"
id="some_html_id-row"
>
<div
class="euiFormRow__fieldWrapper"
>
<div
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__childrenWrapper"
>
<input
class="euiFieldText"
data-test-subj="prefixInput"
id="some_html_id"
type="text"
value=""
/>
</div>
</div>
</div>
</div>
<div
class="euiSpacer euiSpacer--m"
/>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiFormRow, EuiText, EuiTextArea, EuiSpacer, EuiLink } from "@elastic/eui";
import React, { useState, ChangeEvent } from "react";
import { RESTORE_SNAPSHOT_DOCUMENTATION_URL } from "../../../../utils/constants"

interface IndexSettingsInputProps {
getIndexSettings: (indexSettings: string) => void;
ignore: boolean;
}

const IndexSettingsInput = ({ getIndexSettings, ignore }: IndexSettingsInputProps) => {
const [indexSettings, setIndexSettings] = useState("");

const onSettingsChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
setIndexSettings(e.target.value);
getIndexSettings(e.target.value);
};

const title = ignore ? "Specify index settings to ignore" : "Specify custom index settings";
const helperText = ignore
? "Specify a comma-delimited list of settings to exclude from a snapshot."
: "Specify a comma-delimited list of settings to override in all restored indices.";
const placeholderText = ignore
? `Example: \nindex.refresh_interval,\nindex.max_script_fields `
: `Example: \n {\n\"index.number_of_replicas\": 0,\n\"index.auto_expand_replicas\": true\n}`;

return (
<>
<EuiSpacer size="m" />

<EuiText size="xs">
<h4>{title}</h4>
</EuiText>
<EuiText size="xs" style={{ padding: "0px 0px 5px 0px" }}>
<p style={{ fontWeight: 200 }}>
{helperText}
<EuiLink href={RESTORE_SNAPSHOT_DOCUMENTATION_URL} target="_blank" external={true} rel="noopener noreferrer">
Learn more
</EuiLink>
</p>
</EuiText>
<EuiFormRow>
<EuiTextArea value={indexSettings} onChange={onSettingsChange} placeholder={placeholderText} />
</EuiFormRow>

<EuiSpacer size="m" />
</>
);
};

export default IndexSettingsInput;
8 changes: 8 additions & 0 deletions public/pages/Snapshots/components/IndexSettingsInput/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import IndexSettingsInput from "./IndexSettingsInput";

export default IndexSettingsInput;
Loading

0 comments on commit 0aac214

Please sign in to comment.