mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-30 22:23:00 +00:00
* [v2] tags to doc, same as tags to blog - [IN PROGRESS] - Addition of plugin-content-docs - Addition of DocTagsListPage in `docusaurus-theme-classic` ! Error exists for this commit towards the theme aspect and help required. Commit towards #3434 * docs: make tags list page work * temp: disable onBrokenLinks * theme bootstrap: create DocTagsListPage * DocTagsPage added and functionality too - individual doc tag page added to show docs for that specific tag * Added all Docs Tags Link * add some shared tag utils * move tag tests to _dogfooding * fix type * fix some tests * fix blog test * refactor blog post tags handling * better yaml tag examples * better dogfood md files * refactor and factorize theme tag components * finish DocTagDocListPage * Extract DocItemFooter + add inline tag list * minor fix * better typings * fix versions.test.ts tests * add tests for doc tags * fix tests * test toTagDocListProp * move shared theme code to tagUtils * Add new theme translation keys * move common theme code to tagUtils + add tests * update-code-translations should handle theme-common * update french translation * revert add translation * fix pluralization problem in theme.docs.tagDocListPageTitle * add theme component configuration options * add more tags tests * add documentation for docs tagging Co-authored-by: slorber <lorber.sebastien@gmail.com>
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import Joi from '../Joi';
|
|
import {JoiFrontMatter} from '../JoiFrontMatter';
|
|
import {validateFrontMatter} from '../validationUtils';
|
|
|
|
describe('validateFrontMatter', () => {
|
|
test('should accept good values', () => {
|
|
const schema = Joi.object<{test: string}>({
|
|
test: Joi.string(),
|
|
});
|
|
const frontMatter = {
|
|
test: 'hello',
|
|
};
|
|
expect(validateFrontMatter(frontMatter, schema)).toEqual(frontMatter);
|
|
});
|
|
|
|
test('should reject bad values', () => {
|
|
const consoleError = jest.spyOn(console, 'error').mockImplementation();
|
|
const schema = Joi.object<{test: string}>({
|
|
test: Joi.string(),
|
|
});
|
|
const frontMatter = {
|
|
test: true,
|
|
};
|
|
expect(() =>
|
|
validateFrontMatter(frontMatter, schema),
|
|
).toThrowErrorMatchingInlineSnapshot(`"\\"test\\" must be a string"`);
|
|
expect(consoleError).toHaveBeenCalledWith(
|
|
expect.stringContaining('The following frontmatter'),
|
|
);
|
|
});
|
|
|
|
// Fix Yaml trying to convert strings to numbers automatically
|
|
// We only want to deal with a single type in the final frontmatter (not string | number)
|
|
test('should convert number values to string when string schema', () => {
|
|
const schema = Joi.object<{test: string}>({
|
|
test: JoiFrontMatter.string(),
|
|
});
|
|
const frontMatter = {
|
|
test: 42,
|
|
};
|
|
expect(validateFrontMatter(frontMatter, schema)).toEqual({test: '42'});
|
|
});
|
|
|
|
// Helps to fix Yaml trying to convert strings to dates automatically
|
|
// We only want to deal with a single type in the final frontmatter (not string | Date)
|
|
test('should convert date values when string schema', () => {
|
|
const schema = Joi.object<{test: string}>({
|
|
test: JoiFrontMatter.string(),
|
|
});
|
|
const date = new Date();
|
|
const frontMatter = {
|
|
test: date,
|
|
};
|
|
expect(validateFrontMatter(frontMatter, schema)).toEqual({
|
|
test: date.toString(),
|
|
});
|
|
});
|
|
});
|