Skip to content

Commit

Permalink
Blog: add localized blog post date test
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Mar 4, 2021
1 parent e7dd63e commit 0ae6adc
Showing 1 changed file with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import {PluginOptionSchema} from '../pluginOptionSchema';
import {PluginOptions, EditUrlFunction} from '../types';
import Joi from 'joi';

const DefaultI18N: I18n = {
currentLocale: 'en',
locales: ['en'],
defaultLocale: 'en',
localeConfigs: {},
};
function getI18n(locale: string): I18n {
return {
currentLocale: locale,
locales: [locale],
defaultLocale: locale,
localeConfigs: {},
};
}

const DefaultI18N: I18n = getI18n('en');

function validateAndNormalize(
schema: Joi.ObjectSchema,
Expand All @@ -40,6 +44,7 @@ describe('loadBlog', () => {
const getBlogPosts = async (
siteDir: string,
pluginOptions: Partial<PluginOptions> = {},
i18n: I18n = DefaultI18N,
) => {
const generatedFilesDir: string = path.resolve(siteDir, '.docusaurus');
const siteConfig = {
Expand All @@ -52,7 +57,7 @@ describe('loadBlog', () => {
siteDir,
siteConfig,
generatedFilesDir,
i18n: DefaultI18N,
i18n,
} as LoadContext,
validateAndNormalize(PluginOptionSchema, {
path: PluginPath,
Expand Down Expand Up @@ -159,6 +164,27 @@ describe('loadBlog', () => {
});
});

test('simple website blog dates localized', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const blogPostsFrench = await getBlogPosts(siteDir, {}, getI18n('fr'));
expect(blogPostsFrench).toHaveLength(5);
expect(blogPostsFrench[0].metadata.formattedDate).toMatchInlineSnapshot(
`"16 août 2020"`,
);
expect(blogPostsFrench[1].metadata.formattedDate).toMatchInlineSnapshot(
`"15 août 2020"`,
);
expect(blogPostsFrench[2].metadata.formattedDate).toMatchInlineSnapshot(
`"27 février 2020"`,
);
expect(blogPostsFrench[3].metadata.formattedDate).toMatchInlineSnapshot(
`"1 janvier 2019"`,
);
expect(blogPostsFrench[4].metadata.formattedDate).toMatchInlineSnapshot(
`"14 décembre 2018"`,
);
});

test('edit url with editLocalizedBlogs true', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const blogPosts = await getBlogPosts(siteDir, {editLocalizedFiles: true});
Expand Down

0 comments on commit 0ae6adc

Please sign in to comment.