mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 05:27:00 +02:00
fix: navbar item validation done correctly (#5202)
* Initial work Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix again Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More fix (Joi is so hard!) Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * This should pass now Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Such pain Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Minor tweaks Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More test cases Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Minor tweaks Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Errr... this should be better Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Redo isOfType Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Make things more concise Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Remove TODO Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Rename isOfType Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Slight refactor Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More error messages Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More test cases Signed-off-by: Josh-Cena <sidachen2003@gmail.com> Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
c935fe2a37
commit
4bc6a63756
2 changed files with 225 additions and 85 deletions
|
@ -134,6 +134,24 @@ describe('themeConfig', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
// Dropdown with name
|
||||
{
|
||||
type: 'dropdown',
|
||||
label: 'Tools',
|
||||
position: 'left',
|
||||
items: [
|
||||
{
|
||||
type: 'doc',
|
||||
activeSidebarClassName: 'custom-class',
|
||||
docId: 'npm',
|
||||
label: 'NPM',
|
||||
},
|
||||
{
|
||||
to: '/yarn',
|
||||
label: 'Yarn',
|
||||
},
|
||||
],
|
||||
},
|
||||
// Doc version dropdown
|
||||
{
|
||||
type: 'docsVersionDropdown',
|
||||
|
@ -181,6 +199,112 @@ describe('themeConfig', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should reject unknown navbar item type', () => {
|
||||
const config = {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
type: 'joke',
|
||||
position: 'left',
|
||||
label: 'haha',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
testValidateThemeConfig(config),
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Bad navbar item type joke"`);
|
||||
});
|
||||
|
||||
test('should reject nested dropdowns', () => {
|
||||
const config = {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
position: 'left',
|
||||
label: 'Nested',
|
||||
items: [
|
||||
{
|
||||
label: 'Still a dropdown',
|
||||
items: [
|
||||
{
|
||||
label: 'Should reject this',
|
||||
to: '/rejected',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
testValidateThemeConfig(config),
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Nested dropdowns are not allowed"`);
|
||||
});
|
||||
|
||||
test('should reject nested dropdowns', () => {
|
||||
const config = {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
position: 'left',
|
||||
label: 'Nested',
|
||||
items: [{type: 'docsVersionDropdown'}],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
testValidateThemeConfig(config),
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Nested dropdowns are not allowed"`);
|
||||
});
|
||||
|
||||
test('should reject position attribute within dropdown', () => {
|
||||
const config = {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
position: 'left',
|
||||
label: 'Dropdown',
|
||||
items: [
|
||||
{
|
||||
label: 'Hi',
|
||||
position: 'left',
|
||||
to: '/link',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
testValidateThemeConfig(config),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"\\"navbar.items[0].items[0].position\\" is not allowed"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('should give friendly error when href and to coexist', () => {
|
||||
const config = {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
position: 'left',
|
||||
label: 'Nested',
|
||||
to: '/link',
|
||||
href: 'http://example.com/link',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() =>
|
||||
testValidateThemeConfig(config),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"One and only one between \\"to\\" and \\"href\\" should be provided"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('should allow empty alt tags for the logo image in the header', () => {
|
||||
const altTagConfig = {
|
||||
navbar: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue