Skip to content

Commit

Permalink
fix(app): fix failing tests
Browse files Browse the repository at this point in the history
Vitest doesn't support the copying versions of array reordering
functions from baseline 2023, so for now replace them. That's easy for
the dashboard because we can just replace .toReversed().reduce(...) with
.reduceRight(...) but for the historic run sorting we have to
elementwise copy with .map(t=>t) and then sort in-place. Yuck!
  • Loading branch information
sfoster1 committed Oct 24, 2024
1 parent 8b21fae commit fd8d836
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export function useHistoricRunDetails(
hostOverride?: HostConfig | null
): RunData[] {
const { data: allHistoricRuns } = useNotifyAllRunsQuery({}, {}, hostOverride)

return allHistoricRuns == null
? []
: allHistoricRuns.data.toSorted(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
)
: // TODO(sf): figure out why .toSorted() doesn't work in vitest
allHistoricRuns.data
.map(t => t)
.sort(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
)
}
3 changes: 1 addition & 2 deletions app/src/pages/ODD/RobotDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export function RobotDashboard(): JSX.Element {
)

const recentRunsOfUniqueProtocols = (allRunsQueryData?.data ?? [])
.toReversed() // newest runs first
.reduce<RunData[]>((acc, run) => {
.reduceRight<RunData[]>((acc, run) => {
if (
acc.some(collectedRun => collectedRun.protocolId === run.protocolId)
) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/redux/config/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ describe('config', () => {
expect(Cfg.configInitialized(state.config as any)).toEqual({
type: 'config:INITIALIZED',
payload: { config: state.config },
meta: { shell: true },
})
})

it('can create an config:VALUE_UPDATED action for a successful update', () => {
expect(Cfg.configValueUpdated('foo.bar', false)).toEqual({
type: 'config:VALUE_UPDATED',
payload: { path: 'foo.bar', value: false },
meta: { shell: true },
})
})

Expand Down

0 comments on commit fd8d836

Please sign in to comment.