-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdeprecated-order.test.ts
More file actions
44 lines (37 loc) · 1.19 KB
/
Copy pathdeprecated-order.test.ts
File metadata and controls
44 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { describe, expect, it } from 'vitest'
import { sortDeprecatedLast } from '@/lib/deprecated'
describe('deprecated product ordering', () => {
it('pins deprecated products after active products', () => {
const items = [
{ id: 'deprecated-a', deprecated: true },
{ id: 'active-a' },
{ id: 'deprecated-b', deprecated: true },
{ id: 'active-b', deprecated: false },
]
expect(sortDeprecatedLast(items).map(item => item.id)).toEqual([
'active-a',
'active-b',
'deprecated-a',
'deprecated-b',
])
})
it('preserves the existing order within each lifecycle group', () => {
const items = [
{ id: 'active-b' },
{ id: 'active-a' },
{ id: 'deprecated-b', deprecated: true },
{ id: 'deprecated-a', deprecated: true },
]
expect(sortDeprecatedLast(items).map(item => item.id)).toEqual([
'active-b',
'active-a',
'deprecated-b',
'deprecated-a',
])
})
it('does not mutate the input array', () => {
const items = [{ id: 'deprecated', deprecated: true }, { id: 'active' }]
sortDeprecatedLast(items)
expect(items.map(item => item.id)).toEqual(['deprecated', 'active'])
})
})