From d3de5ed3e809e12c939874bcbbb2b7a5430853ac Mon Sep 17 00:00:00 2001 From: Kayla Firestack Date: Fri, 20 Sep 2024 08:45:42 -0400 Subject: [PATCH 01/11] feat(ts/notifications): create notification card for detours --- .../src/components/notificationBellIcon.tsx | 10 ++++- assets/src/components/notificationCard.tsx | 39 +++++++++++++++++-- assets/src/models/detoursList.ts | 6 ++- assets/src/models/notificationData.ts | 30 +++++++++++++- assets/src/realtime.ts | 13 +++++++ lib/notifications/db/detour.ex | 1 + 6 files changed, 92 insertions(+), 7 deletions(-) diff --git a/assets/src/components/notificationBellIcon.tsx b/assets/src/components/notificationBellIcon.tsx index 7567bba2c..4dc2a1dc2 100644 --- a/assets/src/components/notificationBellIcon.tsx +++ b/assets/src/components/notificationBellIcon.tsx @@ -4,6 +4,8 @@ import { joinClasses } from "../helpers/dom" import { NotificationBellIcon as NotificationBellIconSvg } from "../helpers/icon" import { OpenView } from "../state/pagePanelState" import { usePanelStateFromStateDispatchContext } from "../hooks/usePanelState" +import inTestGroup, { TestGroups } from "../userInTestGroup" +import { NotificationType } from "../realtime" const NotificationBellIcon = ({ extraClasses, @@ -14,8 +16,14 @@ const NotificationBellIcon = ({ currentView: { openView }, } = usePanelStateFromStateDispatchContext() const { notifications } = useContext(NotificationsContext) + + const inDetoursList = inTestGroup(TestGroups.DetoursList) const unreadNotifications = (notifications || []).filter( - (notification) => notification.state === "unread" + (notification) => + notification.state === "unread" && + !( + notification.content.$type === NotificationType.Detour && !inDetoursList + ) ) const unreadBadge: boolean = unreadNotifications.length > 0 diff --git a/assets/src/components/notificationCard.tsx b/assets/src/components/notificationCard.tsx index df85711fd..ce4022f8a 100644 --- a/assets/src/components/notificationCard.tsx +++ b/assets/src/components/notificationCard.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement } from "react" +import React, { ReactNode } from "react" import { useRoute, useRoutes } from "../contexts/routesContext" import { BlockWaiverNotification, @@ -11,6 +11,8 @@ import { Route } from "../schedule" import { formattedTime } from "../util/dateTime" import { CardBody, CardProperties, CardReadable } from "./card" import { fullStoryEvent } from "../helpers/fullStory" +import { RoutePill } from "./routePill" +import inTestGroup, { TestGroups } from "../userInTestGroup" export const NotificationCard = ({ notification, @@ -24,7 +26,7 @@ export const NotificationCard = ({ openVPPForCurrentVehicle: (notification: Notification) => void hideLatestNotification?: () => void noFocusOrHover?: boolean -}): ReactElement => { +}) => { const routes = useRoutes( isBlockWaiverNotification(notification) ? notification.content.routeIds : [] ) @@ -33,6 +35,14 @@ export const NotificationCard = ({ ? notification.content.routeIdAtCreation : null ) + + if ( + notification.content.$type === NotificationType.Detour && + !inTestGroup(TestGroups.DetoursList) + ) { + return null + } + const isUnread = notification.state === "unread" return ( { case NotificationType.BlockWaiver: { return blockWaiverNotificationTitle(notification.content.reason) } + + case NotificationType.Detour: { + return "Detour - Active" + } + case NotificationType.BridgeMovement: { switch (notification.content.status) { case "lowered": @@ -156,7 +171,7 @@ const description = ( notification: Notification, routes: Route[], routeAtCreation: Route | null -): string => { +): ReactNode => { switch (notification.content.$type) { case NotificationType.BlockWaiver: { return blockWaiverDescription( @@ -165,6 +180,24 @@ const description = ( routeAtCreation ) } + + case NotificationType.Detour: { + return ( + <> +
+ +
+
{notification.content.headsign}
+
+ From {notification.content.origin.split(" - ")[0]} +
+
{notification.content.direction}
+
+
+ + ) + } + case NotificationType.BridgeMovement: { switch (notification.content.status) { case "raised": diff --git a/assets/src/models/detoursList.ts b/assets/src/models/detoursList.ts index 92a331eda..8df56eb96 100644 --- a/assets/src/models/detoursList.ts +++ b/assets/src/models/detoursList.ts @@ -1,7 +1,8 @@ import { array, Infer, nullable, number, string, type } from "superstruct" +export type DetourId = number export interface SimpleDetour { - id: number + id: DetourId route: string direction: string name: string @@ -9,8 +10,9 @@ export interface SimpleDetour { updatedAt: number } +export const detourId = number() export const SimpleDetourData = type({ - id: number(), + id: detourId, route: string(), direction: string(), name: string(), diff --git a/assets/src/models/notificationData.ts b/assets/src/models/notificationData.ts index 3b47f6740..602a80c83 100644 --- a/assets/src/models/notificationData.ts +++ b/assets/src/models/notificationData.ts @@ -19,6 +19,7 @@ import { NotificationContentTypes, NotificationType, } from "../realtime" +import { detourId } from "./detoursList" const dateFromSeconds = coerce( date(), @@ -65,12 +66,27 @@ export const BridgeNotificationData = union([ }), ]) +export const DetourNotificationData = type({ + __struct__: literal(NotificationType.Detour), + detour_id: detourId, + headsign: string(), + route: string(), + direction: string(), + origin: string(), +}) + +export type DetourNotificationData = Infer + export const NotificationData = type({ id: coerce(string(), number(), (i) => i.toString()), created_at: dateFromSeconds, state: enums(["unread", "read", "deleted"]), // Requires a field named `__struct__` to be present as the discriminator - content: union([BridgeNotificationData, BlockWaiverNotificationData]), + content: union([ + BridgeNotificationData, + BlockWaiverNotificationData, + DetourNotificationData, + ]), }) export type NotificationData = Infer @@ -116,6 +132,18 @@ export const notificationFromData = ( } break } + + case NotificationType.Detour: { + content = { + $type: NotificationType.Detour, + detourId: notificationData.content.detour_id, + direction: notificationData.content.direction, + headsign: notificationData.content.headsign, + origin: notificationData.content.origin, + route: notificationData.content.route, + } + break + } } return { diff --git a/assets/src/realtime.ts b/assets/src/realtime.ts index 6cfb26e4c..e8a817e44 100644 --- a/assets/src/realtime.ts +++ b/assets/src/realtime.ts @@ -10,6 +10,7 @@ import { } from "./schedule" import { Crowding } from "./models/crowding" +import { DetourId } from "./models/detoursList" export interface BlockWaiver { startTime: Date @@ -59,6 +60,7 @@ export type NotificationId = string export enum NotificationType { BridgeMovement = "Elixir.Notifications.Db.BridgeMovement", BlockWaiver = "Elixir.Notifications.Db.BlockWaiver", + Detour = "Elixir.Notifications.Db.Detour", } export interface BridgeLoweredNotification { @@ -90,9 +92,20 @@ export type BlockWaiverNotification = { endTime: Date | null } +export type DetourNotification = { + $type: NotificationType.Detour + detourId: DetourId + headsign: string + route: string + direction: string + origin: string +} + export type NotificationContentTypes = | BridgeNotification | BlockWaiverNotification + | DetourNotification + export interface Notification< TNotification extends NotificationContentTypes = NotificationContentTypes > { diff --git a/lib/notifications/db/detour.ex b/lib/notifications/db/detour.ex index 4181e6c6f..56af0be1c 100644 --- a/lib/notifications/db/detour.ex +++ b/lib/notifications/db/detour.ex @@ -9,6 +9,7 @@ defmodule Notifications.Db.Detour do @derive {Jason.Encoder, only: [ :__struct__, + :detour_id, :status, :headsign, :route, From ab626e0b9fbd9a808d2a42f31ea22b7b5f24746d Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Mon, 30 Sep 2024 18:48:49 -0400 Subject: [PATCH 02/11] tests: added detourNotification factories --- assets/tests/factories/notification.ts | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/assets/tests/factories/notification.ts b/assets/tests/factories/notification.ts index f52da227d..395e4b1c7 100644 --- a/assets/tests/factories/notification.ts +++ b/assets/tests/factories/notification.ts @@ -4,6 +4,7 @@ import { BlockWaiverReason, BridgeLoweredNotification, BridgeRaisedNotification, + DetourNotification, Notification, NotificationType, } from "../../src/realtime" @@ -84,3 +85,34 @@ export const bridgeLoweredNotificationFactory = Factory.define< state: "unread", content: bridgeLoweredNotificationContentFactory.build(), })) + +const detourActivatedNotificationContentFactory = + Factory.define(({ sequence }) => ({ + $type: NotificationType.Detour, + status: "activated", + detourId: sequence, + headsign: `Headsign ${sequence}`, + route: `${sequence}`, + direction: "Outbound", + origin: `Origin station ${sequence}`, + })) + +export const detourActivatedNotificationFactory = Factory.define< + Notification +>(({ sequence }) => ({ + id: sequence.toString(), + createdAt: new Date(), + state: "unread", + content: detourActivatedNotificationContentFactory.build(), +})) + +const detourDeactivatedNotificationContentFactory = {...detourActivatedNotificationContentFactory.build(), status: "deactivated"} + +export const detourDeactivatedNotificationFactory = Factory.define< + Notification +>(({ sequence }) => ({ + id: sequence.toString(), + createdAt: new Date(), + state: "unread", + content: detourDeactivatedNotificationContentFactory, +})) From 2c0f8e54ef205231633eb511b53eff5c0f89e831 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Mon, 30 Sep 2024 18:49:07 -0400 Subject: [PATCH 03/11] tests: notification bell icon tests --- .../notificationBellIcon.test.tsx.snap | 22 ++++++++ .../components/notificationBellIcon.test.tsx | 56 ++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap b/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap index 0f6ed8b98..999012573 100644 --- a/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap +++ b/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap @@ -43,3 +43,25 @@ exports[`NotificationBellIcon renders when the drawer is open and there are not } /> `; + +exports[`NotificationBellIcon renders when there are new detour notifications and user is not part of DetoursList 1`] = ` +", + } + } +/> +`; + +exports[`NotificationBellIcon renders when there are new detour notifications and user is part of DetoursList group 1`] = ` +", + } + } +/> +`; diff --git a/assets/tests/components/notificationBellIcon.test.tsx b/assets/tests/components/notificationBellIcon.test.tsx index f63c38bb0..66157128e 100644 --- a/assets/tests/components/notificationBellIcon.test.tsx +++ b/assets/tests/components/notificationBellIcon.test.tsx @@ -1,4 +1,4 @@ -import { jest, describe, test, expect } from "@jest/globals" +import { jest, describe, test, expect, beforeEach } from "@jest/globals" import React from "react" import renderer from "react-test-renderer" import NotificationBellIcon from "../../src/components/notificationBellIcon" @@ -12,7 +12,17 @@ import { initialState } from "../../src/state" import { OpenView } from "../../src/state/pagePanelState" import stateFactory from "../factories/applicationState" import { viewFactory } from "../factories/pagePanelStateFactory" -import { blockWaiverNotificationFactory } from "../factories/notification" +import { blockWaiverNotificationFactory, detourActivatedNotificationFactory } from "../factories/notification" +import getTestGroups from "../../src/userTestGroups" +import { TestGroups } from "../../src/userInTestGroup" + +jest.mock("../../src/userTestGroups") + +beforeEach(() => { + jest + .mocked(getTestGroups) + .mockReturnValue([]) +}) const unreadNotification: Notification = blockWaiverNotificationFactory.build({ createdAt: new Date(0), @@ -34,6 +44,11 @@ const unreadNotification: Notification = blockWaiverNotificationFactory.build({ }, }) +const unreadDetourNotification: Notification = detourActivatedNotificationFactory.build({ + createdAt: new Date(0), + state: "unread" +}) + const readNotification: Notification = { ...unreadNotification, state: "read" } const unreadNotificationState: NotificationsState = { @@ -44,6 +59,11 @@ const unreadNotificationState: NotificationsState = { setNotificationWithOpenSubmenuId: jest.fn(), } +const unreadDetourNotificationState: NotificationsState = { + ...unreadNotificationState, + notifications: [unreadDetourNotification], +} + const readNotificationState: NotificationsState = { ...unreadNotificationState, notifications: [readNotification], @@ -115,4 +135,36 @@ describe("NotificationBellIcon", () => { .toJSON() expect(tree).toMatchSnapshot() }) + + test("renders when there are new detour notifications and user is part of DetoursList group", () => { + jest + .mocked(getTestGroups) + .mockReturnValue([TestGroups.DetoursList]) + + const state = { ...initialState, openView: OpenView.None } + const tree = renderer + .create( + + + + + + ) + .toJSON() + expect(tree).toMatchSnapshot() + }) + + test("renders when there are new detour notifications and user is not part of DetoursList", () => { + const state = { ...initialState, openView: OpenView.None } + const tree = renderer + .create( + + + + + + ) + .toJSON() + expect(tree).toMatchSnapshot() + }) }) From 60c5da6d331a95e1b686bb7c97bb28fad01701ed Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Mon, 30 Sep 2024 19:04:18 -0400 Subject: [PATCH 04/11] tweak: use better test renderer + formatting --- .../notificationBellIcon.test.tsx.snap | 34 ++++++----- .../components/notificationBellIcon.test.tsx | 60 +++++++++---------- assets/tests/factories/notification.ts | 5 +- 3 files changed, 51 insertions(+), 48 deletions(-) diff --git a/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap b/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap index 999012573..658587ae6 100644 --- a/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap +++ b/assets/tests/components/__snapshots__/notificationBellIcon.test.tsx.snap @@ -45,23 +45,25 @@ exports[`NotificationBellIcon renders when the drawer is open and there are not `; exports[`NotificationBellIcon renders when there are new detour notifications and user is not part of DetoursList 1`] = ` -", - } - } -/> + +
+ + + +
+ `; exports[`NotificationBellIcon renders when there are new detour notifications and user is part of DetoursList group 1`] = ` -", - } - } -/> + +
+ + + +
+ `; diff --git a/assets/tests/components/notificationBellIcon.test.tsx b/assets/tests/components/notificationBellIcon.test.tsx index 66157128e..57f61d3d9 100644 --- a/assets/tests/components/notificationBellIcon.test.tsx +++ b/assets/tests/components/notificationBellIcon.test.tsx @@ -12,16 +12,18 @@ import { initialState } from "../../src/state" import { OpenView } from "../../src/state/pagePanelState" import stateFactory from "../factories/applicationState" import { viewFactory } from "../factories/pagePanelStateFactory" -import { blockWaiverNotificationFactory, detourActivatedNotificationFactory } from "../factories/notification" +import { + blockWaiverNotificationFactory, + detourActivatedNotificationFactory, +} from "../factories/notification" import getTestGroups from "../../src/userTestGroups" import { TestGroups } from "../../src/userInTestGroup" +import { render } from "@testing-library/react" jest.mock("../../src/userTestGroups") beforeEach(() => { - jest - .mocked(getTestGroups) - .mockReturnValue([]) + jest.mocked(getTestGroups).mockReturnValue([]) }) const unreadNotification: Notification = blockWaiverNotificationFactory.build({ @@ -44,10 +46,11 @@ const unreadNotification: Notification = blockWaiverNotificationFactory.build({ }, }) -const unreadDetourNotification: Notification = detourActivatedNotificationFactory.build({ - createdAt: new Date(0), - state: "unread" -}) +const unreadDetourNotification: Notification = + detourActivatedNotificationFactory.build({ + createdAt: new Date(0), + state: "unread", + }) const readNotification: Notification = { ...unreadNotification, state: "read" } @@ -137,34 +140,29 @@ describe("NotificationBellIcon", () => { }) test("renders when there are new detour notifications and user is part of DetoursList group", () => { - jest - .mocked(getTestGroups) - .mockReturnValue([TestGroups.DetoursList]) + jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursList]) const state = { ...initialState, openView: OpenView.None } - const tree = renderer - .create( - - - - - - ) - .toJSON() - expect(tree).toMatchSnapshot() + const { baseElement } = render( + + + + + + ) + + expect(baseElement).toMatchSnapshot() }) test("renders when there are new detour notifications and user is not part of DetoursList", () => { const state = { ...initialState, openView: OpenView.None } - const tree = renderer - .create( - - - - - - ) - .toJSON() - expect(tree).toMatchSnapshot() + const { baseElement } = render( + + + + + + ) + expect(baseElement).toMatchSnapshot() }) }) diff --git a/assets/tests/factories/notification.ts b/assets/tests/factories/notification.ts index 395e4b1c7..20ca28dde 100644 --- a/assets/tests/factories/notification.ts +++ b/assets/tests/factories/notification.ts @@ -106,7 +106,10 @@ export const detourActivatedNotificationFactory = Factory.define< content: detourActivatedNotificationContentFactory.build(), })) -const detourDeactivatedNotificationContentFactory = {...detourActivatedNotificationContentFactory.build(), status: "deactivated"} +const detourDeactivatedNotificationContentFactory = { + ...detourActivatedNotificationContentFactory.build(), + status: "deactivated", +} export const detourDeactivatedNotificationFactory = Factory.define< Notification From fde90f8411b1ae698e96b1afa3181562ef3fa4c7 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Mon, 30 Sep 2024 19:12:02 -0400 Subject: [PATCH 05/11] tests: notificationCard tests --- .../notificationCard.test.tsx.snap | 74 +++++++++++++++++++ .../components/notificationCard.test.tsx | 44 ++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 assets/tests/components/__snapshots__/notificationCard.test.tsx.snap diff --git a/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap b/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap new file mode 100644 index 000000000..0afe79279 --- /dev/null +++ b/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap @@ -0,0 +1,74 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`NotificationCard renders detour notification if user is in DetoursList group 1`] = ` + +
+
+ +
+
+ +`; diff --git a/assets/tests/components/notificationCard.test.tsx b/assets/tests/components/notificationCard.test.tsx index 5a8ab1440..9bc73f944 100644 --- a/assets/tests/components/notificationCard.test.tsx +++ b/assets/tests/components/notificationCard.test.tsx @@ -1,4 +1,4 @@ -import { jest, describe, test, expect } from "@jest/globals" +import { jest, describe, test, expect, beforeEach } from "@jest/globals" import React from "react" import { render } from "@testing-library/react" import { NotificationCard, title } from "../../src/components/notificationCard" @@ -11,14 +11,22 @@ import { blockWaiverNotificationFactory, bridgeLoweredNotificationFactory, bridgeRaisedNotificationFactory, + detourActivatedNotificationFactory, } from "../factories/notification" import routeFactory from "../factories/route" import userEvent from "@testing-library/user-event" import { hideLatestNotification } from "../../src/hooks/useNotificationsReducer" import { RoutesProvider } from "../../src/contexts/routesContext" import { fullStoryEvent } from "../../src/helpers/fullStory" +import getTestGroups from "../../src/userTestGroups" +import { TestGroups } from "../../src/userInTestGroup" jest.mock("../../src/helpers/fullStory") +jest.mock("../../src/userTestGroups") + +beforeEach(() => { + jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursList]) +}) const routes = [ routeFactory.build({ @@ -244,6 +252,36 @@ describe("NotificationCard", () => { expect(dispatch).toHaveBeenCalledWith({ type: "HIDE_LATEST_NOTIFICATION" }) }) + test("renders detour notification if user is in DetoursList group", () => { + const n: Notification = detourActivatedNotificationFactory.build() + const {baseElement} = render( + + + + ) + expect(baseElement).toMatchSnapshot() + }) + + test("does not render detour notification if user not in DetoursList group", () => { + jest.mocked(getTestGroups).mockReturnValue([]) + + const n: Notification = detourActivatedNotificationFactory.build() + const result = render( + + + + ) + expect(result.queryByText(/Detour - Active/)).toBeNull() + }) + test.each<{ notification: Notification should_fire_fs_event: boolean @@ -320,6 +358,10 @@ describe("NotificationCard", () => { }, }), }, + { + should_fire_fs_event: false, + notification: detourActivatedNotificationFactory.build({}), + }, ])( "clicking bridge notification should trigger FS event: $notification.content.reason", async ({ notification, should_fire_fs_event }) => { From 0ee485e9a530a37b555e3896ffec364f584ac35b Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Mon, 30 Sep 2024 19:12:29 -0400 Subject: [PATCH 06/11] tweak: formatting --- assets/tests/components/notificationCard.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/tests/components/notificationCard.test.tsx b/assets/tests/components/notificationCard.test.tsx index 9bc73f944..a0686b92c 100644 --- a/assets/tests/components/notificationCard.test.tsx +++ b/assets/tests/components/notificationCard.test.tsx @@ -254,7 +254,7 @@ describe("NotificationCard", () => { test("renders detour notification if user is in DetoursList group", () => { const n: Notification = detourActivatedNotificationFactory.build() - const {baseElement} = render( + const { baseElement } = render( Date: Tue, 1 Oct 2024 09:55:58 -0400 Subject: [PATCH 07/11] tweak: Update assets/tests/factories/notification.ts Co-authored-by: Kayla Firestack --- assets/tests/factories/notification.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/assets/tests/factories/notification.ts b/assets/tests/factories/notification.ts index 20ca28dde..49076d34b 100644 --- a/assets/tests/factories/notification.ts +++ b/assets/tests/factories/notification.ts @@ -106,10 +106,8 @@ export const detourActivatedNotificationFactory = Factory.define< content: detourActivatedNotificationContentFactory.build(), })) -const detourDeactivatedNotificationContentFactory = { - ...detourActivatedNotificationContentFactory.build(), - status: "deactivated", -} +const detourDeactivatedNotificationContentFactory = + detourActivatedNotificationContentFactory.params({ status: "deactivated" }) export const detourDeactivatedNotificationFactory = Factory.define< Notification From 290af029f476e2d6710de2cb842472a31e4ed435 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Tue, 1 Oct 2024 09:58:19 -0400 Subject: [PATCH 08/11] tweak: format --- assets/tests/factories/notification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/tests/factories/notification.ts b/assets/tests/factories/notification.ts index 49076d34b..ade04eaed 100644 --- a/assets/tests/factories/notification.ts +++ b/assets/tests/factories/notification.ts @@ -106,7 +106,7 @@ export const detourActivatedNotificationFactory = Factory.define< content: detourActivatedNotificationContentFactory.build(), })) -const detourDeactivatedNotificationContentFactory = +const detourDeactivatedNotificationContentFactory = detourActivatedNotificationContentFactory.params({ status: "deactivated" }) export const detourDeactivatedNotificationFactory = Factory.define< From adb472285cf3620fb731c3a950e1a71a792fcce7 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Tue, 1 Oct 2024 15:02:27 -0400 Subject: [PATCH 09/11] tweak: got rid of premature "deactivated" logic --- assets/tests/factories/notification.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/assets/tests/factories/notification.ts b/assets/tests/factories/notification.ts index ade04eaed..0ab7c10f0 100644 --- a/assets/tests/factories/notification.ts +++ b/assets/tests/factories/notification.ts @@ -105,15 +105,3 @@ export const detourActivatedNotificationFactory = Factory.define< state: "unread", content: detourActivatedNotificationContentFactory.build(), })) - -const detourDeactivatedNotificationContentFactory = - detourActivatedNotificationContentFactory.params({ status: "deactivated" }) - -export const detourDeactivatedNotificationFactory = Factory.define< - Notification ->(({ sequence }) => ({ - id: sequence.toString(), - createdAt: new Date(), - state: "unread", - content: detourDeactivatedNotificationContentFactory, -})) From ab9dcb5e824360f8af4d8fb5c549d3403028f2e1 Mon Sep 17 00:00:00 2001 From: Hannah Purcell Date: Tue, 1 Oct 2024 15:21:58 -0400 Subject: [PATCH 10/11] tweak: snapshot --- .../components/__snapshots__/notificationCard.test.tsx.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap b/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap index 0afe79279..0f3a9360c 100644 --- a/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap +++ b/assets/tests/components/__snapshots__/notificationCard.test.tsx.snap @@ -43,19 +43,19 @@ exports[`NotificationCard renders detour notification if user is in DetoursList
- 3 + 2
- Headsign 3 + Headsign 2
From - Origin station 3 + Origin station 2
Date: Tue, 1 Oct 2024 15:54:07 -0400 Subject: [PATCH 11/11] cleanup: replace `initialState` with `stateFactory.build()` --- .../components/notificationBellIcon.test.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/assets/tests/components/notificationBellIcon.test.tsx b/assets/tests/components/notificationBellIcon.test.tsx index 57f61d3d9..8413c960b 100644 --- a/assets/tests/components/notificationBellIcon.test.tsx +++ b/assets/tests/components/notificationBellIcon.test.tsx @@ -8,7 +8,6 @@ import { } from "../../src/contexts/notificationsContext" import { StateDispatchProvider } from "../../src/contexts/stateDispatchContext" import { Notification } from "../../src/realtime" -import { initialState } from "../../src/state" import { OpenView } from "../../src/state/pagePanelState" import stateFactory from "../factories/applicationState" import { viewFactory } from "../factories/pagePanelStateFactory" @@ -74,10 +73,12 @@ const readNotificationState: NotificationsState = { describe("NotificationBellIcon", () => { test("renders when the drawer is closed and there are new notifications", () => { - const state = { ...initialState, openView: OpenView.None } const tree = renderer .create( - + @@ -108,10 +109,12 @@ describe("NotificationBellIcon", () => { }) test("renders when the drawer is closed and there are not new notifications", () => { - const state = { ...initialState, openView: OpenView.None } const tree = renderer .create( - + @@ -142,9 +145,8 @@ describe("NotificationBellIcon", () => { test("renders when there are new detour notifications and user is part of DetoursList group", () => { jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursList]) - const state = { ...initialState, openView: OpenView.None } const { baseElement } = render( - + @@ -155,9 +157,8 @@ describe("NotificationBellIcon", () => { }) test("renders when there are new detour notifications and user is not part of DetoursList", () => { - const state = { ...initialState, openView: OpenView.None } const { baseElement } = render( - +