-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schedule direction component scaffolding (#91)
scaffolding for schedule direction controls
- Loading branch information
1 parent
f4ac65b
commit 08629f0
Showing
21 changed files
with
739 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
apps/site/assets/ts/schedule/__tests__/ScheduleDirectionTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
104
apps/site/assets/ts/schedule/__tests__/ScheduleFinderAccordionTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.