mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 03:26:57 +02:00
refactor(v2): add useThemeConfig hook + cleanup useless theme default values (#3394)
* refactor(theme-classic): clean default or fallback values * refactor(theme-classic): fix announcementbar undefined error * refactor(theme-classic): fixed react hook warning error * refactor(theme-classic): revert prism destruct * create useThemeConfig and use it whenever possible * validateThemeConfig => add [] as default value for almost all arrays * fix tests Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
f5f2064656
commit
0951eef2d7
16 changed files with 154 additions and 142 deletions
|
@ -11,14 +11,19 @@ const {ThemeConfigSchema, DEFAULT_CONFIG} = require('../validateThemeConfig');
|
|||
|
||||
const {normalizeThemeConfig} = require('@docusaurus/utils-validation');
|
||||
|
||||
function testValidateThemeConfig(themeConfig) {
|
||||
return normalizeThemeConfig(ThemeConfigSchema, themeConfig);
|
||||
function testValidateThemeConfig(partialThemeConfig) {
|
||||
return normalizeThemeConfig(ThemeConfigSchema, {
|
||||
...DEFAULT_CONFIG,
|
||||
...partialThemeConfig,
|
||||
});
|
||||
}
|
||||
|
||||
function testOk(partialConfig) {
|
||||
expect(testValidateThemeConfig(partialConfig)).toEqual({
|
||||
function testOk(partialThemeConfig) {
|
||||
expect(
|
||||
testValidateThemeConfig({...DEFAULT_CONFIG, ...partialThemeConfig}),
|
||||
).toEqual({
|
||||
...DEFAULT_CONFIG,
|
||||
...partialConfig,
|
||||
...partialThemeConfig,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -101,7 +106,10 @@ describe('themeConfig', () => {
|
|||
};
|
||||
expect(testValidateThemeConfig(altTagConfig)).toEqual({
|
||||
...DEFAULT_CONFIG,
|
||||
...altTagConfig,
|
||||
navbar: {
|
||||
...DEFAULT_CONFIG.navbar,
|
||||
...altTagConfig.navbar,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -117,7 +125,7 @@ describe('themeConfig', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe.only('customCss config', () => {
|
||||
describe('customCss config', () => {
|
||||
test('should accept customCss undefined', () => {
|
||||
testOk({
|
||||
customCss: undefined,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue