-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Open the detour modal from a notification #2825
Closed
joshlarson
wants to merge
1
commit into
kf/asn/detour-notifications
from
jdl/feat/open-detour-modal-from-notification-card
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
98 changes: 98 additions & 0 deletions
98
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,98 @@ | ||
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 { createActor } from "xstate" | ||
import { createDetourMachine } from "../../src/models/createDetourMachine" | ||
import { originalRouteFactory } from "../factories/originalRouteFactory" | ||
import { shapePointFactory } from "../factories/shapePointFactory" | ||
import getTestGroups from "../../src/userTestGroups" | ||
import { TestGroups } from "../../src/userInTestGroup" | ||
|
||
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())) | ||
|
||
// 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 the state of the machine as the fetchDetour mocked value, | ||
// even if it doesn't match the detour clicked | ||
jest.mocked(fetchDetour).mockResolvedValue( | ||
Ok({ | ||
updatedAt: 1726147775, | ||
author: "fake@email.com", | ||
state: snapshot, | ||
}) | ||
) | ||
|
||
const n = detourActivatedNotificationFactory.build() | ||
|
||
render( | ||
<RoutesProvider routes={routes}> | ||
<NotificationCard | ||
notification={n} | ||
currentTime={new Date()} | ||
openVPPForCurrentVehicle={() => {}} | ||
/> | ||
</RoutesProvider> | ||
) | ||
|
||
// await userEvent.click(screen.getByText(/run1/)) | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is it possible to not hardcode these values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of a struggle when tests assume hardcoded values from factories and then in the future we decide to make them generated, so I'd prefer to start with generated values.
I'd be open to pulling in faker @mbta/skate-developers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - I did this just to get something working, but I'd rather get non-hardcoded values in before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done in #2819