-
-
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): enable 2nd level sidebar collapse
- Loading branch information
Showing
8 changed files
with
320 additions
and
161 deletions.
There are no files selected for viewing
204 changes: 123 additions & 81 deletions
204
__tests__/unit/client/theme-default/support/sidebar.test.ts
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,96 +1,138 @@ | ||
import { getSidebar } from 'client/theme-default/support/sidebar' | ||
import { getSidebar, hasActiveLink } 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: [ | ||
describe('getSidebar', () => { | ||
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: 'C', | ||
link: '' | ||
text: 'D', | ||
items: [{ text: 'D', 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) | ||
|
||
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) | ||
}) | ||
}) | ||
}) | ||
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('hasActiveLink', () => { | ||
test('checks `SidebarLink`', () => { | ||
const item = { text: 'Item 001', link: '/active' } | ||
|
||
expect(hasActiveLink(item, 'active')).toBe(true) | ||
expect(hasActiveLink(item, 'inactive')).toBe(false) | ||
}) | ||
}) | ||
describe('nested sidebar sort', () => { | ||
const nested = [ | ||
{ | ||
text: 'D', | ||
|
||
test('checks `SidebarItem`', () => { | ||
const item = { | ||
text: 'Item 001', | ||
items: [ | ||
{ | ||
text: 'D', | ||
link: '' | ||
} | ||
{ text: 'Item 001', link: '/active-1' }, | ||
{ text: 'Item 002', link: '/active-2' } | ||
] | ||
} | ||
] | ||
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) | ||
|
||
expect(hasActiveLink(item, 'active-1')).toBe(true) | ||
expect(hasActiveLink(item, 'inactive')).toBe(false) | ||
}) | ||
test('gets / sidebar again', () => { | ||
expect(getSidebar(nestedSidebar, '/some-entry.html')).toBe(root) | ||
|
||
test('checks `SidebarItem[]`', () => { | ||
const item = [ | ||
{ | ||
text: 'Item 001', | ||
items: [ | ||
{ text: 'Item 001', link: '/active-1' }, | ||
{ text: 'Item 002', link: '/active-2' } | ||
] | ||
}, | ||
{ | ||
text: 'Item 002', | ||
items: [ | ||
{ text: 'Item 003', link: '/active-3' }, | ||
{ text: 'Item 004', link: '/active-4' } | ||
] | ||
} | ||
] | ||
|
||
expect(hasActiveLink(item, 'active-1')).toBe(true) | ||
expect(hasActiveLink(item, 'active-3')).toBe(true) | ||
expect(hasActiveLink(item, 'inactive')).toBe(false) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.