Skip to content

Commit

Permalink
repair tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Nov 22, 2024
1 parent 724bd08 commit 4e1934e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
56 changes: 49 additions & 7 deletions __tests__/components/__snapshots__/date-time-options.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="12a"
timeFormat="h:mm a"
>
Expand Down Expand Up @@ -145,8 +151,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="12p"
timeFormat="h:mm a"
>
Expand Down Expand Up @@ -262,8 +274,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="133"
timeFormat="h:mm a"
>
Expand Down Expand Up @@ -379,8 +397,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="133p"
timeFormat="h:mm a"
>
Expand Down Expand Up @@ -496,8 +520,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="135p"
timeFormat="h:mm a"
>
Expand Down Expand Up @@ -613,8 +643,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="1335"
timeFormat="h:mm a"
>
Expand Down Expand Up @@ -730,8 +766,14 @@ exports[`components > form > call-taker > date time options should render 1`] =
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="12:34"
timeFormat="h:mm a"
>
Expand Down
1 change: 1 addition & 0 deletions __tests__/components/date-time-options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../test-utils/mock-window-matchMedia'
import '../test-utils/mock-window-url'
import {
getMockInitialState,
Expand Down
7 changes: 7 additions & 0 deletions __tests__/test-utils/mock-window-matchMedia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const mockedMediaQuery = jest.fn()
mockedMediaQuery.mockReturnValue({ matches: [] })

Object.defineProperty(window, 'matchMedia', {
value: mockedMediaQuery,
writable: true
})
15 changes: 7 additions & 8 deletions lib/components/form/call-taker/date-time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,6 +74,7 @@ type Props = {
date?: string
departArrive?: DepartArriveValue
homeTimezone: string
importedUpdateItineraryFilter: (payload: FilterType) => void
onKeyDown: () => void
setQueryParam: ({
date,
Expand All @@ -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
Expand All @@ -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<DepartArriveValue>(
initialDate || initialTime ? 'DEPART' : 'NOW'
Expand Down Expand Up @@ -202,7 +202,7 @@ const DateTimeOptions = ({
syncSortWithDepartArrive &&
DepartArriveTypeMap[departArrive] !== sort.type
) {
updateItineraryFilter({
importedUpdateItineraryFilter({
sort: {
...sort,
type: DepartArriveTypeMap[departArrive]
Expand Down Expand Up @@ -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,
Expand All @@ -317,7 +316,7 @@ const mapStateToProps = (state: AppReduxState) => {
}
}
const mapDispatchToProps = {
updateItineraryFilter: narriativeActions.updateItineraryFilter
importedUpdateItineraryFilter: updateItineraryFilter
}

export default connect(mapStateToProps, mapDispatchToProps)(DateTimeOptions)

0 comments on commit 4e1934e

Please sign in to comment.