From f22a32d351d5ebf75958031078f471fc27a9da4c Mon Sep 17 00:00:00 2001 From: Eneas Rotterdam Date: Sun, 24 Nov 2024 18:54:18 +0100 Subject: [PATCH] fix: update tests for compatibility with new metadata components --- src/content/popup/Metadata/ShogiInfo.tsx | 2 +- src/content/popup/lang-tag.ts | 4 ---- src/content/popup/metadata.test.ts | 26 ++++++++++-------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/content/popup/Metadata/ShogiInfo.tsx b/src/content/popup/Metadata/ShogiInfo.tsx index 8bef6408b1..a661d6be32 100644 --- a/src/content/popup/Metadata/ShogiInfo.tsx +++ b/src/content/popup/Metadata/ShogiInfo.tsx @@ -75,7 +75,7 @@ export function ShogiInfo({ meta }: Props) { {serializeShogi(meta)} = - {move} + {move} ); } diff --git a/src/content/popup/lang-tag.ts b/src/content/popup/lang-tag.ts index 71bb2a1f9c..a9ad5a8fec 100644 --- a/src/content/popup/lang-tag.ts +++ b/src/content/popup/lang-tag.ts @@ -8,7 +8,3 @@ export function getLangTag() { } return langTag; } - -export function clearLangTagCache() { - langTag = null; -} diff --git a/src/content/popup/metadata.test.ts b/src/content/popup/metadata.test.ts index 8ed220e5af..8a501d134e 100644 --- a/src/content/popup/metadata.test.ts +++ b/src/content/popup/metadata.test.ts @@ -8,31 +8,26 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; let locale: 'en' | 'ja' | 'zh_CN' = 'en'; -vi.mock('webextension-polyfill', async () => { +vi.mock('../../common/i18n', async () => { const { mockGetMessage } = await import('./mock-get-message'); return { - default: { - i18n: { - getMessage: (id: string, replacements?: string | Array) => + useLocale: () => { + return { + t: (id: string, replacements?: string | Array) => mockGetMessage(locale, id, replacements), - }, + langTag: locale, + }; }, }; }); import { ShogiMeta } from '../shogi'; -import { clearLangTagCache } from './lang-tag'; import { renderMetadata } from './metadata'; -function setLocale(localeToSet: 'en' | 'ja' | 'zh_CN') { - locale = localeToSet; - clearLangTagCache(); -} - describe('renderShogiInfo', () => { afterEach(() => { - setLocale('en'); + locale = 'en'; }); it('renders a shogi move with a piece and destination', () => { @@ -198,18 +193,19 @@ function getShogiMove( const prevLocale = locale; if (localeToUse) { - setLocale(localeToUse); + locale = localeToUse; } let result = - renderMetadata(params)?.querySelector('.value')?.textContent ?? undefined; + renderMetadata(params)?.querySelector('#shogi-move')?.textContent ?? + undefined; // Drop any zero-width spaces since we only add them for Safari's sake and // they're not expected to affect the visual result result = result?.replace(/\u200b/g, ''); if (prevLocale !== localeToUse) { - setLocale(prevLocale); + locale = prevLocale; } return result;