Skip to content

Commit

Permalink
schedule direction component scaffolding (#91)
Browse files Browse the repository at this point in the history
scaffolding for schedule direction controls
  • Loading branch information
ryan-mahoney authored Jul 17, 2019
1 parent f4ac65b commit 08629f0
Show file tree
Hide file tree
Showing 21 changed files with 739 additions and 114 deletions.
19 changes: 19 additions & 0 deletions apps/site/assets/ts/__v3api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,22 @@ export interface Schedule {
stop_sequence: number;
pickup_type: number;
}

export interface Shape {
stop_ids: string[];
priority: number;
polyline: string;
name: string;
id: string;
direction_id: DirectionId;
}

export interface RoutePattern {
typicality: 1 | 2 | 3 | 4;
time_desc: string | null;
route_id: string;
representative_trip_id: string;
name: string;
id: string;
direction_id: DirectionId;
}
125 changes: 125 additions & 0 deletions apps/site/assets/ts/schedule/__tests__/ScheduleDirectionTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React from "react";
import renderer from "react-test-renderer";
import { mount } from "enzyme";
import { createReactRoot } from "../../app/helpers/testUtils";
import ScheduleDirection from "../components/ScheduleDirection";
import { EnhancedRoute } from "../../__v3api";
import { RoutePatternsByDirection, ShapesById } from "../components/__schedule";

const body = '<div id="body-wrapper"><div id="react-root"></div></div>';

const route = {
type: 3,
name: "route 1",
long_name: "route 1 long name",
id: "route-1",
direction_names: {
0: "Outbound",
1: "Inbound"
},
direction_destinations: {
0: "Begin",
1: "End"
},
description: "key_bus_route",
"custom_route?": false,
header: "",
alert_count: 0
} as EnhancedRoute;
const directionId = 1;
const routePatternsByDirection = {
"0": [
{
typicality: 1,
time_desc: null,
shape_id: "shape-1",
route_id: "route-1",
representative_trip_id: "trip-1",
name: "Pattern 1",
id: "pattern-1",
direction_id: 0
},
{
typicality: 1,
time_desc: null,
shape_id: "shape-3",
route_id: "route-1",
representative_trip_id: "trip-3",
name: "Pattern 3",
id: "pattern-3",
direction_id: 0
}
],
"1": [
{
typicality: 1,
time_desc: null,
shape_id: "shape-2",
route_id: "route-1",
representative_trip_id: "trip-1",
name: "Pattern 2",
id: "pattern-2",
direction_id: 1
}
]
} as RoutePatternsByDirection;
const shapesById = {
"shape-1": {
stop_ids: ["stop"],
priority: 3,
polyline: "xyz",
name: "Shape 1",
id: "shape-1",
direction_id: 0
},
"shape-2": {
stop_ids: ["stop"],
priority: 3,
polyline: "xyz",
name: "Shape 2",
id: "shape-2",
direction_id: 1
},
"shape-3": {
stop_ids: ["stop"],
priority: 3,
polyline: "xyz",
name: "Shape 3",
id: "shape-3",
direction_id: 0
}
} as ShapesById;

const getComponent = () => (
<ScheduleDirection
route={route}
directionId={directionId}
routePatternsByDirection={routePatternsByDirection}
shapesById={shapesById}
/>
);

it("it renders", () => {
createReactRoot();
const tree = renderer.create(getComponent()).toJSON();
expect(tree).toMatchSnapshot();
});

it("can change direction", () => {
document.body.innerHTML = body;
const component = getComponent();
const wrapper = mount(component);
expect(wrapper.find("#direction-name").text()).toBe("Inbound");
wrapper.find("button").simulate("click");
expect(wrapper.find("#direction-name").text()).toBe("Outbound");
});

it("can change route pattern", () => {
document.body.innerHTML = body;
const component = getComponent();
const wrapper = mount(component);
wrapper.find("button").simulate("click");
expect(wrapper.find("#active-shape").text()).toBe("Shape 1");
wrapper.find("select").simulate("change", { target: { value: "pattern-3" } });
expect(wrapper.find("#active-shape").text()).toBe("Shape 3");
});
104 changes: 104 additions & 0 deletions apps/site/assets/ts/schedule/__tests__/ScheduleFinderAccordionTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from "react";
import renderer from "react-test-renderer";
import { createReactRoot } from "../../app/helpers/testUtils";
import ScheduleFinderAccordion from "../components/ScheduleFinderAccordion";
import { EnhancedRoute, ServiceWithServiceDate } from "../../__v3api";
import { ServiceSchedule } from "../components/__schedule";

const services: ServiceWithServiceDate[] = [
{
valid_days: [1, 2, 3, 4, 5],
typicality: "typical_service",
type: "weekday",
start_date: "2019-07-02",
service_date: "2019-07-09",
removed_dates_notes: { "2019-07-04": "Independence Day" },
removed_dates: ["2019-07-04"],
name: "Weekday",
id: "BUS319-O-Wdy-02",
end_date: "2019-08-30",
description: "Weekday schedule",
added_dates_notes: {},
added_dates: []
},
{
valid_days: [6],
typicality: "typical_service",
type: "saturday",
start_date: "2019-07-06",
service_date: "2019-07-09",
removed_dates_notes: {},
removed_dates: [],
name: "Saturday",
id: "BUS319-P-Sa-02",
end_date: "2019-08-31",
description: "Saturday schedule",
added_dates_notes: {},
added_dates: []
},
{
valid_days: [7],
typicality: "typical_service",
type: "sunday",
start_date: "2019-07-07",
service_date: "2019-07-09",
removed_dates_notes: {},
removed_dates: [],
name: "Sunday",
id: "BUS319-Q-Su-02",
end_date: "2019-08-25",
description: "Sunday schedule",
added_dates_notes: {},
added_dates: []
}
] as ServiceWithServiceDate[];

/* eslint-disable @typescript-eslint/camelcase */
const body = '<div id="react-root"></div>';
const route: EnhancedRoute = {
alert_count: 0,
description: "",
direction_destinations: { 0: "Oak Grove", 1: "Forest Hills" },
direction_names: { 0: "Inbound", 1: "Outbound" },
header: "",
id: "Orange",
long_name: "Orange Line",
name: "Orange",
type: 1
};
const stops = [
{
name: "SL",
id: "741",
is_closed: false,
zone: "1"
},
{
name: "Abc",
id: "123",
is_closed: false,
zone: null
},
{
name: "Wellington",
id: "place-welln",
is_closed: true,
zone: null
}
];

it("renders", () => {
createReactRoot();
const tree = renderer
.create(
<ScheduleFinderAccordion
route={route}
stops={stops}
directionId={0}
services={services}
serviceSchedules={{}}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions apps/site/assets/ts/schedule/__tests__/ScheduleFinderTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import renderer from "react-test-renderer";
import { mount } from "enzyme";
import { createReactRoot } from "../../app/helpers/testUtils";
import ScheduleFinder from "../components/ScheduleFinder";
import { EnhancedRoute, Service, ServiceWithServiceDate } from "../../__v3api";
import { EnhancedRoute, ServiceWithServiceDate } from "../../__v3api";
import serviceData from "./serviceData.json";
import { ServiceSchedule } from "../components/__schedule";

Expand Down Expand Up @@ -54,7 +54,7 @@ const services: ServiceWithServiceDate[] = [
added_dates: []
}
] as ServiceWithServiceDate[];
const serviceSchedules: ServiceSchedule = serviceData as ServiceSchedule;
const serviceSchedules: ServiceSchedule = (serviceData as unknown) as ServiceSchedule;
// the enzyme test was done as one test because there was
// an issue mounting it more than once due to the focus-trap
// dependency that the Modal component depends on
Expand Down
8 changes: 6 additions & 2 deletions apps/site/assets/ts/schedule/__tests__/SchedulePageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ it("it renders", () => {
services,
stops,
direction_id: 0,
service_schedules: {}
service_schedules: {},
shape_map: {},
route_patterns: {}
}}
/>
)
Expand Down Expand Up @@ -143,7 +145,9 @@ it("it renders with conditional components", () => {
services,
stops,
direction_id: 0,
service_schedules: {}
service_schedules: {},
shape_map: {},
route_patterns: {}
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const services: ServiceWithServiceDate[] = [
added_dates: []
}
] as ServiceWithServiceDate[];
const serviceSchedules: ServiceSchedule = serviceData as ServiceSchedule;
const serviceSchedules: ServiceSchedule = (serviceData as unknown) as ServiceSchedule;

const crServices: ServiceWithServiceDate[] = [
{
Expand Down
63 changes: 0 additions & 63 deletions apps/site/assets/ts/schedule/__tests__/ServiceSelectorTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,69 +68,6 @@ const services: ServiceWithServiceDate[] = [
] as ServiceWithServiceDate[];
const serviceSchedules: ServiceSchedule = serviceData as ServiceSchedule;

const multipleWeekdays = [
{
valid_days: [1, 2, 3, 4],
typicality: "typical_service",
type: "weekday",
start_date: "2019-07-02",
service_date: "2019-07-09",
removed_dates_notes: { "2019-07-04": "Independence Day" },
removed_dates: ["2019-07-04"],
name: "Weekday",
id: "BUS319-F-Wdy-02",
end_date: "2019-08-29",
description: "Weekday schedule",
added_dates_notes: {},
added_dates: []
},
{
valid_days: [5],
typicality: "typical_service",
type: "weekday",
start_date: "2019-07-05",
service_date: "2019-07-09",
removed_dates_notes: {},
removed_dates: [],
name: "Weekday",
id: "BUS319-D-Wdy-02",
end_date: "2019-08-30",
description: "Weekday schedule",
added_dates_notes: {},
added_dates: []
},
{
valid_days: [6],
typicality: "typical_service",
type: "saturday",
start_date: "2019-07-06",
service_date: "2019-07-09",
removed_dates_notes: {},
removed_dates: [],
name: "Saturday",
id: "BUS319-B-Sa-02",
end_date: "2019-08-31",
description: "Saturday schedule",
added_dates_notes: {},
added_dates: []
},
{
valid_days: [7],
typicality: "typical_service",
type: "sunday",
start_date: "2019-07-07",
service_date: "2019-07-09",
removed_dates_notes: {},
removed_dates: [],
name: "Sunday",
id: "BUS319-C-Su-02",
end_date: "2019-08-25",
description: "Sunday schedule",
added_dates_notes: {},
added_dates: []
}
];

describe("ServiceSelector", () => {
it("it renders", () => {
createReactRoot();
Expand Down
Loading

0 comments on commit 08629f0

Please sign in to comment.