Skip to content

Commit

Permalink
adds util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brettedw committed Nov 6, 2023
1 parent f7354e1 commit 01dc387
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion web/src/features/moreCast2/slices/dataSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ const getNumberOrNaN = (value: number | null) => {
* @param forDate The date the row is for.
* @returns
*/
const createEmptyMoreCast2Row = (
export const createEmptyMoreCast2Row = (
id: string,
stationCode: number,
stationName: string,
Expand Down
42 changes: 41 additions & 1 deletion web/src/features/moreCast2/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { DateTime } from 'luxon'
import { ModelChoice } from 'api/moreCast2API'
import { createDateInterval, createWeatherModelLabel, parseForecastsHelper, rowIDHasher } from 'features/moreCast2/util'
import { createEmptyMoreCast2Row } from 'features/moreCast2/slices/dataSlice'
import {
createDateInterval,
createWeatherModelLabel,
parseForecastsHelper,
rowIDHasher,
validActualPredicate,
validForecastPredicate
} from 'features/moreCast2/util'

const TEST_DATE = '2023-02-16T20:00:00+00:00'
const TEST_DATE2 = '2023-02-17T20:00:00+00:00'
Expand Down Expand Up @@ -152,3 +160,35 @@ describe('createWeatherModelLabel', () => {
expect(result).toBe('GDPS bias')
})
})
describe('validActualPredicate', () => {
const row = createEmptyMoreCast2Row('id', 123, 'testStation', DateTime.fromISO('2023-05-25T09:08:34.123'), 56, -123)
it('should return true if a row contains valid Actual values', () => {
row.precipActual = 1
row.tempActual = 1
row.rhActual = 1
row.windSpeedActual = 1
const result = validActualPredicate(row)
expect(result).toBe(true)
})
it('should return false if a row does not contain valid Actual values', () => {
row.precipActual = NaN
const result = validActualPredicate(row)
expect(result).toBe(false)
})
})
describe('validForecastPredicate', () => {
const row = createEmptyMoreCast2Row('id', 123, 'testStation', DateTime.fromISO('2023-05-25T09:08:34.123'), 56, -123)
it('should return true if a row contains valid Forecast values', () => {
row.precipForecast = { choice: 'FORECAST', value: 2 }
row.tempForecast = { choice: 'FORECAST', value: 2 }
row.rhForecast = { choice: 'FORECAST', value: 2 }
row.windSpeedForecast = { choice: 'FORECAST', value: 2 }
const result = validForecastPredicate(row)
expect(result).toBe(true)
})
it('should return false if a row does not contain valid Forecast values', () => {
row.precipForecast = undefined
const result = validForecastPredicate(row)
expect(result).toBe(false)
})
})
7 changes: 0 additions & 7 deletions web/src/features/moreCast2/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ export const createLabel = (isActual: boolean, label: string) => {
return createWeatherModelLabel(label)
}

export const getYesterdayRowID = (todayRow: MoreCast2Row): string => {
const yesterdayDate = todayRow.forDate.minus({ days: 1 })
const yesterdayID = rowIDHasher(todayRow.stationCode, yesterdayDate)

return yesterdayID
}

export const validActualOrForecastPredicate = (row: MoreCast2Row) =>
validForecastPredicate(row) || validActualPredicate(row)

Expand Down

0 comments on commit 01dc387

Please sign in to comment.