From 59bb5f4b7e827f67f2b9939536488909db6160f7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 15:56:03 +0200 Subject: [PATCH] test extension order --- .../registry/extension.registry.test.ts | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts index 207d740bb7..ae6f221a46 100644 --- a/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts @@ -13,6 +13,7 @@ describe('UmbContextRequestEvent', () => { type: 'section', name: 'test-section-1', alias: 'Umb.Test.Section.1', + weight: 1, meta: { label: 'Test Section 1', pathname: 'test-section-1', @@ -22,11 +23,22 @@ describe('UmbContextRequestEvent', () => { type: 'section', name: 'test-section-2', alias: 'Umb.Test.Section.2', + weight: 200, meta: { label: 'Test Section 2', pathname: 'test-section-2', }, }, + { + type: 'section', + name: 'test-section-3', + alias: 'Umb.Test.Section.3', + weight: 25, + meta: { + label: 'Test Section 3', + pathname: 'test-section-3', + }, + }, { type: 'editor', name: 'test-editor-1', @@ -42,7 +54,7 @@ describe('UmbContextRequestEvent', () => { it('should register an extension', () => { const registeredExtensions = extensionRegistry['_extensions'].getValue(); - expect(registeredExtensions).to.have.lengthOf(3); + expect(registeredExtensions).to.have.lengthOf(4); expect(registeredExtensions?.[0]?.name).to.eq('test-section-1'); }); @@ -54,13 +66,25 @@ describe('UmbContextRequestEvent', () => { }); }); - it('should get all extensions by type', (done) => { + describe('getByType', () => { const type = 'section'; - extensionRegistry.extensionsOfType(type).subscribe((extensions) => { - expect(extensions).to.have.lengthOf(2); - expect(extensions?.[0]?.type).to.eq('section'); - expect(extensions?.[1]?.type).to.eq('section'); - done(); + + it('should get all extensions by type', (done) => { + extensionRegistry.extensionsOfType(type).subscribe((extensions) => { + expect(extensions).to.have.lengthOf(3); + expect(extensions?.[0]?.type).to.eq(type); + expect(extensions?.[1]?.type).to.eq(type); + done(); + }); + }); + + it('should return extensions ordered by weight', (done) => { + extensionRegistry.extensionsOfType(type).subscribe((extensions) => { + expect(extensions?.[0]?.weight).to.eq(200); + expect(extensions?.[1]?.weight).to.eq(25); + expect(extensions?.[2]?.weight).to.eq(1); + done(); + }); }); }); });