Skip to content

Commit

Permalink
tests: fix non-deterministic snapshot
Browse files Browse the repository at this point in the history
- adjust route pattern helper function to use a stable sort_order value.
  • Loading branch information
thecristen committed Oct 25, 2023
1 parent f606f1d commit c87f3a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ exports[`StopPageDepartures renders with data 2`] = `
</span>
</a>
<div
aria-label="Open upcoming departures to Ashmont"
aria-label="Open upcoming departures to Braintree"
class="departure-card__headsign d-flex"
role="button"
tabindex="0"
>
<div
class="departure-card__headsign-name"
>
Ashmont
Braintree
</div>
<div
class="departure-card__content"
Expand All @@ -99,15 +99,15 @@ exports[`StopPageDepartures renders with data 2`] = `
</div>
</div>
<div
aria-label="Open upcoming departures to Braintree"
aria-label="Open upcoming departures to Ashmont"
class="departure-card__headsign d-flex"
role="button"
tabindex="0"
>
<div
class="departure-card__headsign-name"
>
Braintree
Ashmont
</div>
<div
class="departure-card__content"
Expand Down
12 changes: 7 additions & 5 deletions apps/site/assets/ts/stop/__tests__/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const customStop = (args: Partial<Stop>): Stop =>

const customRoutePattern = (
route_id: string,
headsign: string
headsign: string,
index: number
): RoutePatternWithPolyline => {
const routePatternId = `${route_id}-${faker.helpers.slugify(
headsign
Expand All @@ -71,7 +72,7 @@ const customRoutePattern = (
id: routePatternId,
name: `${faker.location.city()} - ${headsign}`,
typicality: faker.number.int({ min: 1, max: 4 }),
sort_order: faker.number.int(),
sort_order: index,
direction_id: faker.number.int({ min: 0, max: 1 }),
representative_trip_polyline: {
...newPolyline(),
Expand All @@ -82,18 +83,19 @@ const customRoutePattern = (
const makeRoutePatternList = (
route: string,
headsign: string,
index: number,
count: number = 1
): RoutePatternWithPolyline[] =>
faker.helpers.multiple<RoutePatternWithPolyline>(
() => customRoutePattern(route, headsign),
() => customRoutePattern(route, headsign, index),
{ count }
);

const makeRoutePatternGroup = (route: string, headsign: string[]) => {
const routePatternsByHeadsigns = Object.fromEntries(
headsign.map(h => [
headsign.map((h, i) => [
h,
makeRoutePatternList(route, h, faker.number.int({ min: 1, max: 4 }))
makeRoutePatternList(route, h, i, faker.number.int({ min: 1, max: 4 }))
])
);
return { [route]: routePatternsByHeadsigns };
Expand Down

0 comments on commit c87f3a6

Please sign in to comment.