Skip to content

Commit 70f367a

Browse files
committed
feat(theme): add versions attribute to docsVersionDropdown navbar item: tests for new options
1 parent afd9b83 commit 70f367a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

packages/docusaurus-theme-classic/src/__tests__/options.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,74 @@ describe('themeConfig', () => {
827827
);
828828
});
829829
});
830+
831+
describe('docsVersionDropdown', () => {
832+
describe('versions', () => {
833+
it('accepts array of strings', () => {
834+
const config = {
835+
navbar: {
836+
items: [
837+
{
838+
type: 'docsVersionDropdown',
839+
versions: ['current', '1.0'],
840+
},
841+
],
842+
},
843+
};
844+
testValidateThemeConfig(config);
845+
});
846+
847+
it('rejects array of non-strings', () => {
848+
const config = {
849+
navbar: {
850+
items: [
851+
{
852+
type: 'docsVersionDropdown',
853+
versions: [1, 2],
854+
},
855+
],
856+
},
857+
};
858+
expect(() =>
859+
testValidateThemeConfig(config),
860+
).toThrowErrorMatchingInlineSnapshot(
861+
`""navbar.items[0].versions[0]" must be a string"`,
862+
);
863+
});
864+
865+
it('accepts dictionary of version objects', () => {
866+
const config = {
867+
navbar: {
868+
items: [
869+
{
870+
type: 'docsVersionDropdown',
871+
versions: {current: {}, '1.0': {label: '1.x'}},
872+
},
873+
],
874+
},
875+
};
876+
testValidateThemeConfig(config);
877+
});
878+
879+
it('rejects dictionary of invalid objects', () => {
880+
const config = {
881+
navbar: {
882+
items: [
883+
{
884+
type: 'docsVersionDropdown',
885+
versions: {current: {}, '1.0': {invalid: '1.x'}},
886+
},
887+
],
888+
},
889+
};
890+
expect(() =>
891+
testValidateThemeConfig(config),
892+
).toThrowErrorMatchingInlineSnapshot(
893+
`""navbar.items[0].versions.1.0.invalid" is not allowed"`,
894+
);
895+
});
896+
});
897+
});
830898
});
831899

832900
describe('validateOptions', () => {

0 commit comments

Comments
 (0)