Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

MAT-7576b: On TC create, navigate page 1 #713

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 46 additions & 13 deletions src/components/createTestCase/CreateNewTestCaseDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CreateNewTestCaseDialog from "./CreateNewTestCaseDialog";
import { Measure } from "@madie/madie-models";
import axios from "../../api/axios-instance";
import { specialChars } from "../../util/checkSpecialCharacters";
import { MemoryRouter } from "react-router-dom";

jest.mock("../../api/axios-instance");
const mockedAxios = axios as jest.Mocked<typeof axios>;
Expand Down Expand Up @@ -39,10 +40,18 @@ describe("Create New Test Case Dialog", () => {
jest.clearAllMocks();
});

const mockMeasure = { ...formikInfo, id: "test-id" };

test("should render all the fields in the test case creation form", async () => {
await act(async () => {
const { findByTestId } = await render(
<CreateNewTestCaseDialog open={true} onClose={undefined} />
<MemoryRouter
initialEntries={[
`/measures/${mockMeasure.id}/edit/test-cases/list-page`,
]}
>
<CreateNewTestCaseDialog open={true} onClose={undefined} />
</MemoryRouter>
);

expect(await findByTestId("create-test-case-title")).toBeInTheDocument();
Expand All @@ -64,7 +73,13 @@ describe("Create New Test Case Dialog", () => {
test("Save button should not be enabled when required field is empty", async () => {
await act(async () => {
const { getByTestId } = await render(
<CreateNewTestCaseDialog open={true} onClose={undefined} />
<MemoryRouter
initialEntries={[
`/measures/${mockMeasure.id}/edit/test-cases/list-page`,
]}
>
<CreateNewTestCaseDialog open={true} onClose={undefined} />
</MemoryRouter>
);

const titleInput = await getByTestId("create-test-case-title-input");
Expand Down Expand Up @@ -96,11 +111,17 @@ describe("Create New Test Case Dialog", () => {
} as unknown as Measure;
await act(async () => {
const { getByRole, getByTestId, getByText, queryByTestId } = await render(
<CreateNewTestCaseDialog
open={true}
onClose={jest.fn()}
measure={measure}
/>
<MemoryRouter
initialEntries={[
`/measures/${mockMeasure.id}/edit/test-cases/list-page`,
]}
>
<CreateNewTestCaseDialog
open={true}
onClose={jest.fn()}
measure={measure}
/>
</MemoryRouter>
);

const titleInput = await getByTestId("create-test-case-title-input");
Expand Down Expand Up @@ -143,7 +164,13 @@ describe("Create New Test Case Dialog", () => {

await act(async () => {
const { getByRole, getByTestId, getByText, queryByTestId } = await render(
<CreateNewTestCaseDialog open={true} onClose={jest.fn()} />
<MemoryRouter
initialEntries={[
`/measures/${mockMeasure.id}/edit/test-cases/list-page`,
]}
>
<CreateNewTestCaseDialog open={true} onClose={jest.fn()} />
</MemoryRouter>
);

const titleInput = await getByTestId("create-test-case-title-input");
Expand Down Expand Up @@ -196,11 +223,17 @@ describe("Create New Test Case Dialog", () => {
} as unknown as Measure;
await act(async () => {
const { getByRole, getByTestId, getByText, queryByTestId } = await render(
<CreateNewTestCaseDialog
open={true}
onClose={jest.fn()}
measure={measure}
/>
<MemoryRouter
initialEntries={[
`/measures/${mockMeasure.id}/edit/test-cases/list-page`,
]}
>
<CreateNewTestCaseDialog
open={true}
onClose={jest.fn()}
measure={measure}
/>
</MemoryRouter>
);

const titleInput = await getByTestId("create-test-case-title-input");
Expand Down
14 changes: 13 additions & 1 deletion src/components/createTestCase/CreateNewTestCaseDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useRef, useEffect } from "react";
import { useParams } from "react-router-dom";
import { useParams, useNavigate, useLocation } from "react-router-dom";
import queryString from "query-string";
import { TestCase, Measure, Model } from "@madie/madie-models";
import { TestCaseValidator } from "../../validators/TestCaseValidator";
import {
Expand Down Expand Up @@ -73,6 +74,10 @@
onClose,
measure,
}: createNewTestCaseDialogProps) => {
let navigate = useNavigate();
const { search } = useLocation();
const values = queryString.parse(search);

const [toast, setToast] = useState<Toast>({
toastOpen: false,
toastType: "danger",
Expand Down Expand Up @@ -162,6 +167,13 @@
measureId
);
handleTestCaseResponse(savedTestCase);
// go to page 1
const newPath = `/measures/${measureId}/edit/test-cases/list-page/${
measure.groups[0].id
}?filter=${values.filter ? values.filter : ""}&search=${
values.search ? values.search : ""
}&page=1&limit=${values.limit ? values.limit : 10}`;
navigate(newPath);

Check warning on line 176 in src/components/createTestCase/CreateNewTestCaseDialog.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/createTestCase/CreateNewTestCaseDialog.tsx#L176

Added line #L176 was not covered by tests
} catch (error) {
setToast({
toastOpen: true,
Expand Down
Loading