Skip to content

Commit

Permalink
chore(SuccessStep): reset parking report state (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliooassis committed Jul 16, 2020
1 parent 5c7218e commit ecb5732
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/containers/SuccessStep/index.js
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} />
}
41 changes: 41 additions & 0 deletions src/containers/SuccessStep/index.test.js
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
)
})
})

0 comments on commit ecb5732

Please sign in to comment.