Skip to content

Commit 0e173f4

Browse files
authored
Added PolicyDetails page (#62)
* Added PolicyDetails page * Code cleanup, simplified page states, fixed error handling Signed-off-by: Eric Lobdell <[email protected]> * Fixed duplicate import, removed outdated test, updated policy detail test Signed-off-by: Eric Lobdell <[email protected]>
1 parent 69d8fe1 commit 0e173f4

File tree

10 files changed

+312
-41
lines changed

10 files changed

+312
-41
lines changed

cypress/integration/policies_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,26 @@ describe("Policies", () => {
188188
});
189189
});
190190
});
191+
192+
describe("can be viewed", () => {
193+
before(() => {
194+
cy.deleteAllIndices();
195+
cy.createPolicy(POLICY_ID, samplePolicy);
196+
});
197+
198+
it("successfully", () => {
199+
cy.contains(POLICY_ID);
200+
201+
cy.get(`[data-test-subj="policyLink_${POLICY_ID}"]`).click({ force: true });
202+
203+
cy.contains(POLICY_ID);
204+
cy.contains(samplePolicy.policy.description);
205+
samplePolicy.policy.states.forEach((state, i) => {
206+
cy.contains(state.name);
207+
});
208+
209+
cy.get(`[data-test-subj="viewButton"]`).click({ force: true });
210+
cy.contains(`View JSON of ${POLICY_ID}`);
211+
});
212+
})
191213
});

cypress/support/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ if (Cypress.env("security_enabled")) {
5353
Cypress.env("opensearch", `http://${Cypress.env("opensearch_url")}`);
5454
Cypress.env("opensearch_dashboards", `http://${Cypress.env("opensearch_dashboards_url")}`);
5555
}
56+
57+
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
58+
Cypress.on('uncaught:exception', (err) => {
59+
/* returning false here prevents Cypress from failing the test */
60+
if (resizeObserverLoopErrRe.test(err.message)) {
61+
return false
62+
}
63+
})

public/pages/Main/Main.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Indices from "../Indices";
3535
import CreatePolicy from "../CreatePolicy";
3636
import VisualCreatePolicy from "../VisualCreatePolicy";
3737
import ChangePolicy from "../ChangePolicy";
38+
import PolicyDetails from "../PolicyDetails/containers/PolicyDetails";
3839
import Rollups from "../Rollups";
3940
import { ModalProvider, ModalRoot } from "../../components/Modal";
4041
import { ServicesConsumer } from "../../services";
@@ -48,7 +49,6 @@ import RollupDetails from "../RollupDetails/containers/RollupDetails";
4849
import { EditTransform, Transforms } from "../Transforms";
4950
import TransformDetails from "../Transforms/containers/Transforms/TransformDetails";
5051
import queryString from "query-string";
51-
import PolicyDetails from "../PolicyDetails/containers/PolicyDetails";
5252

5353
enum Navigation {
5454
IndexManagement = "Index Management",
@@ -76,6 +76,7 @@ const HIDDEN_NAV_ROUTES = [
7676
ROUTES.TRANSFORM_DETAILS,
7777
ROUTES.CREATE_POLICY,
7878
ROUTES.EDIT_POLICY,
79+
ROUTES.POLICY_DETAILS,
7980
ROUTES.CHANGE_POLICY,
8081
];
8182

@@ -191,6 +192,14 @@ export default class Main extends Component<MainProps, object> {
191192
</div>
192193
)}
193194
/>
195+
<Route
196+
path={ROUTES.POLICY_DETAILS}
197+
render={(props: RouteComponentProps) => (
198+
<div style={{ padding: "25px 25px" }}>
199+
<PolicyDetails {...props} policyService={services.policyService} />
200+
</div>
201+
)}
202+
/>
194203
<Route
195204
path={ROUTES.MANAGED_INDICES}
196205
render={(props: RouteComponentProps) => (

public/pages/Policies/containers/Policies/Policies.test.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* SPDX-License-Identifier: Apache-2.0
33
*
44
* The OpenSearch Contributors require contributions made to
@@ -63,6 +63,7 @@ function renderPoliciesWithRouter() {
6363
/>
6464
<Route path={ROUTES.CREATE_POLICY} render={(props) => <div>Testing create policy</div>} />
6565
<Route path={ROUTES.EDIT_POLICY} render={(props) => <div>Testing edit policy: {props.location.search}</div>} />
66+
<Route path={ROUTES.POLICY_DETAILS} render={(props) =><div>Testing policy details: {props.location.search}</div>} />
6667
<Redirect from="/" to={ROUTES.INDEX_POLICIES} />
6768
</Switch>
6869
</ModalProvider>
@@ -189,41 +190,19 @@ describe("<IndexPolicies /> spec", () => {
189190
await waitFor(() => expect(queryByText(testPolicy.id)).toBeNull());
190191
});
191192

192-
it("can open and close a policy in modal", async () => {
193+
it("can open a policy", async () => {
193194
const policies = [testPolicy];
194195
browserServicesMock.policyService.getPolicies = jest.fn().mockResolvedValue({
195196
ok: true,
196197
response: { policies, totalPolicies: 1 },
197198
});
198-
const { getByText, queryByText, getByTestId } = renderPoliciesWithRouter();
199+
const { getByText } = renderPoliciesWithRouter();
199200

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

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

204-
// asserts that the policy description showed up in modal as the
205-
// whole JSON is broken up between span elements
206-
await waitFor(() => getByText(`"${testPolicy.policy.policy.description}"`));
207-
208-
userEvent.click(getByTestId("policyModalCloseButton"));
209-
210-
expect(queryByText(`"${testPolicy.policy.policy.description}"`)).toBeNull();
211-
});
212-
213-
it("can go to edit a policy from modal", async () => {
214-
const policies = [testPolicy];
215-
browserServicesMock.policyService.getPolicies = jest.fn().mockResolvedValue({
216-
ok: true,
217-
response: { policies, totalPolicies: 1 },
218-
});
219-
const { getByText, getByTestId } = renderPoliciesWithRouter();
220-
221-
await waitFor(() => getByText(testPolicy.id));
222-
userEvent.click(getByText(testPolicy.id));
223-
await waitFor(() => getByTestId("policyModalEditButton"));
224-
userEvent.click(getByTestId("policyModalEditButton"));
225-
226-
await waitFor(() => getByText(`Testing edit policy: ?id=${testPolicy.id}`));
205+
await waitFor(() => getByText(`Testing policy details: ?id=${testPolicy.id}`));
227206
});
228207

229208
it("sorts/paginates the table", async () => {

public/pages/Policies/containers/Policies/Policies.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,9 @@ export default class Policies extends Component<PoliciesProps, PoliciesState> {
104104
textOnly: true,
105105
width: "150px",
106106
render: (name: string, item: PolicyItem) => (
107-
<ModalConsumer>
108-
{({ onShow, onClose }) => (
109-
<EuiLink
110-
onClick={() =>
111-
onShow(PolicyModal, { policyId: item.id, policy: item.policy, onEdit: () => this.onClickModalEdit(item, onClose) })
112-
}
113-
>
114-
{name}
115-
</EuiLink>
116-
)}
117-
</ModalConsumer>
107+
<EuiLink onClick={() => this.props.history.push(`${ROUTES.POLICY_DETAILS}?id=${name}`)} data-test-subj={`policyLink_${name}`}>
108+
{name}
109+
</EuiLink>
118110
),
119111
},
120112
{

public/pages/PolicyDetails/components/PolicySettings/PolicySettings.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ interface PolicySettingsProps {
2323
description: string;
2424
sequenceNumber: number;
2525
schemaVersion: number;
26-
ismTemplates: ISMTemplate[];
26+
ismTemplates: ISMTemplate[] | ISMTemplate | null;
27+
onEdit: () => void;
2728
}
2829

2930
interface PolicySettingsState {
@@ -59,6 +60,7 @@ export default class PolicySettings extends Component<PolicySettingsProps, Polic
5960
sequenceNumber,
6061
schemaVersion,
6162
ismTemplates,
63+
onEdit,
6264
} = this.props;
6365

6466
const {
@@ -95,7 +97,7 @@ export default class PolicySettings extends Component<PolicySettingsProps, Polic
9597
const pagination = {
9698
pageIndex: pageIndex,
9799
pageSize,
98-
totalItemCount: ismTemplates.length,
100+
totalItemCount: ismTemplates.length || 0,
99101
pageSizeOptions: [10, 20, 50],
100102
hidePerPageOptions: !showPerPageOptions,
101103
};
@@ -110,7 +112,7 @@ export default class PolicySettings extends Component<PolicySettingsProps, Polic
110112
{
111113
text: "Edit",
112114
buttonProps: {
113-
onClick: () => {},
115+
onClick: () => onEdit(),
114116
},
115117
},
116118
]}

0 commit comments

Comments
 (0)