-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(SuccessStep): reset parking report state (#184)
- Loading branch information
1 parent
5c7218e
commit ecb5732
Showing
2 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import React from "react" | ||
import React, { useEffect } from "react" | ||
import SuccessStep from "../../components/SuccessStep" | ||
|
||
import { useActiveStepState } from "../../hooks/useStepsNavigation/useActiveStepState" | ||
import { useSetActiveStepState } from "../../hooks/useStepsNavigation/useActiveStepState" | ||
import { useSetParkingReportState } from "../../hooks/useParkingReportState" | ||
|
||
export default () => { | ||
const [activeStepIndex, setActiveStepIndex] = useActiveStepState() | ||
const setActiveStepIndex = useSetActiveStepState() | ||
const setParkingReportState = useSetParkingReportState() | ||
const onClick = () => setActiveStepIndex(0) | ||
|
||
useEffect(() => { | ||
setParkingReportState({ | ||
uuid: null, | ||
carFrontPhotoPreviewUrl: null, | ||
carPlate: "", | ||
currentPosition: null, | ||
isCarFrontPhotoValid: true, | ||
isLocationValid: true, | ||
}) | ||
}, [setParkingReportState]) | ||
|
||
return <SuccessStep onClick={onClick} /> | ||
} |
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 { RecoilRoot } from "recoil" | ||
import { render, screen } from "@testing-library/react" | ||
import SuccessStep from "." | ||
import { useSetActiveStepState } from "../../hooks/useStepsNavigation/useActiveStepState" | ||
import { useSetParkingReportState } from "../../hooks/useParkingReportState" | ||
|
||
jest.mock("../../hooks/useStepsNavigation/useActiveStepState") | ||
|
||
jest.mock("../../hooks/useParkingReportState", () => { | ||
return { | ||
useSetParkingReportState: jest.fn(), | ||
} | ||
}) | ||
|
||
describe("<SuccessStep /> container", () => { | ||
it("should set the parking report state", async () => { | ||
const defaultParkingReportState = { | ||
uuid: null, | ||
carFrontPhotoPreviewUrl: null, | ||
carPlate: "", | ||
currentPosition: null, | ||
isCarFrontPhotoValid: true, | ||
isLocationValid: true, | ||
} | ||
const setParkingReportStateMock = jest.fn() | ||
|
||
useSetActiveStepState.mockImplementation(() => jest.fn()) | ||
useSetParkingReportState.mockImplementation(() => setParkingReportStateMock) | ||
|
||
render( | ||
<RecoilRoot> | ||
<SuccessStep /> | ||
</RecoilRoot> | ||
) | ||
|
||
expect(setParkingReportStateMock).toHaveBeenCalledWith( | ||
defaultParkingReportState | ||
) | ||
}) | ||
}) |