1
0
Fork 0
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:
Raphaël TISON 2024-10-15 22:22:10 +02:00 committed by GitHub
parent f57c089ae2
commit a133a33a00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 184 additions and 0 deletions

View 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);
});
});
});