mirror of https://github.com/vuejs/vitepress
feat(theme): sort multiple sidebars (#1552)
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>pull/1554/head
parent
701b876bc7
commit
db1c343dfb
@ -0,0 +1,97 @@
|
|||||||
|
import { describe, test, expect } from 'vitest'
|
||||||
|
import { getSidebar } from 'client/theme-default/support/sidebar'
|
||||||
|
|
||||||
|
describe('client/theme-default/support/sidebar', () => {
|
||||||
|
const root = [
|
||||||
|
{
|
||||||
|
text: 'A',
|
||||||
|
collapsible: true,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: 'A',
|
||||||
|
link: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'B',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: 'B',
|
||||||
|
link: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const another = [
|
||||||
|
{
|
||||||
|
text: 'C',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: 'C',
|
||||||
|
link: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
describe('normal sidebar sort', () => {
|
||||||
|
const normalSidebar = {
|
||||||
|
'/': root,
|
||||||
|
'/multi-sidebar/': another
|
||||||
|
}
|
||||||
|
test('gets / sidebar', () => {
|
||||||
|
expect(getSidebar(normalSidebar, '/')).toBe(root)
|
||||||
|
})
|
||||||
|
test('gets /multi-sidebar/ sidebar', () => {
|
||||||
|
expect(getSidebar(normalSidebar, '/multi-sidebar/')).toBe(another)
|
||||||
|
})
|
||||||
|
test('gets / sidebar again', () => {
|
||||||
|
expect(getSidebar(normalSidebar, '/some-entry.html')).toBe(root)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('reversed sidebar sort', () => {
|
||||||
|
const reversedSidebar = {
|
||||||
|
'/multi-sidebar/': another,
|
||||||
|
'/': root
|
||||||
|
}
|
||||||
|
test('gets / sidebar', () => {
|
||||||
|
expect(getSidebar(reversedSidebar, '/')).toBe(root)
|
||||||
|
})
|
||||||
|
test('gets /multi-sidebar/ sidebar', () => {
|
||||||
|
expect(getSidebar(reversedSidebar, '/multi-sidebar/')).toBe(another)
|
||||||
|
})
|
||||||
|
test('gets / sidebar again', () => {
|
||||||
|
expect(getSidebar(reversedSidebar, '/some-entry.html')).toBe(root)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('nested sidebar sort', () => {
|
||||||
|
const nested = [
|
||||||
|
{
|
||||||
|
text: 'D',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: 'D',
|
||||||
|
link: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const nestedSidebar = {
|
||||||
|
'/': root,
|
||||||
|
'/multi-sidebar/': another,
|
||||||
|
'/multi-sidebar/nested/': nested
|
||||||
|
}
|
||||||
|
test('gets / sidebar', () => {
|
||||||
|
expect(getSidebar(nestedSidebar, '/')).toBe(root)
|
||||||
|
})
|
||||||
|
test('gets /multi-sidebar/ sidebar', () => {
|
||||||
|
expect(getSidebar(nestedSidebar, '/multi-sidebar/')).toBe(another)
|
||||||
|
})
|
||||||
|
test('gets /multi-sidebar/nested/ sidebar', () => {
|
||||||
|
expect(getSidebar(nestedSidebar, '/multi-sidebar/nested/')).toBe(nested)
|
||||||
|
})
|
||||||
|
test('gets / sidebar again', () => {
|
||||||
|
expect(getSidebar(nestedSidebar, '/some-entry.html')).toBe(root)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,40 @@
|
|||||||
|
import { expect, test } from 'vitest'
|
||||||
|
import { page, vitePressTestUrl, waitForLayout } from '~utils'
|
||||||
|
|
||||||
|
describe('test multi sidebar sort root', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await page.goto(
|
||||||
|
vitePressTestUrl + '/frontmatter/multiple-levels-outline.html'
|
||||||
|
)
|
||||||
|
await waitForLayout()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('using / sidebar', async () => {
|
||||||
|
const sidebarLocator = await page.locator(
|
||||||
|
'.VPSidebarGroup .title .title-text'
|
||||||
|
)
|
||||||
|
|
||||||
|
const sidebarContent = await sidebarLocator.allTextContents()
|
||||||
|
expect(sidebarContent).toEqual([
|
||||||
|
'Frontmatter',
|
||||||
|
'Static Data',
|
||||||
|
'Multi Sidebar Test'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('test multi sidebar sort other', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await page.goto(vitePressTestUrl + '/multi-sidebar/index.html')
|
||||||
|
await waitForLayout()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('using /multi-sidebar/ sidebar', async () => {
|
||||||
|
const sidebarLocator = await page.locator(
|
||||||
|
'.VPSidebarGroup .title .title-text'
|
||||||
|
)
|
||||||
|
|
||||||
|
const sidebarContent = await sidebarLocator.allTextContents()
|
||||||
|
expect(sidebarContent).toEqual(['Multi Sidebar'])
|
||||||
|
})
|
||||||
|
})
|
@ -1,3 +1,3 @@
|
|||||||
# Full Configured VitePress Example
|
# Full Configured VitePress Example
|
||||||
|
|
||||||
WIP
|
WIP
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: Multi Sidebar Test
|
||||||
|
---
|
||||||
|
|
||||||
|
# Multi Sidebar Test
|
Loading…
Reference in new issue