Skip to content

Commit

Permalink
update InformationRequirementsTablePage.spec.tsx to give a more usefu…
Browse files Browse the repository at this point in the history
…l snap
  • Loading branch information
matbusby committed Apr 24, 2024
1 parent 73cc943 commit f7c9954
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,68 @@
import React from "react";
import { shallow } from "enzyme";
import { InformationRequirementsTablePage } from "@/components/pages/Project/InformationRequirementsTablePage";
import * as MOCK from "@/tests/mocks/dataMocks";
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper";
import { PROJECTS } from "@mds/common/constants/reducerTypes";
import * as reducerTypes from "@mds/common/constants/reducerTypes";
import { AUTHENTICATION, PROJECTS } from "@mds/common/constants/reducerTypes";
import { render } from "@testing-library/react";
import { USER_ROLES } from "@mds/common";
import { Provider } from "react-redux";
import { store } from "@/App";
import * as projectActionCreator from "@mds/common/redux/actionCreators/projectActionCreator";
import { AppThunk } from "@mds/common/interfaces/appThunk.type";
import { success } from "@mds/common/redux/actions/genericActions";
import * as projectActions from "@mds/common/redux/actions/projectActions";
import { BrowserRouter } from "react-router-dom";

const initialState = {
[PROJECTS]: {
projects: [MOCK.PROJECT],
project: MOCK.PROJECT,
requirements: MOCK.INFORMATION_REQUIREMENTS_TABLE.requirements,
informationRequirementsTableDocumentTypesHash:
MOCK.INFORMATION_REQUIREMENTS_TABLE_STATUS_CODES_HASH,
},
[AUTHENTICATION]: {
userAccessData: [USER_ROLES.role_minespace_proponent],
},
};

function mockFunction() {
const original = jest.requireActual("react-router-dom");
const projectGuid = "8132462392222";
const irtGuid = "c16afb82-144c-4138-9a36-ba5c24c43d8a";
return {
...original,
useParams: jest.fn().mockReturnValue({
projectGuid,
irtGuid,
}),
useLocation: jest.fn().mockReturnValue({
state: { current: 0 },
}),
};
}

jest.mock("react-router-dom", () => mockFunction());
jest.spyOn(projectActionCreator, "fetchProjectById").mockImplementation(
(): AppThunk<Promise<any>> => (dispatch) => {
dispatch(success(reducerTypes.GET_PROJECT));
dispatch(projectActions.storeProject(MOCK.PROJECT));
return Promise.resolve(MOCK.PROJECT);
}
);
describe("InformationRequirementsTablePage", () => {
it("renders properly", () => {
const component = shallow(
<ReduxWrapper initialState={initialState}>
<InformationRequirementsTablePage />
</ReduxWrapper>
const { container } = render(
<BrowserRouter>
<ReduxWrapper initialState={initialState}>
<Provider store={store}>
<InformationRequirementsTablePage />
</Provider>
</ReduxWrapper>
</BrowserRouter>
);
expect(component).toMatchSnapshot();

expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InformationRequirementsTablePage renders properly 1`] = `
<Provider
store={
Object {
"@@observable": [Function],
"dispatch": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<InformationRequirementsTablePage />
</Provider>
`;
exports[`InformationRequirementsTablePage renders properly 1`] = `<div />`;
47 changes: 47 additions & 0 deletions services/minespace-web/src/tests/mocks/dataMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,53 @@ export const PROJECT = {
project_summary: {},
information_requirements_table: {
irt_guid: "c16afb82-144c-4138-9a36-ba5c24c43d8a",
requirements: [
{
irt_requirements_xref_guid: "e2627ea7-1bcd-4df4-bba2-e1d96f6d4889",
requirement_guid: "1ec24233-5a51-45bb-9fd8-ada055c13e87",
deleted_ind: false,
required: false,
methods: false,
comment: "Indigenous",
version: 2,
},
{
irt_requirements_xref_guid: "f3dd5aeb-b48d-4209-b7df-1fa773a3628f",
requirement_guid: "a4d1f134-bd37-40d8-abb9-faec6c3d5ae0",
deleted_ind: false,
required: false,
methods: false,
comment: "Nation",
version: 2,
},
{
irt_requirements_xref_guid: "0dc94297-ff8e-4548-b903-9f75a3ebd060",
requirement_guid: "c26cd541-642d-4cb5-985a-26c6e1bef26b",
deleted_ind: false,
required: false,
methods: false,
comment: "hello",
version: 2,
},
{
irt_requirements_xref_guid: "a3c1d302-c167-422e-9d39-ee8e19b56157",
requirement_guid: "da1b8ff9-7a8b-4311-a6ab-0169f0070e5d",
deleted_ind: false,
required: false,
methods: false,
comment: "First",
version: 2,
},
{
irt_requirements_xref_guid: "9ceb3468-134c-4fd9-9596-cb1239f47e0f",
requirement_guid: "e2c995d0-37ef-4588-ad91-76b6f2b07ab1",
deleted_ind: false,
required: false,
methods: false,
comment: "carp",
version: 2,
},
],
},
major_mine_application: {
major_mine_application_guid: "c16afb82-144c-4138-9a36-ba5c24c43d8a",
Expand Down

0 comments on commit f7c9954

Please sign in to comment.