Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian committed Jan 8, 2025
1 parent f69cffa commit 83e769d
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 1 deletion.
162 changes: 161 additions & 1 deletion services/ui-src/src/components/reports/DrawerReportPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import {
mockEntityStore,
mockVerbiageIntro,
mockDrawerForm,
mockNaaarReportStore,
mockNaaarReportContext,
} from "utils/testing/setupJest";
// constants
import { saveAndCloseText } from "../../constants";
import { DEFAULT_ANALYSIS_METHODS, saveAndCloseText } from "../../constants";
// types
import { McrEntityState } from "types";

const mockUseNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down Expand Up @@ -306,6 +310,162 @@ describe("Test DrawerReportPage with completed entity", () => {
});
});

describe("Test DrawerReportPage with custom entities", () => {
afterEach(() => {
jest.clearAllMocks();
});
const mockAnalysisMethodEntityStore: McrEntityState = {
entities: [],
entityType: "analysisMethods",
selectedEntity: {
id: "k9t7YoOeTOAXX3s7qF6XfN33",
name: "Geomapping",
isRequired: true,
},
// ACTIONS
setSelectedEntity: () => {},
setEntityType: () => {},
setEntities: () => {},
};
const mockAnalysisMethodsReportPageJson = {
name: "mock-route",
path: "/naaar/analysis-methods",
pageType: "drawer",
entityType: "analysisMethods",
verbiage: {
intro: mockVerbiageIntro,
dashboardTitle: "Mock dashboard title",
drawerTitle: "Mock drawer title",
addEntityButtonText: "Add other analysis method",
},
drawerForm: {
id: "am",
fields: [
{
id: "am_default_text",
type: "text",
validation: "text",
props: {
label: "Fill in info on analysis method",
},
},
],
},
addEntityDrawerForm: {
id: "am_custom",
fields: [
{
id: "am_custom_text",
type: "text",
validation: "text",
props: {
label: "Fill in info on custom analysis method",
},
},
],
},
};

const mockNaaarReportContextWithAnalysisMethods: any = mockNaaarReportContext;
mockNaaarReportContextWithAnalysisMethods.report.fieldData[
"analysisMethods"
] = [DEFAULT_ANALYSIS_METHODS[0]];

const mockCustomNaaarReportStore = {
...mockNaaarReportStore,
report: mockNaaarReportContextWithAnalysisMethods.report,
reportsByState: [mockNaaarReportContextWithAnalysisMethods.report],
};
const drawerReportPageWithCustomEntities = (
<RouterWrappedComponent>
<ReportContext.Provider value={mockNaaarReportContextWithAnalysisMethods}>
<DrawerReportPage route={mockAnalysisMethodsReportPageJson} />
</ReportContext.Provider>
</RouterWrappedComponent>
);
it("Can enter default analysis method drawer", async () => {
mockedUseStore.mockReturnValue({
...mockStateUserStore,
...mockCustomNaaarReportStore,
...mockAnalysisMethodEntityStore,
});

render(drawerReportPageWithCustomEntities);
const enterDefaultMethod = screen.getAllByText("Enter")[0];
await userEvent.click(enterDefaultMethod);
expect(screen.getByRole("dialog")).toBeVisible();
const textField = await screen.getByLabelText(
"Fill in info on analysis method"
);
expect(textField).toBeVisible();
});

it("Can enter custom analysis method drawer and fill out form", async () => {
const mockAnalysisMethodNoSelectedEntityStore =
mockAnalysisMethodEntityStore;
mockAnalysisMethodNoSelectedEntityStore.selectedEntity = undefined;
mockedUseStore.mockReturnValue({
...mockStateUserStore,
...mockCustomNaaarReportStore,
...mockAnalysisMethodNoSelectedEntityStore,
});

render(drawerReportPageWithCustomEntities);
const addCustomMethod = screen.getByText("Add other analysis method");
await userEvent.click(addCustomMethod);
expect(screen.getByRole("dialog")).toBeVisible();
const customTextField = await screen.getByLabelText(
"Fill in info on custom analysis method"
);
expect(customTextField).toBeVisible();
await userEvent.type(customTextField, "new analysis method");
const saveCustomMethod = screen.getByText("Save & close");
await userEvent.click(saveCustomMethod);
const enterDefaultMethod = screen.getAllByText("Enter")[0];
expect(enterDefaultMethod).toBeVisible();
});

it("Can shows statusing for custom analysis methods", async () => {
const mockNaaarReportContextWithCustomAnalysisMethods: any =
mockNaaarReportContext;
mockNaaarReportContextWithCustomAnalysisMethods.report.fieldData[
"analysisMethods"
] = [
DEFAULT_ANALYSIS_METHODS[0],
{
id: "custom_entity",
name: "custom entity",
},
];

const mockCustomNaaarReportStore = {
...mockNaaarReportStore,
report: mockNaaarReportContextWithCustomAnalysisMethods.report,
reportsByState: [mockNaaarReportContextWithCustomAnalysisMethods.report],
};

mockedUseStore.mockReturnValue({
...mockStateUserStore,
...mockCustomNaaarReportStore,
...mockAnalysisMethodEntityStore,
});

const drawerReportPageWithCustomEntities = (
<RouterWrappedComponent>
<ReportContext.Provider
value={mockNaaarReportContextWithCustomAnalysisMethods}
>
<DrawerReportPage route={mockAnalysisMethodsReportPageJson} />
</ReportContext.Provider>
</RouterWrappedComponent>
);

render(drawerReportPageWithCustomEntities);
const iconAltText = screen.getAllByAltText("Entity is incomplete");
expect(iconAltText.length).toBeGreaterThan(0);
});
});

describe("Test DrawerReportPage accessibility", () => {
it("Should not have basic accessibility issues", async () => {
mockedUseStore.mockReturnValue({
Expand Down
1 change: 1 addition & 0 deletions services/ui-src/src/types/formFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const entityTypes = [
"sanctions",
"program",
"ilos",
"analysisMethods",
] as const;

/**
Expand Down

0 comments on commit 83e769d

Please sign in to comment.