diff --git a/__tests__/components/__snapshots__/date-time-options.js.snap b/__tests__/components/__snapshots__/date-time-options.js.snap index 9e8214cdc..37415059c 100644 --- a/__tests__/components/__snapshots__/date-time-options.js.snap +++ b/__tests__/components/__snapshots__/date-time-options.js.snap @@ -28,8 +28,14 @@ exports[`components > form > call-taker > date time options should correctly han > @@ -145,8 +151,14 @@ exports[`components > form > call-taker > date time options should correctly han > @@ -262,8 +274,14 @@ exports[`components > form > call-taker > date time options should correctly han > @@ -379,8 +397,14 @@ exports[`components > form > call-taker > date time options should correctly han > @@ -496,8 +520,14 @@ exports[`components > form > call-taker > date time options should correctly han > @@ -613,8 +643,14 @@ exports[`components > form > call-taker > date time options should correctly han > @@ -730,8 +766,14 @@ exports[`components > form > call-taker > date time options should render 1`] = > diff --git a/__tests__/components/date-time-options.js b/__tests__/components/date-time-options.js index d2737d38f..931e05de5 100644 --- a/__tests__/components/date-time-options.js +++ b/__tests__/components/date-time-options.js @@ -1,3 +1,4 @@ +import '../test-utils/mock-window-matchMedia' import '../test-utils/mock-window-url' import { getMockInitialState, diff --git a/__tests__/test-utils/mock-window-matchMedia.js b/__tests__/test-utils/mock-window-matchMedia.js new file mode 100644 index 000000000..5fefd4aed --- /dev/null +++ b/__tests__/test-utils/mock-window-matchMedia.js @@ -0,0 +1,7 @@ +const mockedMediaQuery = jest.fn() +mockedMediaQuery.mockReturnValue({ matches: [] }) + +Object.defineProperty(window, 'matchMedia', { + value: mockedMediaQuery, + writable: true +}) diff --git a/lib/components/form/call-taker/date-time-picker.tsx b/lib/components/form/call-taker/date-time-picker.tsx index 3fddd8444..96292df86 100644 --- a/lib/components/form/call-taker/date-time-picker.tsx +++ b/lib/components/form/call-taker/date-time-picker.tsx @@ -7,9 +7,9 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap' import coreUtils from '@opentripplanner/core-utils' import React, { useEffect, useRef, useState } from 'react' -import * as narriativeActions from '../../../actions/narrative' import { AppReduxState, FilterType, SortType } from '../../../util/state-types' import { DepartArriveTypeMap, DepartArriveValue } from '../date-time-modal' +import { updateItineraryFilter } from '../../../actions/narrative' const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } = coreUtils.time @@ -74,6 +74,7 @@ type Props = { date?: string departArrive?: DepartArriveValue homeTimezone: string + importedUpdateItineraryFilter: (payload: FilterType) => void onKeyDown: () => void setQueryParam: ({ date, @@ -88,7 +89,6 @@ type Props = { syncSortWithDepartArrive?: boolean time?: string timeFormat: string - updateItineraryFilter: (payload: FilterType) => void } /** * Contains depart/arrive selector and time/date inputs for the admin-oriented @@ -108,13 +108,13 @@ const DateTimeOptions = ({ date: initialDate, departArrive: initialDepartArrive, homeTimezone, + importedUpdateItineraryFilter, onKeyDown, setQueryParam, sort, syncSortWithDepartArrive, time: initialTime, - timeFormat, - updateItineraryFilter + timeFormat }: Props) => { const [departArrive, setDepartArrive] = useState( initialDate || initialTime ? 'DEPART' : 'NOW' @@ -202,7 +202,7 @@ const DateTimeOptions = ({ syncSortWithDepartArrive && DepartArriveTypeMap[departArrive] !== sort.type ) { - updateItineraryFilter({ + importedUpdateItineraryFilter({ sort: { ...sort, type: DepartArriveTypeMap[departArrive] @@ -306,8 +306,7 @@ const DateTimeOptions = ({ // connect to the redux store const mapStateToProps = (state: AppReduxState) => { const { dateTime, homeTimezone, itinerary } = state.otp.config - // @ts-expect-error TS doesn't understand it's fine if this value is undefined - const { syncSortWithDepartArrive } = itinerary + const syncSortWithDepartArrive = itinerary?.syncSortWithDepartArrive const { sort } = state.otp.filter return { homeTimezone, @@ -317,7 +316,7 @@ const mapStateToProps = (state: AppReduxState) => { } } const mapDispatchToProps = { - updateItineraryFilter: narriativeActions.updateItineraryFilter + importedUpdateItineraryFilter: updateItineraryFilter } export default connect(mapStateToProps, mapDispatchToProps)(DateTimeOptions)