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:
Shubham Kumar 2020-10-02 22:53:34 +05:30 committed by GitHub
parent f5f2064656
commit 0951eef2d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 154 additions and 142 deletions

View file

@ -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,