mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
3.3 KiB
166 lines
3.3 KiB
2 years ago
|
import { resolveHeaders } from 'client/theme-default/composables/outline'
|
||
2 years ago
|
|
||
|
describe('client/theme-default/composables/outline', () => {
|
||
|
describe('resolveHeader', () => {
|
||
|
test('levels range', () => {
|
||
|
expect(
|
||
2 years ago
|
resolveHeaders(
|
||
2 years ago
|
[
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 1',
|
||
|
link: '#h2-1'
|
||
|
},
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 1',
|
||
|
link: '#h3-1'
|
||
|
}
|
||
|
],
|
||
|
[2, 3]
|
||
|
)
|
||
|
).toEqual([
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 1',
|
||
|
link: '#h2-1',
|
||
|
children: [
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 1',
|
||
|
link: '#h3-1'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
])
|
||
|
})
|
||
|
|
||
|
test('specific level', () => {
|
||
|
expect(
|
||
2 years ago
|
resolveHeaders(
|
||
2 years ago
|
[
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 1',
|
||
|
link: '#h2-1'
|
||
|
},
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 1',
|
||
|
link: '#h3-1'
|
||
|
}
|
||
|
],
|
||
|
2
|
||
|
)
|
||
|
).toEqual([
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 1',
|
||
|
link: '#h2-1'
|
||
|
}
|
||
|
])
|
||
|
})
|
||
|
|
||
|
test('complex deep', () => {
|
||
|
expect(
|
||
2 years ago
|
resolveHeaders(
|
||
2 years ago
|
[
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 1',
|
||
|
link: '#h2-1'
|
||
|
},
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 1',
|
||
|
link: '#h3-1'
|
||
|
},
|
||
|
{
|
||
|
level: 4,
|
||
|
title: 'h4 - 1',
|
||
|
link: '#h4-1'
|
||
|
},
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 2',
|
||
|
link: '#h3-2'
|
||
|
},
|
||
|
{
|
||
|
level: 4,
|
||
|
title: 'h4 - 2',
|
||
|
link: '#h4-2'
|
||
|
},
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 2',
|
||
|
link: '#h2-2'
|
||
|
},
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 3',
|
||
|
link: '#h3-3'
|
||
|
},
|
||
|
{
|
||
|
level: 4,
|
||
|
title: 'h4 - 3',
|
||
|
link: '#h4-3'
|
||
|
}
|
||
|
],
|
||
|
'deep'
|
||
|
)
|
||
|
).toEqual([
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 1',
|
||
|
link: '#h2-1',
|
||
|
children: [
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 1',
|
||
|
link: '#h3-1',
|
||
|
children: [
|
||
|
{
|
||
|
level: 4,
|
||
|
title: 'h4 - 1',
|
||
|
link: '#h4-1'
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 2',
|
||
|
link: '#h3-2',
|
||
|
children: [
|
||
|
{
|
||
|
level: 4,
|
||
|
title: 'h4 - 2',
|
||
|
link: '#h4-2'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
level: 2,
|
||
|
title: 'h2 - 2',
|
||
|
link: '#h2-2',
|
||
|
children: [
|
||
|
{
|
||
|
level: 3,
|
||
|
title: 'h3 - 3',
|
||
|
link: '#h3-3',
|
||
|
children: [
|
||
|
{
|
||
|
level: 4,
|
||
|
title: 'h4 - 3',
|
||
|
link: '#h4-3'
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
])
|
||
|
})
|
||
|
})
|
||
|
})
|