test: improve test coverage (#6857)

This commit is contained in:
Joshua Chen 2022-03-06 17:55:21 +08:00 committed by GitHub
parent edb4d00096
commit f763ac13a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 435 additions and 220 deletions

View file

@ -22,6 +22,47 @@ Array [
]
`;
exports[`translateContent should fallback when translation is incomplete 1`] = `
Object {
"blogListPaginated": Array [
Object {
"items": Array [
"hello",
],
"metadata": Object {
"blogDescription": "Someone's random blog",
"blogTitle": "My blog",
"nextPage": null,
"page": 1,
"permalink": "/",
"postsPerPage": 10,
"previousPage": null,
"totalCount": 1,
"totalPages": 1,
},
},
],
"blogPosts": Array [
Object {
"id": "hello",
"metadata": Object {
"date": 2021-07-19T00:00:00.000Z,
"description": "/blog/2021/06/19/hello",
"formattedDate": "June 19, 2021",
"permalink": "/blog/2021/06/19/hello",
"source": "/blog/2021/06/19/hello",
"tags": Array [],
"title": "Hello",
"truncated": true,
},
},
],
"blogSidebarTitle": "All my posts",
"blogTags": Object {},
"blogTagsListPath": "/tags",
}
`;
exports[`translateContent should return translated loaded content matching snapshot 1`] = `
Object {
"blogListPaginated": Array [

View file

@ -77,6 +77,12 @@ describe('getContentTranslationFiles', () => {
});
describe('translateContent', () => {
test('should fallback when translation is incomplete', () => {
expect(
translateContent(sampleBlogContent, [{path: 'foo', content: {}}]),
).toMatchSnapshot();
});
test('should not translate anything if translation files are untranslated', () => {
const translationFiles = getSampleTranslationFiles();
expect(translateContent(sampleBlogContent, translationFiles)).toEqual(

View file

@ -53,9 +53,6 @@ export function translateContent(
content: BlogContent,
translationFiles: TranslationFiles,
): BlogContent {
if (translationFiles.length === 0) {
return content;
}
const {content: optionsTranslations} = translationFiles[0]!;
return {
...content,