Skip to content

Commit

Permalink
test: Add tests for new luxon configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ShtibsDev committed Feb 20, 2024
1 parent c9c55fd commit 4679b07
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions tests/generate.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import MockDate from 'mockdate';
import dateFnsGenerateConfig from '../src/generate/dateFns';
import dayjsGenerateConfig from '../src/generate/dayjs';
import luxonGenerateConfig from '../src/generate/luxon';
import luxonGenerateConfig, {
generateConfigWithLocale as luxonGenerateConfigWithLocale,
} from '../src/generate/luxon';
import momentGenerateConfig from '../src/generate/moment';
import { getMoment } from './util/commonUtil';

Expand All @@ -23,6 +25,7 @@ describe('Picker.Generate', () => {
{ name: 'dayjs', generateConfig: dayjsGenerateConfig },
{ name: 'date-fns', generateConfig: dateFnsGenerateConfig },
{ name: 'luxon', generateConfig: luxonGenerateConfig },
{ name: 'luxon-with-locale', generateConfig: luxonGenerateConfigWithLocale },
];

list.forEach(({ name, generateConfig }) => {
Expand Down Expand Up @@ -102,7 +105,7 @@ describe('Picker.Generate', () => {
});

it('week', () => {
if (!['date-fns', 'luxon'].includes(name)) {
if (!['date-fns', 'luxon', 'luxon-with-locale'].includes(name)) {
expect(
generateConfig.locale.format(
'en_US',
Expand Down Expand Up @@ -141,7 +144,9 @@ describe('Picker.Generate', () => {
});

it('getWeekFirstDay', () => {
const expectedUsFirstDay = name === 'luxon' ? 1 : 0;
let expectedUsFirstDay = 0;
if (name === 'luxon') expectedUsFirstDay = 1;
if (name === 'luxon-with-locale') expectedUsFirstDay = 7;

expect(generateConfig.locale.getWeekFirstDay('en_US')).toEqual(expectedUsFirstDay);
expect(generateConfig.locale.getWeekFirstDay('zh_CN')).toEqual(1);
Expand All @@ -158,25 +163,21 @@ describe('Picker.Generate', () => {

it('getWeekFirstDate', () => {
const formatStr = name === 'date-fns' ? 'yyyy-MM-dd' : 'YYYY-MM-DD';
const usDate = generateConfig.locale.getWeekFirstDate(
'en_US',
generateConfig.locale.parse('en_US', '2020-12-30', [formatStr]),
);
const cnDate = generateConfig.locale.getWeekFirstDate(
'zh_CN',
generateConfig.locale.parse('zh_CN', '2020-12-30', [formatStr]),
const [usDate, cnDate] = ['en_US', 'zh_CN'].map((locale) =>
generateConfig.locale.getWeekFirstDate(
locale,
generateConfig.locale.parse(locale, '2020-12-30', [formatStr]),
),
);

const expectedUsFirstDate = name === 'luxon' ? '28' : '27';
const expectedUsDate = name === 'luxon' ? '2020-12-28' : '2020-12-27';

expect(generateConfig.locale.format('en_US', usDate, formatStr)).toEqual(
`2020-12-${expectedUsFirstDate}`,
);
expect(generateConfig.locale.format('en_US', usDate, formatStr)).toEqual(expectedUsDate);
expect(generateConfig.locale.format('zh_CN', cnDate, formatStr)).toEqual('2020-12-28');
});

it('Parse format Wo', () => {
if (!['date-fns', 'luxon'].includes(name)) {
if (!['date-fns', 'luxon', 'luxon-with-locale'].includes(name)) {
expect(
generateConfig.locale.parse('en_US', '2012-51st', ['YYYY-Wo']).format('Wo'),
).toEqual('51st');
Expand Down Expand Up @@ -265,7 +266,7 @@ describe('Picker.Generate', () => {
),
).toEqual(49);

const expectedUsWeek = name === 'luxon' ? 49 : 50;
const expectedUsWeek = ['luxon', 'luxon-with-locale'].includes(name) ? 49 : 50;
expect(
generateConfig.locale.getWeek(
'en_US',
Expand Down

0 comments on commit 4679b07

Please sign in to comment.