Skip to content

Commit

Permalink
resolving UT build failures
Browse files Browse the repository at this point in the history
Signed-off-by: Shubh Sahu <shubhvs@amazon.com>
  • Loading branch information
Shubh Sahu committed Aug 16, 2024
1 parent b4cfed3 commit eb62eab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@ import { ModalProvider, ModalRoot } from "../../../../components/Modal";
import { DEFAULT_POLICY } from "../../utils/constants";
import { ROUTES } from "../../../../utils/constants";
import { CoreServicesConsumer, CoreServicesContext } from "../../../../components/core_services";
import { getApplication, getNavigationUI, getUISettings } from "../../../../services/Services";

jest.mock("../../components/DefinePolicy", () => require("../../components/DefinePolicy/__mocks__/DefinePolicyMock"));

jest.mock("../../../../services/Services", () => ({
...jest.requireActual("../../../../services/Services"),
getUISettings: jest.fn(),
getApplication: jest.fn(),
getNavigationUI: jest.fn(),
}));

beforeEach(() => {
(getUISettings as jest.Mock).mockReturnValue({
get: jest.fn().mockReturnValue(false), // or false, depending on your test case
});
(getApplication as jest.Mock).mockReturnValue({});

(getNavigationUI as jest.Mock).mockReturnValue({});
});

function renderCreatePolicyWithRouter(initialEntries = ["/"]) {
return {
...render(
Expand Down
21 changes: 19 additions & 2 deletions public/pages/Policies/containers/Policies/Policies.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,6 +18,23 @@ import { ServicesConsumer, ServicesContext } from "../../../../services";
import { BREADCRUMBS, ROUTES } from "../../../../utils/constants";
import { BrowserServices } from "../../../../models/interfaces";
import { CoreServicesContext } from "../../../../components/core_services";
import { getApplication, getNavigationUI, getUISettings } from "../../../../services/Services";

jest.mock("../../../../services/Services", () => ({
...jest.requireActual("../../../../services/Services"),
getUISettings: jest.fn(),
getApplication: jest.fn(),
getNavigationUI: jest.fn(),
}));

beforeEach(() => {
(getUISettings as jest.Mock).mockReturnValue({
get: jest.fn().mockReturnValue(false), // or false, depending on your test case
});
(getApplication as jest.Mock).mockReturnValue({});

(getNavigationUI as jest.Mock).mockReturnValue({});
});

// TODO: Move common renderWith or with___ helpers into top level tests directory
function renderPoliciesWithRouter() {
Expand All @@ -42,7 +59,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>} />
<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

0 comments on commit eb62eab

Please sign in to comment.