Skip to content

Commit

Permalink
feat(ScheduleLink): Update wording on schedule link for commuter rail (
Browse files Browse the repository at this point in the history
…#1878)

* feat(ScheduleLink): Update wording on schedule link for commuter rail

* feat(SchedulePDFS): Change Additional Info Header, and add test
  • Loading branch information
kotva006 authored Feb 6, 2024
1 parent ed7c149 commit b2ad683
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/ts/schedule/components/AdditionalLineInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const AdditionalLineInfo = ({
}: Props): ReactElement<HTMLElement> => (
<>
<ContentTeasers teasers={teasers} />
<PDFSchedules pdfs={pdfs} />
<PDFSchedules pdfs={pdfs} route={route} />
<Connections connections={connections} />
<Fares fares={fares} fareLink={fareLink} routeType={route.type} />
{/* Only show the hours for non subway lines */}
Expand Down
13 changes: 11 additions & 2 deletions assets/ts/schedule/components/PDFSchedules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ExpandableBlock from "../../components/ExpandableBlock";
import { SchedulePDF } from "./__schedule";
import renderSvg from "../../helpers/render-svg";
import pdfIcon from "../../../static/images/icon-pdf-default.svg";
import { Route } from "../../__v3api";
import { isACommuterRailRoute } from "../../models/route";

const link = (pdf: SchedulePDF): ReactElement<HTMLElement> => (
<a
Expand All @@ -20,12 +22,19 @@ const link = (pdf: SchedulePDF): ReactElement<HTMLElement> => (

interface Props {
pdfs: SchedulePDF[];
route: Route;
}

const PDFSchedules = ({ pdfs }: Props): ReactElement<HTMLElement> | null =>
const PDFSchedules = ({
pdfs,
route
}: Props): ReactElement<HTMLElement> | null =>
pdfs.length > 0 ? (
<ExpandableBlock
header={{ text: "PDF Schedules and Maps", iconSvgText: null }}
header={{
text: `PDF Schedules${isACommuterRailRoute(route) ? "" : " and Maps"}`,
iconSvgText: null
}}
initiallyExpanded
id="pdfs"
>
Expand Down
24 changes: 22 additions & 2 deletions assets/ts/schedule/components/__tests__/PDFSchedulesTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from "react";
import renderer from "react-test-renderer";
import { createReactRoot } from "../../../app/helpers/testUtils";
import PDFSchedules from "../PDFSchedules";
import { Route } from "../../../__v3api";
import { render, screen } from "@testing-library/react";

const pdfs = [
{
Expand All @@ -10,14 +12,32 @@ const pdfs = [
}
];

const crRoute = {
type: 2
} as Route;

const railRoute = {
type: 0
} as Route;

it("it renders", () => {
createReactRoot();
const tree = renderer.create(<PDFSchedules pdfs={pdfs} />).toJSON();
const tree = renderer
.create(<PDFSchedules pdfs={pdfs} route={railRoute} />)
.toJSON();
expect(tree).toMatchSnapshot();
});

it("it renders without pdfs", () => {
createReactRoot();
const tree = renderer.create(<PDFSchedules pdfs={[]} />).toJSON();
const tree = renderer
.create(<PDFSchedules pdfs={[]} route={railRoute} />)
.toJSON();
expect(tree).toMatchSnapshot();
});

it("Does not include the `and Maps` for CR routes", () => {
render(<PDFSchedules pdfs={pdfs} route={crRoute} />);
expect(screen.queryByText("PDF Schedules and Maps")).toBeNull();
expect(screen.getByText("PDF Schedules")).toBeInTheDocument();
});
1 change: 1 addition & 0 deletions lib/dotcom_web/views/schedule_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ defmodule DotcomWeb.ScheduleView do
pdf_name =
cond do
RoutePdf.custom?(pdf) -> pdf.link_text_override
Route.commuter_rail?(route) -> [pretty_route_name(route), " schedule"]
true -> [pretty_route_name(route), " schedule and map"]
end

Expand Down
5 changes: 5 additions & 0 deletions lib/routes/route.ex
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ defmodule Routes.Route do
type_atom(route) in [:subway, :commuter_rail]
end

@spec commuter_rail?(t()) :: boolean
def commuter_rail?(route) do
type_atom(route) == :commuter_rail
end

@spec to_json_safe(t) :: map
def to_json_safe(%__MODULE__{
id: id,
Expand Down
8 changes: 8 additions & 0 deletions test/routes/route_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,12 @@ defmodule Routes.RouteTest do
refute %Routes.Route{type: 4} |> rail?()
end
end

describe "commuter_rail?/1" do
test "returns ture if a route is a commuter rail" do
assert %Routes.Route{type: 2} |> commuter_rail?()
refute %Routes.Route{type: 0} |> commuter_rail?()
refute %Routes.Route{type: 1} |> commuter_rail?()
end
end
end

0 comments on commit b2ad683

Please sign in to comment.