-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): sort multiple sidebars (#1552)
Co-authored-by: Divyansh Singh <[email protected]>
- Loading branch information
Showing
6 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Full Configured VitePress Example | ||
|
||
WIP | ||
WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Multi Sidebar Test | ||
--- | ||
|
||
# Multi Sidebar Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters