Skip to content

Commit

Permalink
Merge pull request #722 from opentripplanner/percy-fix-annoyances
Browse files Browse the repository at this point in the history
Percy Fix Annoyances
  • Loading branch information
miles-grant-ibigroup authored Dec 7, 2022
2 parents 07e5171 + 8571aef commit d62e430
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 263 deletions.
27 changes: 14 additions & 13 deletions __tests__/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@

import nock from 'nock'

import '../test-utils/mock-window-url'
import * as api from '../../lib/actions/api'

// Use mocked randId function and pass in searchId for routingQuery calls so that
// snapshots are deterministic (i.e., the random IDs don't change).
let idCounter = 1234
const randId = () => `abcd${idCounter++}`

/**
* Sets the requestId values as needed to deterministic IDs.
*/
function setMockRequestIds(calls) {
calls.forEach((call) => {
call.forEach((action) => {
if (action.payload && action.payload.requestId) {
action.payload.requestId = randId()
}
})
})
}

describe('actions > api', () => {
describe('routingQuery', () => {
const defaultState = {
Expand Down Expand Up @@ -64,16 +78,3 @@ describe('actions > api', () => {
})
})
})

/**
* Sets the requestId values as needed to deterministic IDs.
*/
function setMockRequestIds (calls) {
calls.forEach(call => {
call.forEach(action => {
if (action.payload && action.payload.requestId) {
action.payload.requestId = randId()
}
})
})
}
60 changes: 30 additions & 30 deletions __tests__/components/viewers/__snapshots__/stop-viewer.js.snap

Large diffs are not rendered by default.

68 changes: 31 additions & 37 deletions __tests__/components/viewers/stop-viewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import '../../test-utils/mock-window-url'
import {
getMockInitialState,
mockWithProvider
} from '../../test-utils/mock-data/store'
import {
restoreDateNowBehavior,
setDefaultTestTime,
setTestTime
} from '../../test-utils'
import StopViewer from '../../../lib/components/viewers/stop-viewer'
import { restoreDateNowBehavior, setDefaultTestTime, setTestTime } from '../../test-utils'
import { getMockInitialState, mockWithProvider } from '../../test-utils/mock-data/store'

describe('components > viewers > stop viewer', () => {
afterEach(restoreDateNowBehavior)
Expand All @@ -13,41 +21,33 @@ describe('components > viewers > stop viewer', () => {
}

expect(
mockWithProvider(
StopViewer,
{},
mockState
).snapshot()
mockWithProvider(StopViewer, {}, mockState).snapshot()
).toMatchSnapshot()
})

it('should render with OTP transit index data', () => {
const mockState = getMockInitialState()
const stopId = 'TriMet:715'
mockState.otp.ui.viewedStop = { stopId }
mockState.otp.transitIndex.stops[stopId] = require('./mock-otp-transit-index-data.json')
mockState.otp.transitIndex.stops[
stopId
] = require('./mock-otp-transit-index-data.json')

expect(
mockWithProvider(
StopViewer,
{},
mockState
).snapshot()
mockWithProvider(StopViewer, {}, mockState).snapshot()
).toMatchSnapshot()
})

it('should render times after midnight with the correct day of week', () => {
const mockState = getMockInitialState()
const stopId = 'TriMet:9860'
mockState.otp.ui.viewedStop = { stopId }
mockState.otp.transitIndex.stops[stopId] = require('./mock-otp-transit-index-data-stop-9860.json')
mockState.otp.transitIndex.stops[
stopId
] = require('./mock-otp-transit-index-data-stop-9860.json')

expect(
mockWithProvider(
StopViewer,
{},
mockState
).snapshot()
mockWithProvider(StopViewer, {}, mockState).snapshot()
).toMatchSnapshot()
})

Expand All @@ -58,14 +58,12 @@ describe('components > viewers > stop viewer', () => {
const mockState = getMockInitialState()
const stopId = 'TriMet:9860'
mockState.otp.ui.viewedStop = { stopId }
mockState.otp.transitIndex.stops[stopId] = require('./mock-otp-transit-index-data-stop-9860.json')
mockState.otp.transitIndex.stops[
stopId
] = require('./mock-otp-transit-index-data-stop-9860.json')

expect(
mockWithProvider(
StopViewer,
{},
mockState
).snapshot()
mockWithProvider(StopViewer, {}, mockState).snapshot()
).toMatchSnapshot()
})

Expand All @@ -78,14 +76,12 @@ describe('components > viewers > stop viewer', () => {
const mockState = getMockInitialState()
const stopId = 'TriMet:9860'
mockState.otp.ui.viewedStop = { stopId }
mockState.otp.transitIndex.stops[stopId] = require('./mock-otp-transit-index-data-stop-9860-48-hr.json')
mockState.otp.transitIndex.stops[
stopId
] = require('./mock-otp-transit-index-data-stop-9860-48-hr.json')

expect(
mockWithProvider(
StopViewer,
{},
mockState
).snapshot()
mockWithProvider(StopViewer, {}, mockState).snapshot()
).toMatchSnapshot()
})

Expand All @@ -94,14 +90,12 @@ describe('components > viewers > stop viewer', () => {
mockState.otp.ui.viewedStop = {
stopId: 'TriMet:715'
}
mockState.otp.transitIndex.stops['TriMet:715'] = require('./mock-trimet-transit-index-data.json')
mockState.otp.transitIndex.stops[
'TriMet:715'
] = require('./mock-trimet-transit-index-data.json')

expect(
mockWithProvider(
StopViewer,
{},
mockState
).snapshot()
mockWithProvider(StopViewer, {}, mockState).snapshot()
).toMatchSnapshot()
})
})
5 changes: 3 additions & 2 deletions __tests__/reducers/create-otp-reducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getInitialState} from '../../lib/reducers/create-otp-reducer'
import {restoreDateNowBehavior, setDefaultTestTime} from '../test-utils'
import '../test-utils/mock-window-url'
import { getInitialState } from '../../lib/reducers/create-otp-reducer'
import { restoreDateNowBehavior, setDefaultTestTime } from '../test-utils'

describe('lib > reducers > create-otp-reducer', () => {
afterEach(restoreDateNowBehavior)
Expand Down
4 changes: 4 additions & 0 deletions __tests__/test-utils/mock-window-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Object.defineProperty(URL, 'createObjectURL', {
value: jest.fn(),
writable: true
})
49 changes: 28 additions & 21 deletions __tests__/util/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals describe, expect, it */

import {queryIsValid} from '../../lib/util/state'
import '../test-utils/mock-window-url'
import { queryIsValid } from '../../lib/util/state'

describe('util > state', () => {
describe('queryIsValid', () => {
Expand All @@ -12,32 +13,38 @@ describe('util > state', () => {
lat: 34,
lon: 12
}
const testCases = [{
expected: false,
input: {
otp: {
currentQuery: {
from: fakeFromLocation
const testCases = [
{
expected: false,
input: {
otp: {
currentQuery: {
from: fakeFromLocation
}
}
}
},
title: 'should not be valid with only from location'
},
title: 'should not be valid with only from location'
}, {
expected: true,
input: {
otp: {
currentQuery: {
from: fakeFromLocation,
to: fakeToLocation
{
expected: true,
input: {
otp: {
currentQuery: {
from: fakeFromLocation,
to: fakeToLocation
}
}
}
},
title: 'should be valid with from and to locations'
}]
},
title: 'should be valid with from and to locations'
}
]

testCases.forEach((testCase) => {
// eslint-disable-next-line jest/valid-title
it(testCase.title, () => {
expect(queryIsValid(testCase.input))[testCase.expected ? 'toBeTruthy' : 'toBeFalsy']()
expect(queryIsValid(testCase.input))[
testCase.expected ? 'toBeTruthy' : 'toBeFalsy'
]()
})
})
})
Expand Down
2 changes: 2 additions & 0 deletions a11y/a11y.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import execa from 'execa'
import puppeteer from 'puppeteer'

import '../__tests__/test-utils/mock-window-url'

import routes from '../lib/util/webapp-routes'

import { mockServer } from './mock-server'
Expand Down
2 changes: 1 addition & 1 deletion lib/components/app/call-taker-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class CallTakerPanel extends Component {
onClick={this._addPlace}
to={to}
/>
<div className="search-options">
<div className="search-options percy-hide">
<DateTimeOptions
date={date}
departArrive={departArrive}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/app/print-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class PrintLayout extends Component<Props, State> {
itinerary={itinerary}
LegIcon={LegIcon}
/>
<TripDetails itinerary={itinerary} />
<TripDetails className="percy-hide" itinerary={itinerary} />
</>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/components/viewers/stop-time-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const StopTimeCell = ({

return (
<div>
<div className="pull-left">
<div className="pull-left percy-hide">
<StyledIconWrapperTextAlign
style={{ color: '#888', fontSize: '0.8em', marginRight: 2 }}
>
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@
"@auth0/auth0-react": "^1.1.0",
"@bugsnag/js": "^7.17.0",
"@bugsnag/plugin-react": "^7.17.0",
"@opentripplanner/base-map": "^3.0.5",
"@opentripplanner/core-utils": "^7.0.9",
"@opentripplanner/base-map": "^3.0.6",
"@opentripplanner/core-utils": "^7.0.10",
"@opentripplanner/endpoints-overlay": "2.0.5",
"@opentripplanner/from-to-location-picker": "^2.1.5",
"@opentripplanner/geocoder": "^1.3.2",
"@opentripplanner/geocoder": "^1.3.3",
"@opentripplanner/humanize-distance": "^1.2.0",
"@opentripplanner/icons": "^2.0.1",
"@opentripplanner/itinerary-body": "^4.1.5",
"@opentripplanner/location-field": "1.12.9",
"@opentripplanner/location-field": "1.12.11",
"@opentripplanner/location-icon": "^1.4.0",
"@opentripplanner/park-and-ride-overlay": "^2.0.4",
"@opentripplanner/printable-itinerary": "^2.0.6",
"@opentripplanner/route-viewer-overlay": "^2.0.6",
"@opentripplanner/route-viewer-overlay": "^2.0.8",
"@opentripplanner/stop-viewer-overlay": "^2.0.4",
"@opentripplanner/stops-overlay": "^5.0.5",
"@opentripplanner/transit-vehicle-overlay": "^4.0.0",
"@opentripplanner/transitive-overlay": "^3.0.8",
"@opentripplanner/trip-details": "^2.2.6",
"@opentripplanner/transitive-overlay": "^3.0.9",
"@opentripplanner/trip-details": "^2.2.7",
"@opentripplanner/trip-form": "^3.0.1",
"@opentripplanner/trip-viewer-overlay": "^2.0.3",
"@opentripplanner/trip-viewer-overlay": "^2.0.4",
"@opentripplanner/vehicle-rental-overlay": "^2.0.4",
"@styled-icons/fa-regular": "^10.34.0",
"@styled-icons/fa-solid": "^10.34.0",
Expand Down Expand Up @@ -125,9 +125,9 @@
"@craco/craco": "^6.3.0",
"@jackwilsdon/craco-use-babelrc": "^1.0.0",
"@opentripplanner/scripts": "^1.0.2",
"@opentripplanner/types": "^4.0.3",
"@percy/cli": "^1.14.0",
"@percy/puppeteer": "^2.0.0",
"@opentripplanner/types": "^4.0.4",
"@percy/cli": "^1.16.0",
"@percy/puppeteer": "^2.0.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
"@types/mapbox__polyline": "^1.0.2",
"@types/qs": "^6.9.7",
Expand Down
Loading

0 comments on commit d62e430

Please sign in to comment.