-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
sort-pages.test.ts
71 lines (65 loc) · 1.74 KB
/
sort-pages.test.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { describe, expect, it } from 'vitest'
import { sortPages } from '../src/utils'
const kind = 'MdxPage'
describe('sortPages()', () => {
it('should sort by date', () => {
const data = sortPages([
{ kind, name: 'baz', frontMatter: { date: new Date('1995-10-21') } },
{ kind, name: 'foo', frontMatter: { date: new Date('1992-10-21') } },
{ kind, name: 'quz', frontMatter: { date: new Date('1998-10-21') } }
])
expect(data).toEqual([
['quz', 'Quz'],
['baz', 'Baz'],
['foo', 'Foo']
])
})
it('should sort by date first and after by title', () => {
const data = sortPages([
{ kind, name: 'quz' },
{ kind, name: 'foo', frontMatter: { date: new Date('1992-10-21') } },
{ kind, name: 'baz' }
])
expect(data).toEqual([
['foo', 'Foo'],
['baz', 'Baz'],
['quz', 'Quz']
])
})
it('should take priority `frontMatter.title` over name', () => {
const data = sortPages([
{ kind, name: 'baz' },
{ kind, name: 'foo', frontMatter: { title: 'abc' } },
{ kind, name: 'quz' }
])
expect(data).toEqual([
['foo', 'abc'],
['baz', 'Baz'],
['quz', 'Quz']
])
})
it('should sort numeric', () => {
const data = sortPages([
{ kind, name: '10-baz' },
{ kind, name: '0-foo' },
{ kind, name: '2.5-quz' }
])
expect(data).toEqual([
['0-foo', '0 Foo'],
['2.5-quz', '2.5 Quz'],
['10-baz', '10 Baz']
])
})
it('should capitalize `Folder`', () => {
const data = sortPages([
{ kind, name: 'quz' },
{ kind: 'Folder', name: 'foo' },
{ kind, name: 'baz' }
])
expect(data).toEqual([
['baz', 'Baz'],
['foo', 'Foo'],
['quz', 'Quz']
])
})
})