From 27dcf78c960d007932b0863f90cdd4fd94a32920 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 25 May 2022 16:14:51 +0200 Subject: [PATCH 1/3] add essential icon registry --- src/Umbraco.Web.UI.Client/src/app.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/app.ts b/src/Umbraco.Web.UI.Client/src/app.ts index bf7b86de04..428e9cd8b8 100644 --- a/src/Umbraco.Web.UI.Client/src/app.ts +++ b/src/Umbraco.Web.UI.Client/src/app.ts @@ -1,4 +1,4 @@ -import '@umbraco-ui/uui'; +import { UUIIconRegistryEssential } from '@umbraco-ui/uui'; import '@umbraco-ui/uui-css/dist/uui-css.css'; // TODO: lazy load these @@ -48,6 +48,8 @@ export class UmbApp extends UmbContextProviderMixin(LitElement) { } `; + private _iconRegistry: UUIIconRegistryEssential = new UUIIconRegistryEssential(); + private _isInstalled = false; private _view?: HTMLElement; @@ -57,10 +59,8 @@ export class UmbApp extends UmbContextProviderMixin(LitElement) { constructor() { super(); this.addEventListener(umbRouterBeforeEnterEventType, this._onBeforeEnter); - } + this._iconRegistry.attach(this); - connectedCallback(): void { - super.connectedCallback(); const { extensionRegistry } = window.Umbraco; this.provideContext('umbExtensionRegistry', window.Umbraco.extensionRegistry); From b02ef6013197076914ee021b4353cd51b521aeee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 25 May 2022 16:15:31 +0200 Subject: [PATCH 2/3] adjusted context api tests --- .../src/core/context/context-consumer.test.ts | 15 +++++++++------ .../src/core/context/context-consumer.ts | 6 +++--- .../core/context/context-provide.event.test.ts | 4 ++-- .../src/core/context/context-provider.test.ts | 7 +++++-- .../src/core/context/context-provider.ts | 10 +++++----- .../core/context/context-request.event.test.ts | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts index 0aa28485c9..becefcd15a 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts @@ -19,16 +19,17 @@ describe('UmbContextConsumer', () => { describe('Public API', () => { describe('methods', () => { - it('has a dispatchRequest method', () => { - expect(consumer).to.have.property('dispatchRequest').that.is.a('function'); + it('has a request method', () => { + expect(consumer).to.have.property('request').that.is.a('function'); }); }); describe('events', () => { it('dispatches request context event when constructed', async () => { const listener = oneEvent(window, umbContextRequestEventType); - // eslint-disable-next-line @typescript-eslint/no-empty-function - new UmbContextConsumer(document.body, testContextKey, () => {}); + + consumer.attach(); + const event = await listener as unknown as UmbContextRequestEventImplementation; expect(event).to.exist; expect(event.type).to.eq(umbContextRequestEventType); @@ -39,14 +40,16 @@ describe('UmbContextConsumer', () => { it('works with UmbContextProvider', (done: any) => { const provider = new UmbContextProvider(document.body, testContextKey, new MyClass()); + provider.attach(); const element = document.createElement('div'); document.body.appendChild(element); - new UmbContextConsumer(element, testContextKey, (_instance) => { + const localConsumer = new UmbContextConsumer(element, testContextKey, (_instance) => { expect(_instance.prop).to.eq('value from provider'); done(); - }); + }) + localConsumer.attach(); provider.detach(); }); diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.ts index 877af11028..6e16eff06b 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.ts @@ -9,13 +9,13 @@ export class UmbContextConsumer { /** * Creates an instance of UmbContextConsumer. - * @param {HTMLElement} element + * @param {EventTarget} target * @param {string} _contextKey * @param {UmbContextCallback} _callback * @memberof UmbContextConsumer */ constructor ( - protected element: HTMLElement, + protected target: EventTarget, private _contextKey: string, private _callback: UmbContextCallback ) { @@ -27,7 +27,7 @@ export class UmbContextConsumer { */ public request() { const event = new UmbContextRequestEventImplementation(this._contextKey, this._callback); - this.element.dispatchEvent(event); + this.target.dispatchEvent(event); } public attach() { diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-provide.event.test.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-provide.event.test.ts index 402a06670b..67c04c81e7 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-provide.event.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-provide.event.test.ts @@ -17,7 +17,7 @@ describe('UmbContextProvideEvent', () => { expect(event.composed).to.be.true; }); - it('is cancelable', () => { - expect(event.composed).to.be.false; + it('is not cancelable', () => { + expect(event.cancelable).to.be.false; }); }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-provider.test.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-provider.test.ts index 24c25cb050..5899817f91 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-provider.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-provider.test.ts @@ -12,6 +12,7 @@ describe('UmbContextProvider', () => { beforeEach(() => { provider = new UmbContextProvider(document.body, 'my-test-context', new MyClass()); + provider.attach(); }); afterEach(async () => { @@ -38,7 +39,7 @@ describe('UmbContextProvider', () => { }); it('handles context request events', (done) => { - const event = new UmbContextRequestEventImplementation('my-test-context', (_instance) => { + const event = new UmbContextRequestEventImplementation('my-test-context', (_instance: MyClass) => { expect(_instance.prop).to.eq('value from provider'); done(); }); @@ -50,9 +51,11 @@ describe('UmbContextProvider', () => { const element = document.createElement('div'); document.body.appendChild(element); - new UmbContextConsumer(element, 'my-test-context', (_instance) => { + const localConsumer = new UmbContextConsumer(element, 'my-test-context', (_instance: MyClass) => { expect(_instance.prop).to.eq('value from provider'); done(); + localConsumer.detach(); }); + localConsumer.attach(); }); }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-provider.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-provider.ts index a2118711c1..346deb313b 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-provider.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-provider.ts @@ -6,18 +6,18 @@ import { UmbContextProvideEventImplementation } from './context-provide.event'; * @class UmbContextProvider */ export class UmbContextProvider { - protected host: HTMLElement; + protected host: EventTarget; private _contextKey: string; - private _instance: any; + private _instance: unknown; /** * Creates an instance of UmbContextProvider. - * @param {HTMLElement} host + * @param {EventTarget} host * @param {string} contextKey * @param {*} instance * @memberof UmbContextProvider */ - constructor (host: HTMLElement, contextKey: string, instance: unknown) { + constructor (host: EventTarget, contextKey: string, instance: unknown) { this.host = host; this._contextKey = contextKey; this._instance = instance; @@ -36,7 +36,7 @@ export class UmbContextProvider { */ public detach () { this.host.removeEventListener(umbContextRequestEventType, this._handleContextRequest); - // TODO: fire unprovide event. + // TODO: fire unprovided event. } /** diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-request.event.test.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-request.event.test.ts index 68eb9780bc..f10e1ff88c 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-request.event.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-request.event.test.ts @@ -25,6 +25,6 @@ describe('UmbContextRequestEvent', () => { }); it('is cancelable', () => { - expect(event.composed).to.be.true; + expect(event.cancelable).to.be.true; }); }); \ No newline at end of file From 1f9460e94a6db661865d7b073c76ccc08bad7772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 25 May 2022 16:16:32 +0200 Subject: [PATCH 3/3] tets name --- .../src/core/context/context-consumer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts b/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts index becefcd15a..3a20144a2e 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context/context-consumer.test.ts @@ -25,7 +25,7 @@ describe('UmbContextConsumer', () => { }); describe('events', () => { - it('dispatches request context event when constructed', async () => { + it('dispatches context request event when constructed', async () => { const listener = oneEvent(window, umbContextRequestEventType); consumer.attach();