-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
574 additions
and
361 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
199 changes: 117 additions & 82 deletions
199
__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,131 @@ | ||
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) | ||
}) | ||
}) | ||
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) | ||
|
||
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('nested sidebar sort', () => { | ||
const nested = [ | ||
{ | ||
text: 'D', | ||
|
||
describe('hasActiveLink', () => { | ||
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('active-1', item)).toBe(true) | ||
expect(hasActiveLink('inactive', item)).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('active-1', item)).toBe(true) | ||
expect(hasActiveLink('active-3', item)).toBe(true) | ||
expect(hasActiveLink('inactive', item)).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
Oops, something went wrong.