Skip to content

Commit

Permalink
Added PolicyDetails page (opensearch-project#62)
Browse files Browse the repository at this point in the history
* Added PolicyDetails page

* Code cleanup, simplified page states, fixed error handling

Signed-off-by: Eric Lobdell <lobdelle@amazon.com>

* Fixed duplicate import, removed outdated test, updated policy detail test

Signed-off-by: Eric Lobdell <lobdelle@amazon.com>
  • Loading branch information
lobdelle committed Aug 13, 2021
1 parent 69d8fe1 commit 0e173f4
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 41 deletions.
22 changes: 22 additions & 0 deletions cypress/integration/policies_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,26 @@ describe("Policies", () => {
});
});
});

describe("can be viewed", () => {
before(() => {
cy.deleteAllIndices();
cy.createPolicy(POLICY_ID, samplePolicy);
});

it("successfully", () => {
cy.contains(POLICY_ID);

cy.get(`[data-test-subj="policyLink_${POLICY_ID}"]`).click({ force: true });

cy.contains(POLICY_ID);
cy.contains(samplePolicy.policy.description);
samplePolicy.policy.states.forEach((state, i) => {
cy.contains(state.name);
});

cy.get(`[data-test-subj="viewButton"]`).click({ force: true });
cy.contains(`View JSON of ${POLICY_ID}`);
});
})
});
8 changes: 8 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ if (Cypress.env("security_enabled")) {
Cypress.env("opensearch", `http://${Cypress.env("opensearch_url")}`);
Cypress.env("opensearch_dashboards", `http://${Cypress.env("opensearch_dashboards_url")}`);
}

const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Cypress.on('uncaught:exception', (err) => {
/* returning false here prevents Cypress from failing the test */
if (resizeObserverLoopErrRe.test(err.message)) {
return false
}
})
11 changes: 10 additions & 1 deletion public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Indices from "../Indices";
import CreatePolicy from "../CreatePolicy";
import VisualCreatePolicy from "../VisualCreatePolicy";
import ChangePolicy from "../ChangePolicy";
import PolicyDetails from "../PolicyDetails/containers/PolicyDetails";
import Rollups from "../Rollups";
import { ModalProvider, ModalRoot } from "../../components/Modal";
import { ServicesConsumer } from "../../services";
Expand All @@ -48,7 +49,6 @@ import RollupDetails from "../RollupDetails/containers/RollupDetails";
import { EditTransform, Transforms } from "../Transforms";
import TransformDetails from "../Transforms/containers/Transforms/TransformDetails";
import queryString from "query-string";
import PolicyDetails from "../PolicyDetails/containers/PolicyDetails";

enum Navigation {
IndexManagement = "Index Management",
Expand Down Expand Up @@ -76,6 +76,7 @@ const HIDDEN_NAV_ROUTES = [
ROUTES.TRANSFORM_DETAILS,
ROUTES.CREATE_POLICY,
ROUTES.EDIT_POLICY,
ROUTES.POLICY_DETAILS,
ROUTES.CHANGE_POLICY,
];

Expand Down Expand Up @@ -191,6 +192,14 @@ export default class Main extends Component<MainProps, object> {
</div>
)}
/>
<Route
path={ROUTES.POLICY_DETAILS}
render={(props: RouteComponentProps) => (
<div style={{ padding: "25px 25px" }}>
<PolicyDetails {...props} policyService={services.policyService} />
</div>
)}
/>
<Route
path={ROUTES.MANAGED_INDICES}
render={(props: RouteComponentProps) => (
Expand Down
31 changes: 5 additions & 26 deletions public/pages/Policies/containers/Policies/Policies.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
Expand Down Expand Up @@ -63,6 +63,7 @@ function renderPoliciesWithRouter() {
/>
<Route path={ROUTES.CREATE_POLICY} render={(props) => <div>Testing create policy</div>} />
<Route path={ROUTES.EDIT_POLICY} render={(props) => <div>Testing edit policy: {props.location.search}</div>} />
<Route path={ROUTES.POLICY_DETAILS} render={(props) =><div>Testing policy details: {props.location.search}</div>} />
<Redirect from="/" to={ROUTES.INDEX_POLICIES} />
</Switch>
</ModalProvider>
Expand Down Expand Up @@ -189,41 +190,19 @@ describe("<IndexPolicies /> spec", () => {
await waitFor(() => expect(queryByText(testPolicy.id)).toBeNull());
});

it("can open and close a policy in modal", async () => {
it("can open a policy", async () => {
const policies = [testPolicy];
browserServicesMock.policyService.getPolicies = jest.fn().mockResolvedValue({
ok: true,
response: { policies, totalPolicies: 1 },
});
const { getByText, queryByText, getByTestId } = renderPoliciesWithRouter();
const { getByText } = renderPoliciesWithRouter();

await waitFor(() => getByText(testPolicy.id));

userEvent.click(getByText(testPolicy.id));

// asserts that the policy description showed up in modal as the
// whole JSON is broken up between span elements
await waitFor(() => getByText(`"${testPolicy.policy.policy.description}"`));

userEvent.click(getByTestId("policyModalCloseButton"));

expect(queryByText(`"${testPolicy.policy.policy.description}"`)).toBeNull();
});

it("can go to edit a policy from modal", async () => {
const policies = [testPolicy];
browserServicesMock.policyService.getPolicies = jest.fn().mockResolvedValue({
ok: true,
response: { policies, totalPolicies: 1 },
});
const { getByText, getByTestId } = renderPoliciesWithRouter();

await waitFor(() => getByText(testPolicy.id));
userEvent.click(getByText(testPolicy.id));
await waitFor(() => getByTestId("policyModalEditButton"));
userEvent.click(getByTestId("policyModalEditButton"));

await waitFor(() => getByText(`Testing edit policy: ?id=${testPolicy.id}`));
await waitFor(() => getByText(`Testing policy details: ?id=${testPolicy.id}`));
});

it("sorts/paginates the table", async () => {
Expand Down
14 changes: 3 additions & 11 deletions public/pages/Policies/containers/Policies/Policies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,9 @@ export default class Policies extends Component<PoliciesProps, PoliciesState> {
textOnly: true,
width: "150px",
render: (name: string, item: PolicyItem) => (
<ModalConsumer>
{({ onShow, onClose }) => (
<EuiLink
onClick={() =>
onShow(PolicyModal, { policyId: item.id, policy: item.policy, onEdit: () => this.onClickModalEdit(item, onClose) })
}
>
{name}
</EuiLink>
)}
</ModalConsumer>
<EuiLink onClick={() => this.props.history.push(`${ROUTES.POLICY_DETAILS}?id=${name}`)} data-test-subj={`policyLink_${name}`}>
{name}
</EuiLink>
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ interface PolicySettingsProps {
description: string;
sequenceNumber: number;
schemaVersion: number;
ismTemplates: ISMTemplate[];
ismTemplates: ISMTemplate[] | ISMTemplate | null;
onEdit: () => void;
}

interface PolicySettingsState {
Expand Down Expand Up @@ -59,6 +60,7 @@ export default class PolicySettings extends Component<PolicySettingsProps, Polic
sequenceNumber,
schemaVersion,
ismTemplates,
onEdit,
} = this.props;

const {
Expand Down Expand Up @@ -95,7 +97,7 @@ export default class PolicySettings extends Component<PolicySettingsProps, Polic
const pagination = {
pageIndex: pageIndex,
pageSize,
totalItemCount: ismTemplates.length,
totalItemCount: ismTemplates.length || 0,
pageSizeOptions: [10, 20, 50],
hidePerPageOptions: !showPerPageOptions,
};
Expand All @@ -110,7 +112,7 @@ export default class PolicySettings extends Component<PolicySettingsProps, Polic
{
text: "Edit",
buttonProps: {
onClick: () => {},
onClick: () => onEdit(),
},
},
]}
Expand Down
Loading

0 comments on commit 0e173f4

Please sign in to comment.