From d5f3d98dfc362d1ad730285b4899d2c7ddcf2afc Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:12:39 +0200 Subject: [PATCH] chore(web): use development lang for tests (#10025) --- .../components/album-page/__tests__/album-card.spec.ts | 9 +-------- .../lib/components/album-page/album-description.spec.ts | 5 ----- .../notification/__tests__/notification-card.spec.ts | 5 ----- .../notification/__tests__/notification-list.spec.ts | 4 +--- web/src/lib/i18n.spec.ts | 3 --- web/src/test-data/setup.ts | 5 +++++ 6 files changed, 7 insertions(+), 24 deletions(-) diff --git a/web/src/lib/components/album-page/__tests__/album-card.spec.ts b/web/src/lib/components/album-page/__tests__/album-card.spec.ts index 6ffa273a4d..977899db82 100644 --- a/web/src/lib/components/album-page/__tests__/album-card.spec.ts +++ b/web/src/lib/components/album-page/__tests__/album-card.spec.ts @@ -2,7 +2,6 @@ import { sdkMock } from '$lib/__mocks__/sdk.mock'; import { albumFactory } from '@test-data'; import '@testing-library/jest-dom'; import { fireEvent, render, waitFor, type RenderResult } from '@testing-library/svelte'; -import { init, register, waitLocale } from 'svelte-i18n'; import AlbumCard from '../album-card.svelte'; const onShowContextMenu = vi.fn(); @@ -10,12 +9,6 @@ const onShowContextMenu = vi.fn(); describe('AlbumCard component', () => { let sut: RenderResult; - beforeAll(async () => { - await init({ fallbackLocale: 'en-US' }); - register('en-US', () => import('$lib/i18n/en.json')); - await waitLocale('en-US'); - }); - it.each([ { album: albumFactory.build({ albumThumbnailAssetId: null, shared: false, assetCount: 0 }), @@ -43,7 +36,7 @@ describe('AlbumCard component', () => { const albumImgElement = sut.getByTestId('album-image'); const albumNameElement = sut.getByTestId('album-name'); const albumDetailsElement = sut.getByTestId('album-details'); - const detailsText = `${count} items` + (shared ? ' . Shared' : ''); + const detailsText = `${count} items` + (shared ? ' . shared' : ''); expect(albumImgElement).toHaveAttribute('src'); expect(albumImgElement).toHaveAttribute('alt', album.albumName); diff --git a/web/src/lib/components/album-page/album-description.spec.ts b/web/src/lib/components/album-page/album-description.spec.ts index 61bfb70596..1c069de2bc 100644 --- a/web/src/lib/components/album-page/album-description.spec.ts +++ b/web/src/lib/components/album-page/album-description.spec.ts @@ -1,14 +1,9 @@ import AlbumDescription from '$lib/components/album-page/album-description.svelte'; import '@testing-library/jest-dom'; import { render, screen } from '@testing-library/svelte'; -import { init } from 'svelte-i18n'; import { describe } from 'vitest'; describe('AlbumDescription component', () => { - beforeAll(async () => { - await init({ fallbackLocale: 'en-US' }); - }); - it('shows an AutogrowTextarea component when isOwned is true', () => { render(AlbumDescription, { isOwned: true, id: '', description: '' }); const autogrowTextarea = screen.getByTestId('autogrow-textarea'); diff --git a/web/src/lib/components/shared-components/notification/__tests__/notification-card.spec.ts b/web/src/lib/components/shared-components/notification/__tests__/notification-card.spec.ts index 25d648fca4..76b9c39564 100644 --- a/web/src/lib/components/shared-components/notification/__tests__/notification-card.spec.ts +++ b/web/src/lib/components/shared-components/notification/__tests__/notification-card.spec.ts @@ -1,16 +1,11 @@ import '@testing-library/jest-dom'; import { cleanup, render, type RenderResult } from '@testing-library/svelte'; -import { init } from 'svelte-i18n'; import { NotificationType } from '../notification'; import NotificationCard from '../notification-card.svelte'; describe('NotificationCard component', () => { let sut: RenderResult; - beforeAll(async () => { - await init({ fallbackLocale: 'en-US' }); - }); - it('disposes timeout if already removed from the DOM', () => { vi.spyOn(window, 'clearTimeout'); diff --git a/web/src/lib/components/shared-components/notification/__tests__/notification-list.spec.ts b/web/src/lib/components/shared-components/notification/__tests__/notification-list.spec.ts index c84a6d4582..44634d6b20 100644 --- a/web/src/lib/components/shared-components/notification/__tests__/notification-list.spec.ts +++ b/web/src/lib/components/shared-components/notification/__tests__/notification-list.spec.ts @@ -1,6 +1,5 @@ import '@testing-library/jest-dom'; import { render, waitFor, type RenderResult } from '@testing-library/svelte'; -import { init } from 'svelte-i18n'; import { get } from 'svelte/store'; import { NotificationType, notificationController } from '../notification'; import NotificationList from '../notification-list.svelte'; @@ -12,8 +11,7 @@ function _getNotificationListElement(sut: RenderResult): HTMLA describe('NotificationList component', () => { const sut: RenderResult = render(NotificationList); - beforeAll(async () => { - await init({ fallbackLocale: 'en-US' }); + beforeAll(() => { // https://testing-library.com/docs/svelte-testing-library/faq#why-arent-transition-events-running vi.stubGlobal('requestAnimationFrame', (fn: FrameRequestCallback) => { setTimeout(() => fn(Date.now()), 16); diff --git a/web/src/lib/i18n.spec.ts b/web/src/lib/i18n.spec.ts index 6bfcc32b43..43f3a689e9 100644 --- a/web/src/lib/i18n.spec.ts +++ b/web/src/lib/i18n.spec.ts @@ -1,7 +1,6 @@ import messages from '$lib/i18n/en.json'; import { exec as execCallback } from 'node:child_process'; import { promisify } from 'node:util'; -import { init } from 'svelte-i18n'; type Messages = { [key: string]: string | Messages }; @@ -23,8 +22,6 @@ function setEmptyMessages(messages: Messages) { } describe('i18n', () => { - beforeEach(() => init({ fallbackLocale: 'dev' })); - test('no missing messages', async () => { const { stdout } = await exec('npx svelte-i18n extract -c svelte.config.js "src/**/*"'); const extractedMessages: Messages = JSON.parse(stdout); diff --git a/web/src/test-data/setup.ts b/web/src/test-data/setup.ts index 7b0828bfa8..6709bd5b80 100644 --- a/web/src/test-data/setup.ts +++ b/web/src/test-data/setup.ts @@ -1 +1,6 @@ import '@testing-library/jest-dom'; +import { init } from 'svelte-i18n'; + +beforeAll(async () => { + await init({ fallbackLocale: 'dev' }); +});