mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add unit tests for utils (#5412)
* add unit tests for Card utils * add unit tests for DateFnsLocale utils * fix lint * add unit tests for Events utils * fix lint * fix lint
This commit is contained in:
parent
f57c089ae2
commit
a133a33a00
3 changed files with 184 additions and 0 deletions
58
src/utils/dateFnsLocale.test.ts
Normal file
58
src/utils/dateFnsLocale.test.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import * as dateFnsLocale from './dateFnsLocale';
|
||||
|
||||
describe('Utils: dateFnsLocale', () => {
|
||||
describe('Function: getLocale', () => {
|
||||
it('Should return "en-US" by default', () => {
|
||||
const { code } = dateFnsLocale.getLocale();
|
||||
expect(code).toEqual('en-US');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Function: getLocaleWithSuffix', () => {
|
||||
it('Should return "en-US" by default with addSuffix to true', () => {
|
||||
const { addSuffix, locale } = dateFnsLocale.getLocaleWithSuffix();
|
||||
|
||||
expect(addSuffix).toEqual(true);
|
||||
expect(locale.code).toEqual('en-US');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Function: updateLocale', () => {
|
||||
it('Should import "fr-ca" locale', async () => {
|
||||
const expectedCode = 'fr-CA';
|
||||
|
||||
await dateFnsLocale.updateLocale('fr-ca');
|
||||
const { code } = dateFnsLocale.getLocale();
|
||||
const { locale: localeWithSuffix } =
|
||||
dateFnsLocale.getLocaleWithSuffix();
|
||||
|
||||
expect(code).toEqual(expectedCode);
|
||||
expect(localeWithSuffix.code).toEqual(expectedCode);
|
||||
});
|
||||
|
||||
it('Should import "fr" locale', async () => {
|
||||
const expectedCode = 'fr';
|
||||
|
||||
await dateFnsLocale.updateLocale('fr-fr');
|
||||
const { code } = dateFnsLocale.getLocale();
|
||||
const { locale: localeWithSuffix } =
|
||||
dateFnsLocale.getLocaleWithSuffix();
|
||||
|
||||
expect(code).toEqual(expectedCode);
|
||||
expect(localeWithSuffix.code).toEqual(expectedCode);
|
||||
});
|
||||
|
||||
it('Should import "en-US" locale if given locale is not found', async () => {
|
||||
const expectedCode = 'en-US';
|
||||
|
||||
await dateFnsLocale.updateLocale('unknown-unknown');
|
||||
const { code } = dateFnsLocale.getLocale();
|
||||
const { locale: localeWithSuffix } =
|
||||
dateFnsLocale.getLocaleWithSuffix();
|
||||
|
||||
expect(code).toEqual(expectedCode);
|
||||
expect(localeWithSuffix.code).toEqual(expectedCode);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue