diff --git a/assets/src/models/detoursList.ts b/assets/src/models/detoursList.ts index a381853d1..b15359de0 100644 --- a/assets/src/models/detoursList.ts +++ b/assets/src/models/detoursList.ts @@ -71,7 +71,9 @@ export type GroupedDetoursData = Infer export const groupedDetoursFromData = ( groupedDetours: GroupedDetoursData ): GroupedSimpleDetours => ({ - active: groupedDetours.active.map(simpleDetourFromActivatedData), + active: groupedDetours.active + .map(simpleDetourFromActivatedData) + .sort((a, b) => b.activatedAt.getTime() - a.activatedAt.getTime()), draft: groupedDetours.draft.map((detour) => simpleDetourFromData(detour)), past: groupedDetours.past.map((detour) => simpleDetourFromData(detour)), }) diff --git a/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap b/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap index 3f81c4f76..11dae2c62 100644 --- a/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap +++ b/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap @@ -1,5 +1,207 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`DetourListPage orders active detour list by activatedAt value 1`] = ` + +
+
+
+

+ Active detours +

+ + + All Skate users + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Route and direction + + Starting Intersection + + On detour since + + Est. Duration +
+
+
+ 3 +
+
+
+ Headsign 3 +
+
+ Inbound +
+
+
+
+ Street A3 & Avenue B3 + + 23 hours ago + + 2 hours +
+
+
+ 1 +
+
+
+ Headsign 1 +
+
+ Inbound +
+
+
+
+ Street A1 & Avenue B1 + + 54 hours ago + + 2 hours +
+
+
+ 2 +
+
+
+ Headsign 2 +
+
+ Inbound +
+
+
+
+ Street A2 & Avenue B2 + + 84 hours ago + + 2 hours +
+
+
+ +`; + exports[`DetourListPage renders detour list page for dispatchers 1`] = `
diff --git a/assets/tests/components/detours/detourListPage.test.tsx b/assets/tests/components/detours/detourListPage.test.tsx index f1d7f4865..3f322c1be 100644 --- a/assets/tests/components/detours/detourListPage.test.tsx +++ b/assets/tests/components/detours/detourListPage.test.tsx @@ -9,6 +9,8 @@ import { render, screen, waitFor } from "@testing-library/react" import getTestGroups from "../../../src/userTestGroups" import { TestGroups } from "../../../src/userInTestGroup" import { byRole } from "testing-library-selector" +import { groupedDetoursFromData } from "../../../src/models/detoursList" +import { activeDetourDataFactory } from "../../factories/detourListFactory" jest.useFakeTimers().setSystemTime(new Date("2024-08-29T20:00:00")) @@ -201,4 +203,55 @@ describe("DetourListPage", () => { expect(screen.queryByText("No active detours.")).not.toBeInTheDocument() expect(screen.queryByText("No closed detours.")).not.toBeInTheDocument() }) + + test("orders active detour list by activatedAt value", async () => { + jest.mocked(getTestGroups).mockReturnValue([TestGroups.DetoursList]) + + jest.mocked(fetchDetours).mockResolvedValue( + Ok( + groupedDetoursFromData({ + active: [ + activeDetourDataFactory.build({ + details: { + // Drafted third + id: 8, + // Updated second + updated_at: 1724876500, + }, + // Activated second + activated_at: new Date(1724766392000), + }), + activeDetourDataFactory.build({ + details: { + // Drafted second + id: 7, + // Updated third + updated_at: 1724876600, + }, + // Activated first + activated_at: new Date(1724656392000), + }), + activeDetourDataFactory.build({ + details: { + // Drafted first + id: 1, + // Updated first + updated_at: 1724876400, + }, + // Activated third + activated_at: new Date(1724876392000), + }), + ], + draft: [], + past: [], + }) + ) + ) + + const { baseElement } = render() + + await screen.findAllByText(/Headsign/) + + expect(baseElement).toMatchSnapshot() + }) })