/
navigation.ts
57 lines (49 loc) · 1.73 KB
/
navigation.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
import { describe, test, expect } from 'vitest'
import { $fetch } from '@nuxt/test-utils'
import { hash } from 'ohash'
import { jsonStringify } from '../../src/runtime/utils/json'
export const testNavigation = () => {
describe('navigation', () => {
test('Get navigation', async () => {
const query = { where: [{ _locale: 'en' }] }
const list = await $fetch(`/api/_content/navigation/${hash(query)}`, {
params: {
_params: jsonStringify(query)
}
})
expect(list.find(item => item._path === '/')).toBeTruthy()
expect(list.find(item => item._path === '/').children).toBeUndefined()
})
test('Get cats navigation', async () => {
const query = { where: [{ _path: /^\/cats/ }] }
const list = await $fetch(`/api/_content/navigation/${hash(query)}`, {
params: {
_params: jsonStringify(query)
}
})
expect(list).toMatchSnapshot('basic-navigation-cats')
})
test('Get dogs navigation', async () => {
const query = { where: [{ _path: /^\/dogs/ }] }
const list = await $fetch(`/api/_content/navigation/${hash(query)}`, {
params: {
_params: jsonStringify(query)
}
})
expect(list).toMatchSnapshot('basic-navigation-dogs')
})
test('Get numbers navigation', async () => {
const query = { where: [{ _path: /^\/numbers/ }] }
const list = await $fetch(`/api/_content/navigation/${hash(query)}`, {
params: {
_params: jsonStringify(query)
}
})
expect(list[0]?.children).toBeDefined()
const fibo = [1, 2, 3, 5, 8, 13, 21]
list[0].children.forEach((item, index) => {
expect(item.title).toEqual(String(fibo[index]))
})
})
})
}