-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Open the detour modal from a notification (#2835)
Co-authored-by: Josh Larson <[email protected]>
- Loading branch information
1 parent
f683d85
commit 227ac53
Showing
5 changed files
with
228 additions
and
44 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
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
66 changes: 66 additions & 0 deletions
66
assets/tests/components/notificationCard.openDetour.test.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,66 @@ | ||
import { jest, describe, test, expect } from "@jest/globals" | ||
import "@testing-library/jest-dom/jest-globals" | ||
import React from "react" | ||
import { render, screen } from "@testing-library/react" | ||
import { NotificationCard } from "../../src/components/notificationCard" | ||
import { detourActivatedNotificationFactory } from "../factories/notification" | ||
import routeFactory from "../factories/route" | ||
import userEvent from "@testing-library/user-event" | ||
import { RoutesProvider } from "../../src/contexts/routesContext" | ||
import { fetchDetour, fetchDetours } from "../../src/api" | ||
import { Ok } from "../../src/util/result" | ||
import { detourListFactory } from "../factories/detourListFactory" | ||
import getTestGroups from "../../src/userTestGroups" | ||
import { TestGroups } from "../../src/userInTestGroup" | ||
import { detourStateMachineFactory } from "../factories/detourStateMachineFactory" | ||
|
||
jest.mock("../../src/api") | ||
jest.mock("../../src/helpers/fullStory") | ||
jest.mock("../../src/userTestGroups") | ||
|
||
const routes = [ | ||
routeFactory.build({ | ||
id: "route1", | ||
name: "r1", | ||
}), | ||
routeFactory.build({ | ||
id: "route2", | ||
name: "r2", | ||
}), | ||
routeFactory.build({ | ||
id: "route3", | ||
name: "r3", | ||
}), | ||
] | ||
|
||
describe("NotificationCard", () => { | ||
test("renders detour details modal to match mocked fetchDetour", async () => { | ||
jest | ||
.mocked(getTestGroups) | ||
.mockReturnValue([TestGroups.DetoursPilot, TestGroups.DetoursList]) | ||
|
||
jest.mocked(fetchDetours).mockResolvedValue(Ok(detourListFactory.build())) | ||
jest | ||
.mocked(fetchDetour) | ||
.mockResolvedValue(Ok(detourStateMachineFactory.build())) | ||
|
||
const n = detourActivatedNotificationFactory.build() | ||
|
||
render( | ||
<RoutesProvider routes={routes}> | ||
<NotificationCard | ||
notification={n} | ||
currentTime={new Date()} | ||
openVPPForCurrentVehicle={() => {}} | ||
/> | ||
</RoutesProvider> | ||
) | ||
|
||
await userEvent.click(screen.getByRole("button", { name: /Detour/ })) | ||
// Render modal based on mocked value, which is a detour-in-progress | ||
|
||
expect( | ||
screen.getByRole("heading", { name: "Share Detour Details" }) | ||
).toBeVisible() | ||
}) | ||
}) |
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
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,35 @@ | ||
import { Factory } from "fishery" | ||
import { createActor } from "xstate" | ||
import { createDetourMachine } from "../../src/models/createDetourMachine" | ||
import { originalRouteFactory } from "./originalRouteFactory" | ||
import { shapePointFactory } from "./shapePointFactory" | ||
import { DetourWithState } from "../../src/models/detour" | ||
|
||
export const detourStateMachineFactory = Factory.define<DetourWithState>(() => { | ||
// Stub out a detour machine, and start a detour-in-progress | ||
const machine = createActor(createDetourMachine, { | ||
input: originalRouteFactory.build(), | ||
}).start() | ||
machine.send({ | ||
type: "detour.edit.place-waypoint-on-route", | ||
location: shapePointFactory.build(), | ||
}) | ||
machine.send({ | ||
type: "detour.edit.place-waypoint", | ||
location: shapePointFactory.build(), | ||
}) | ||
machine.send({ | ||
type: "detour.edit.place-waypoint-on-route", | ||
location: shapePointFactory.build(), | ||
}) | ||
machine.send({ type: "detour.edit.done" }) | ||
|
||
const snapshot = machine.getPersistedSnapshot() | ||
machine.stop() | ||
|
||
return { | ||
updatedAt: 1724866392, | ||
author: "[email protected]", | ||
state: snapshot, | ||
} | ||
}) |