Skip to content

Commit

Permalink
Merge branch 'main' into hp/active-detours-sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahpurcell committed Jan 29, 2025
2 parents 7c43ead + d1e306b commit acfb3df
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 31 deletions.
5 changes: 4 additions & 1 deletion assets/src/components/detours/changeDurationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const ChangingDuration = ({
<span className="mb-4">
<span className="fw-bold">Previous time length</span>{" "}
<span>(estimate)</span>
<p className="mt-2" data-testid="change-detour-duration-previous-time">
<p
className="mt-2 mb-4"
data-testid="change-detour-duration-previous-time"
>
{selectedDuration}
</p>
</span>
Expand Down
8 changes: 4 additions & 4 deletions assets/src/components/detoursTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EmptyDetourTableIcon } from "../helpers/skateIcons"
import { joinClasses } from "../helpers/dom"

interface DetoursTableProps {
data: SimpleDetour[] | undefined
data: SimpleDetour[]
onOpenDetour: (detourId: number) => void
status: DetourStatus
classNames?: string[]
Expand Down Expand Up @@ -40,7 +40,7 @@ export const DetoursTable = ({
classNames = [],
}: DetoursTableProps) => (
<Table
hover={!!data}
hover={!!data.length}
className={joinClasses([...classNames, "c-detours-table"])}
variant={status === DetourStatus.Active ? "active-detour" : ""}
>
Expand All @@ -57,7 +57,7 @@ export const DetoursTable = ({
</tr>
</thead>
<tbody>
{data ? (
{data.length ? (
<PopulatedDetourRows
status={status}
data={data}
Expand Down Expand Up @@ -118,7 +118,7 @@ const PopulatedDetourRows = ({

const EmptyDetourRows = ({ message }: { message: string }) => (
<tr aria-hidden>
<td colSpan={3} className="p-3 p-md-4">
<td colSpan={4} className="p-3 p-md-4">
<div className="d-flex justify-content-center mb-3">
<EmptyDetourTableIcon height="100px" width="100px" />
</div>
Expand Down
29 changes: 10 additions & 19 deletions assets/src/models/detoursList.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
array,
coerce,
date,
Infer,
nullable,
number,
string,
type,
} from "superstruct"
import { array, coerce, date, Infer, number, string, type } from "superstruct"

export type DetourId = number
export interface SimpleDetour {
Expand Down Expand Up @@ -64,23 +55,23 @@ export const simpleDetourFromActivatedData = (
})

export interface GroupedSimpleDetours {
active?: SimpleDetour[]
draft?: SimpleDetour[]
past?: SimpleDetour[]
active: SimpleDetour[]
draft: SimpleDetour[]
past: SimpleDetour[]
}

export const GroupedDetoursData = type({
active: nullable(array(ActivatedDetourData)),
draft: nullable(array(SimpleDetourData)),
past: nullable(array(SimpleDetourData)),
active: array(ActivatedDetourData),
draft: array(SimpleDetourData),
past: array(SimpleDetourData),
})

export type GroupedDetoursData = Infer<typeof GroupedDetoursData>

export const groupedDetoursFromData = (
groupedDetours: GroupedDetoursData
): GroupedSimpleDetours => ({
active: groupedDetours.active?.map(simpleDetourFromActivatedData),
draft: groupedDetours.draft?.map((detour) => simpleDetourFromData(detour)),
past: groupedDetours.past?.map((detour) => simpleDetourFromData(detour)),
active: groupedDetours.active.map(simpleDetourFromActivatedData),
draft: groupedDetours.draft.map((detour) => simpleDetourFromData(detour)),
past: groupedDetours.past.map((detour) => simpleDetourFromData(detour)),
})
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
>
<td
class="p-3 p-md-4"
colspan="3"
colspan="4"
>
<div
class="d-flex justify-content-center mb-3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
>
<td
class="p-3 p-md-4"
colspan="3"
colspan="4"
>
<div
class="d-flex justify-content-center mb-3"
Expand Down Expand Up @@ -1102,7 +1102,7 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
>
<td
class="p-3 p-md-4"
colspan="3"
colspan="4"
>
<div
class="d-flex justify-content-center mb-3"
Expand Down
46 changes: 43 additions & 3 deletions assets/tests/components/detours/detourListPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DetourListPage } from "../../../src/components/detourListPage"
import { fetchDetours } from "../../../src/api"
import { neverPromise } from "../../testHelpers/mockHelpers"
import { Ok } from "../../../src/util/result"
import { render, screen } from "@testing-library/react"
import { render, screen, waitFor } from "@testing-library/react"
import getTestGroups from "../../../src/userTestGroups"
import { TestGroups } from "../../../src/userInTestGroup"
import { byRole } from "testing-library-selector"
Expand Down Expand Up @@ -57,7 +57,7 @@ describe("DetourListPage", () => {
estimatedDuration: "3 hours",
},
],
draft: undefined,
draft: [],
past: [
{
id: 10,
Expand Down Expand Up @@ -123,7 +123,7 @@ describe("DetourListPage", () => {
estimatedDuration: "Until end of service",
},
],
draft: undefined,
draft: [],
past: [
{
id: 10,
Expand Down Expand Up @@ -162,6 +162,46 @@ describe("DetourListPage", () => {
expect(baseElement).toMatchSnapshot()
})

test("renders empty tables when needed", async () => {
jest.mocked(fetchDetours).mockResolvedValue(
Ok({
active: [
{
id: 1,
route: "1",
viaVariant: "X",
direction: "Inbound",
name: "Headsign A",
intersection: "Street A & Avenue B",
updatedAt: 1724866392,
activatedAt: new Date(1724866392000),
estimatedDuration: "4 hours",
},
],
draft: [],
past: [
{
id: 10,
route: "1",
viaVariant: "X",
direction: "Inbound",
name: "Headsign A",
intersection: "Street E & Avenue F",
updatedAt: 1724866392,
},
],
})
)

render(<DetourListPage />)

await waitFor(() =>
expect(screen.queryByText("No draft detours.")).toBeVisible()
)
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])

Expand Down
2 changes: 1 addition & 1 deletion assets/tests/factories/detourListFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const detourListFactory = Factory.define<GroupedSimpleDetours>(() => {
})
),
],
draft: undefined,
draft: [],
past: [simpleDetourFactory.build({ name: "Headsign Z" })],
}
})
Expand Down

0 comments on commit acfb3df

Please sign in to comment.