-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
services/core-web/src/components/mine/Permit/PermitConditionForm.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from "react"; | ||
import { fireEvent, render, waitFor } from "@testing-library/react"; | ||
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper"; | ||
import { PERMITS } from "@mds/common/constants/reducerTypes"; | ||
import * as MOCK from "@mds/common/tests/mocks/dataMocks"; | ||
import PermitConditionForm from "./PermitConditionForm"; | ||
|
||
const condition = MOCK.PERMITS[0].permit_amendments[0].conditions[0]; | ||
const initialState = { | ||
[PERMITS]: { | ||
permits: MOCK.PERMITS, | ||
permitAmendments: { | ||
[MOCK.PERMITS[0].permit_guid]: MOCK.PERMITS[0].permit_amendments[0] | ||
} | ||
}, | ||
}; | ||
|
||
function mockFunction() { | ||
const original = jest.requireActual("react-router-dom"); | ||
return { | ||
...original, | ||
useParams: jest.fn().mockReturnValue({ | ||
id: MOCK.MINES.mineIds[0], | ||
permitGuid: MOCK.PERMITS[0].permit_guid, | ||
}), | ||
}; | ||
} | ||
|
||
jest.mock("react-router-dom", () => mockFunction()); | ||
|
||
describe("PermitConditionForm", () => { | ||
it("renders properly in edit mode", async () => { | ||
const { container, findByText } = render(<ReduxWrapper initialState={initialState}> | ||
<PermitConditionForm | ||
permitAmendmentGuid={MOCK.PERMITS[0].permit_amendments[0].permit_amendment_guid} | ||
condition={condition} | ||
canEditPermitConditions={true} | ||
onEdit={jest.fn()} | ||
setEditingConditionGuid={jest.fn()} | ||
editingConditionGuid={undefined} | ||
moveUp={jest.fn()} | ||
moveDown={jest.fn()} | ||
refreshData={jest.fn()} | ||
setIsAddingListItem={jest.fn()} | ||
isAddingListItem={false} | ||
/> | ||
</ReduxWrapper>); | ||
|
||
const editElement = container.querySelector("[aria-label='Edit Condition']") | ||
fireEvent.click(editElement); | ||
await findByText("Add Report Requirement"); | ||
expect(container).toMatchSnapshot() | ||
}); | ||
it("does not allow edit when it shouldn't", async () => { | ||
const { container } = render(<ReduxWrapper initialState={initialState}> | ||
<PermitConditionForm | ||
permitAmendmentGuid={MOCK.PERMITS[0].permit_amendments[0].permit_amendment_guid} | ||
condition={condition} | ||
canEditPermitConditions={false} | ||
onEdit={jest.fn()} | ||
setEditingConditionGuid={jest.fn()} | ||
editingConditionGuid={undefined} | ||
moveUp={jest.fn()} | ||
moveDown={jest.fn()} | ||
refreshData={jest.fn()} | ||
setIsAddingListItem={jest.fn()} | ||
isAddingListItem={false} | ||
/> | ||
</ReduxWrapper>); | ||
|
||
const editElements = container.querySelectorAll("[aria-label='Edit Condition']"); | ||
expect(Array.from(editElements)).toEqual([]); | ||
|
||
// and make sure that it's not just missing the aria-label and nothing happens on click | ||
const conditionColumn = container.querySelector(".condition-column"); | ||
fireEvent.click(conditionColumn); | ||
await waitFor(() => { | ||
const editButtons = container.querySelectorAll(".condition-edit-buttons"); | ||
expect(Array.from(editButtons)).toEqual([]) | ||
}) | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
services/core-web/src/components/mine/Permit/SubConditionForm.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper"; | ||
import * as MOCK from "@mds/common/tests/mocks/dataMocks"; | ||
import SubConditionForm from "./SubConditionForm"; | ||
|
||
const condition = MOCK.PERMITS[0].permit_amendments[0].conditions[0]; | ||
const conditionCategory = { | ||
...MOCK.PERMITS[0].permit_amendments[0].condition_categories[0], | ||
conditions: [condition] | ||
} | ||
const initialState = {} | ||
|
||
describe("SubConditionForm", () => { | ||
it("renders properly for adding list item", async () => { | ||
const { container } = render(<ReduxWrapper initialState={initialState}> | ||
<SubConditionForm | ||
level={2} | ||
permitAmendmentGuid={MOCK.PERMITS[0].permit_amendments[0].permit_amendment_guid} | ||
parentCondition={condition} | ||
handleCancel={jest.fn()} | ||
onSubmit={jest.fn()} | ||
/> | ||
</ReduxWrapper>); | ||
|
||
expect(container).toMatchSnapshot() | ||
}); | ||
it("renders properly for adding to category", () => { | ||
const { container } = render(<ReduxWrapper initialState={initialState}> | ||
<SubConditionForm | ||
permitAmendmentGuid={MOCK.PERMITS[0].permit_amendments[0].permit_amendment_guid} | ||
conditionCategory={conditionCategory} | ||
handleCancel={jest.fn()} | ||
onSubmit={jest.fn()} | ||
/> | ||
</ReduxWrapper>); | ||
|
||
const textInput = container.querySelector("textarea"); | ||
expect(textInput.placeholder).toEqual("Enter Sub-Section title"); | ||
}); | ||
}); |
Oops, something went wrong.