-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: macro glossarysidebar * fix: glossarysidebar test --------- Co-authored-by: Vitalii Perehonchuk <[email protected]> Co-authored-by: Mykola Myslovskyi <[email protected]>
- Loading branch information
1 parent
b60400a
commit c793b47
Showing
5 changed files
with
236 additions
and
0 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
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,34 @@ | ||
const pageToNavItem = ({ path, slug, title }, currentSlug) => ({ | ||
title, | ||
path, | ||
isCurrent: slug === currentSlug, | ||
}); | ||
|
||
export default function GlossarySidebar() { | ||
const { | ||
env: { slug, targetLocale }, | ||
registry, | ||
} = this; | ||
const glossaryPages = registry.getChildren('Glossary', false); | ||
const translatedGlossaryPages = glossaryPages.filter( | ||
(item) => item.hasLocalizedContent, | ||
); | ||
function sortByTitle({ title: titleA = '' }, { title: titleB = '' }) { | ||
return titleA.localeCompare(titleB, targetLocale); | ||
} | ||
// TODO: we definitely need it typed at some point | ||
return [ | ||
{ | ||
title: 'Глосарій', | ||
sections: [ | ||
{ | ||
expanded: true, | ||
items: translatedGlossaryPages | ||
.map((item) => pageToNavItem(item, slug)) | ||
.sort(sortByTitle), | ||
title: 'Терміни', | ||
}, | ||
], | ||
}, | ||
]; | ||
} |
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,167 @@ | ||
import test from 'ava'; | ||
|
||
import { macros } from '../../../../lib/kuma'; | ||
|
||
test("Macros 'GlossarySidebar' should be present", (t) => { | ||
t.truthy(macros({}).lookup('GlossarySidebar')); | ||
|
||
t.timeout(200); | ||
}); | ||
|
||
test("Macros 'GlossarySidebar' should generate partial navigation for glossary", (t) => { | ||
const GlossarySidebar = macros({ | ||
env: { | ||
slug: 'Glossary/Truthy', | ||
}, | ||
registry: { | ||
getChildren: () => [ | ||
{ | ||
hasLocalizedContent: true, | ||
title: 'Хибні значення', | ||
path: '/en-US/docs/Glossary/Falsy', | ||
slug: 'Glossary/Falsy', | ||
}, | ||
{ | ||
hasLocalizedContent: true, | ||
title: 'Істинні значення', | ||
path: '/en-US/docs/Glossary/Truthy', | ||
slug: 'Glossary/Truthy', | ||
}, | ||
{ | ||
title: 'Undefined', | ||
path: '/en-US/docs/Glossary/Undefined', | ||
slug: 'Glossary/Undefined', | ||
}, | ||
{ | ||
title: 'Null', | ||
path: '/en-US/docs/Glossary/Null', | ||
slug: 'Glossary/Null', | ||
}, | ||
{ | ||
title: 'NaN', | ||
path: '/en-US/docs/Glossary/NaN', | ||
slug: 'Glossary/NaN', | ||
}, | ||
{ | ||
title: 'Primitive', | ||
path: '/en-US/docs/Glossary/Primitive', | ||
slug: 'Glossary/Primitive', | ||
}, | ||
{ | ||
title: 'Object', | ||
path: '/en-US/docs/Glossary/Object', | ||
slug: 'Glossary/Object', | ||
}, | ||
{ | ||
title: 'Array', | ||
path: '/en-US/docs/Glossary/Array', | ||
slug: 'Glossary/Array', | ||
}, | ||
{ | ||
title: 'Function', | ||
path: '/en-US/docs/Glossary/Function', | ||
slug: 'Glossary/Function', | ||
}, | ||
{ | ||
title: 'Operator', | ||
path: '/en-US/docs/Glossary/Operator', | ||
slug: 'Glossary/Operator', | ||
}, | ||
{ | ||
title: 'Statement', | ||
path: '/en-US/docs/Glossary/Statement', | ||
slug: 'Glossary/Statement', | ||
}, | ||
{ | ||
title: 'Expression', | ||
path: '/en-US/docs/Glossary/Expression', | ||
slug: 'Glossary/Expression', | ||
}, | ||
{ | ||
title: 'Keyword', | ||
path: '/en-US/docs/Glossary/Keyword', | ||
slug: 'Glossary/Keyword', | ||
}, | ||
{ | ||
title: 'Property', | ||
path: '/en-US/docs/Glossary/Property', | ||
slug: 'Glossary/Property', | ||
}, | ||
{ | ||
title: 'Event', | ||
path: '/en-US/docs/Glossary/Event', | ||
slug: 'Glossary/Event', | ||
}, | ||
{ | ||
title: 'Method', | ||
path: '/en-US/docs/Glossary/Method', | ||
slug: 'Glossary/Method', | ||
}, | ||
{ | ||
title: 'Interface', | ||
path: '/en-US/docs/Glossary/Interface', | ||
slug: 'Glossary/Interface', | ||
}, | ||
{ | ||
title: 'Array.prototype.map()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/map', | ||
}, | ||
{ | ||
title: 'Array.prototype.filter()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/filter', | ||
}, | ||
{ | ||
title: 'Array.prototype.reduce()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/reduce', | ||
}, | ||
{ | ||
title: 'Array.prototype.forEach()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/forEach', | ||
}, | ||
{ | ||
title: 'Array.prototype.every()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/every', | ||
}, | ||
{ | ||
title: 'Array.prototype.some()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/some', | ||
}, | ||
{ | ||
title: 'Array.prototype.indexOf()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/indexOf', | ||
}, | ||
{ | ||
title: 'Array.prototype.lastIndexOf()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf', | ||
}, | ||
{ | ||
title: 'Array.prototype.includes()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/includes', | ||
}, | ||
{ | ||
title: 'Array.prototype.find()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/find', | ||
}, | ||
{ | ||
title: 'Array.prototype.findIndex()', | ||
path: '/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex', | ||
slug: 'Web/JavaScript/Reference/Global_Objects/Array/findIndex', | ||
}, | ||
], | ||
}, | ||
}).lookup('GlossarySidebar'); | ||
|
||
t.snapshot(GlossarySidebar()); | ||
|
||
t.timeout(200); | ||
}); |
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,33 @@ | ||
# Snapshot report for `test/src/kuma/macros/GlossarySidebar.mjs` | ||
|
||
The actual snapshot is saved in `GlossarySidebar.mjs.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## Macros 'GlossarySidebar' should generate partial navigation for glossary | ||
|
||
> Snapshot 1 | ||
[ | ||
{ | ||
sections: [ | ||
{ | ||
expanded: true, | ||
items: [ | ||
{ | ||
isCurrent: true, | ||
path: '/en-US/docs/Glossary/Truthy', | ||
title: 'Істинні значення', | ||
}, | ||
{ | ||
isCurrent: false, | ||
path: '/en-US/docs/Glossary/Falsy', | ||
title: 'Хибні значення', | ||
}, | ||
], | ||
title: 'Терміни', | ||
}, | ||
], | ||
title: 'Глосарій', | ||
}, | ||
] |
Binary file not shown.