From 5c30003abb40f1b91fa2340ab6b40a07ea3bb8d2 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:21:46 +0200 Subject: [PATCH] load languages appropriately in tests --- .../localization-api/localize.controller.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/libs/localization-api/localize.controller.test.ts b/src/Umbraco.Web.UI.Client/src/libs/localization-api/localize.controller.test.ts index 0f23d801e0..71d158851b 100644 --- a/src/Umbraco.Web.UI.Client/src/libs/localization-api/localize.controller.test.ts +++ b/src/Umbraco.Web.UI.Client/src/libs/localization-api/localize.controller.test.ts @@ -4,6 +4,7 @@ import { UmbTranslationRegistry } from './registry/translation.registry.js'; import { customElement, property } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; + @customElement('umb-localize-controller-host') class UmbLocalizeControllerHostElement extends UmbLitElement { @property() @@ -59,12 +60,11 @@ describe('UmbLocalizeController', () => { const registry = new UmbTranslationRegistry(umbExtensionsRegistry); umbExtensionsRegistry.register(english); umbExtensionsRegistry.register(danish); - registry.loadLanguage(english.meta.culture); - registry.loadLanguage(danish.meta.culture); let element: UmbLocalizeControllerHostElement; beforeEach(async () => { + registry.loadLanguage(english.meta.culture); element = await fixture(html``); }); @@ -78,7 +78,11 @@ describe('UmbLocalizeController', () => { it('should update the term when the language changes', async () => { expect(element.localize.term('general_close')).to.equal('Close'); + // Load Danish + registry.loadLanguage(danish.meta.culture); + // Switch browser to Danish element.lang = danish.meta.culture; + await elementUpdated(element); expect(element.localize.term('general_close')).to.equal('Luk'); }); @@ -91,15 +95,20 @@ describe('UmbLocalizeController', () => { }); it('should provide a fallback term when the term is not found', async () => { + // Load Danish + registry.loadLanguage(danish.meta.culture); + // Switch browser to Danish element.lang = danish.meta.culture; await elementUpdated(element); expect(element.localize.term('general_close')).to.equal('Luk'); expect(element.localize.term('general_logout')).to.equal('Log out'); }); - it('should override a term', async () => { + it('should override a term if new extension is registered', async () => { umbExtensionsRegistry.register(englishOverride); + // Let the registry load the new extension await aTimeout(0); + await elementUpdated(element); expect(element.localize.term('general_close')).to.equal('Close 2'); }); });