From 4107117efb9a4d5caed1f419eed8c24b39724fd2 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Fri, 30 Aug 2024 13:27:48 +0100 Subject: [PATCH] Trying to add a test to show that a late registered extension works - but test says otherwise compared to using it in entrypoint --- .../registry/extension.registry.test.ts | 46 ++++++++++++++++++- .../packages/property-editors/entry-point.ts | 20 +++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/libs/extension-api/registry/extension.registry.test.ts b/src/Umbraco.Web.UI.Client/src/libs/extension-api/registry/extension.registry.test.ts index e089f1bd17..b38fdac8b2 100644 --- a/src/Umbraco.Web.UI.Client/src/libs/extension-api/registry/extension.registry.test.ts +++ b/src/Umbraco.Web.UI.Client/src/libs/extension-api/registry/extension.registry.test.ts @@ -483,7 +483,7 @@ describe('Append Conditions', () => { type: 'section', name: 'test-section-2', alias: 'Umb.Test.Section.2', - weight: 200 + weight: 200, }, ]; @@ -661,4 +661,48 @@ describe('Prepend Conditions', () => { expect(extUpdated.conditions?.[1]?.alias).to.equal('Umb.Test.Condition.Invalid'); expect(extUpdated.conditions?.[2]?.alias).to.equal('Umb.Test.Condition.Valid'); }); + + it('allows conditions to be prepended when an extension is loaded later on', async () => { + const conditions: Array = [ + { + alias: 'Umb.Test.Condition.Invalid', + }, + { + alias: 'Umb.Condition.WorkspaceAlias', + match: 'Umb.Workspace.Document', + } as WorkspaceAliasConditionConfig, + ]; + + console.log('About to go KABOOM..'); + + // Prepend the conditions + // [WB] HELP: Why is this fine when using in in an entrypoint + // /src/packages/property-editors/entry-point.ts + // But this TEST implodes if it can't find the extension that is not yet registered + await extensionRegistry.prependConditions('Late.Extension.To.Be.Loaded', conditions); + + // Make sure the extension is not registered YET + expect(extensionRegistry.isRegistered('Late.Extension.To.Be.Loaded')).to.be.false; + + // Register the extension LATE/after the conditions have been added + extensionRegistry.register({ + type: 'section', + name: 'Late Section Extension with one condition', + alias: 'Late.Extension.To.Be.Loaded', + weight: 200, + conditions: [ + { + alias: 'Umb.Test.Condition.Valid', + }, + ], + }); + + expect(extensionRegistry.isRegistered('Late.Extension.To.Be.Loaded')).to.be.true; + + const extUpdated = extensionRegistry.getByAlias('Late.Extension.To.Be.Loaded') as ManifestWithDynamicConditions; + expect(extUpdated.conditions?.length).to.equal(3); + expect(extUpdated.conditions?.[0]?.alias).to.equal('Umb.Condition.WorkspaceAlias'); + expect(extUpdated.conditions?.[1]?.alias).to.equal('Umb.Test.Condition.Invalid'); + expect(extUpdated.conditions?.[2]?.alias).to.equal('Umb.Test.Condition.Valid'); + }); }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/property-editors/entry-point.ts b/src/Umbraco.Web.UI.Client/src/packages/property-editors/entry-point.ts index baafe2af43..64d64bc9c4 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/property-editors/entry-point.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/property-editors/entry-point.ts @@ -1,4 +1,8 @@ -import type { ManifestWithDynamicConditions, UmbConditionConfigBase, UmbEntryPointOnInit } from '@umbraco-cms/backoffice/extension-api'; +import type { + ManifestWithDynamicConditions, + UmbConditionConfigBase, + UmbEntryPointOnInit, +} from '@umbraco-cms/backoffice/extension-api'; import type { WorkspaceAliasConditionConfig } from '@umbraco-cms/backoffice/workspace'; import './checkbox-list/components/index.js'; @@ -13,9 +17,16 @@ export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => { match: 'Umb.Workspace.WARRENYO', } as WorkspaceAliasConditionConfig; + console.log( + 'Should not be false and not registered', + _extensionRegistry.isRegistered('Umb.Dashboard.UmbracoNewsLATE'), + ); + _extensionRegistry.appendCondition('Umb.Dashboard.UmbracoNewsLATE', condition); - const ext:ManifestWithDynamicConditions = { + console.log('I HAZ APPENED CONDITIONS'); + + const ext: ManifestWithDynamicConditions = { alias: 'Umb.Dashboard.UmbracoNewsLATE', type: 'dashboard', name: 'WARREN Package', @@ -30,4 +41,9 @@ export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => { _extensionRegistry.register(ext); + const amIRegistered = _extensionRegistry.isRegistered('Umb.Dashboard.UmbracoNewsLATE'); + console.log('Should be true and registered', amIRegistered); + + const getTheThing = _extensionRegistry.getByAlias('Umb.Dashboard.UmbracoNewsLATE'); + console.log('Should be the extension', getTheThing); };