Browse Source
feat: add automatic and manual refresh for custom trip orders with descending date sorting
develop
feat: add automatic and manual refresh for custom trip orders with descending date sorting
develop
5 changed files with 163 additions and 19 deletions
-
4src/features/custom-trip/CustomTripOrderDetailPage.tsx
-
55src/features/custom-trip/CustomTripPage.tsx
-
51src/features/custom-trip/components/CustomTripOrdersTab.tsx
-
39src/features/custom-trip/services/__tests__/custom-trip-api.test.ts
-
33src/features/custom-trip/services/custom-trip-api.ts
@ -0,0 +1,39 @@ |
|||||
|
import { describe, expect, it } from 'vitest' |
||||
|
import { sortOrdersByCreatedDesc } from '../custom-trip-api' |
||||
|
|
||||
|
describe('sortOrdersByCreatedDesc', () => { |
||||
|
it('sorts orders by creation date and time from newest to oldest', () => { |
||||
|
const input = [ |
||||
|
{ id: 150, created: '2026-10-24T16:08:51.649117' }, |
||||
|
{ id: 153, created: '2026-10-26T15:37:35.936085' }, |
||||
|
{ id: 156, created: '2026-11-01T15:54:15.359013' }, |
||||
|
{ id: 155, created: '2026-10-26T18:45:37.290538' }, |
||||
|
{ id: 154, created: '2026-10-26T16:52:11.347603' }, |
||||
|
] |
||||
|
|
||||
|
const sorted = sortOrdersByCreatedDesc(input) |
||||
|
expect(sorted.map((o) => o.id)).toEqual([156, 155, 154, 153, 150]) |
||||
|
}) |
||||
|
|
||||
|
it('uses id descending as deterministic tie-breaker when timestamps match', () => { |
||||
|
const input = [ |
||||
|
{ id: 10, created: '2026-10-26T12:00:00' }, |
||||
|
{ id: 12, created: '2026-10-26T12:00:00' }, |
||||
|
{ id: 11, created: '2026-10-26T12:00:00' }, |
||||
|
] |
||||
|
|
||||
|
const sorted = sortOrdersByCreatedDesc(input) |
||||
|
expect(sorted.map((o) => o.id)).toEqual([12, 11, 10]) |
||||
|
}) |
||||
|
|
||||
|
it('handles missing or invalid created values without throwing', () => { |
||||
|
const input = [ |
||||
|
{ id: 1, created: '' }, |
||||
|
{ id: 2, created: 'invalid-date' }, |
||||
|
{ id: 3, created: '2026-11-01T10:00:00' }, |
||||
|
] |
||||
|
|
||||
|
const sorted = sortOrdersByCreatedDesc(input) |
||||
|
expect(sorted.map((o) => o.id)).toEqual([3, 2, 1]) |
||||
|
}) |
||||
|
}) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue