From fc6c76bccb9322485a86a5ffe08ca3a77c30e95c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Sun, 7 Apr 2024 15:31:07 +0200 Subject: [PATCH] add tests to entity context --- .../core/entity/entity.context.test.ts | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts new file mode 100644 index 0000000000..e01e1937b0 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts @@ -0,0 +1,77 @@ +import { expect } from '@open-wc/testing'; +import { UmbEntityContext } from './entity.context.js'; +import { UMB_ENTITY_CONTEXT } from './entity.context-token.js'; +import { Observable } from '@umbraco-cms/backoffice/external/rxjs'; +import { customElement } from '@umbraco-cms/backoffice/external/lit'; +import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'; + +@customElement('umb-test-host') +export class UmbTestHostElement extends UmbElementMixin(HTMLElement) {} + +@customElement('umb-test-child') +export class UmbTestChildElement extends UmbElementMixin(HTMLElement) {} + +describe('UmbEntityContext', () => { + let context: UmbEntityContext; + let host: UmbTestHostElement; + let child: UmbTestChildElement; + + beforeEach(() => { + host = new UmbTestHostElement(); + child = new UmbTestChildElement(); + host.appendChild(child); + document.body.appendChild(host); + context = new UmbEntityContext(host); + }); + + describe('Public API', () => { + describe('properties', () => { + it('has a entity type property', () => { + expect(context).to.have.property('entityType').to.be.an.instanceOf(Observable); + }); + + it('has a unique property', () => { + expect(context).to.have.property('unique').to.be.an.instanceOf(Observable); + }); + }); + + describe('methods', () => { + it('has a getEntityType method', () => { + expect(context).to.have.property('getEntityType').that.is.a('function'); + }); + + it('has a setEntityType method', () => { + expect(context).to.have.property('setEntityType').that.is.a('function'); + }); + + it('has a getUnique method', () => { + expect(context).to.have.property('getUnique').that.is.a('function'); + }); + + it('has a setUnique method', () => { + expect(context).to.have.property('setUnique').that.is.a('function'); + }); + }); + }); + + describe('set and get entity type', () => { + it('should set entity type', () => { + context.setEntityType('entity-type'); + expect(context.getEntityType()).to.equal('entity-type'); + }); + }); + + describe('set and get unique', () => { + it('should set unique', () => { + context.setUnique('unique-value'); + expect(context.getUnique()).to.equal('unique-value'); + }); + }); + + describe('it is provided as a context', () => { + it('should be provided as a context', async () => { + const providedContext = await child.getContext(UMB_ENTITY_CONTEXT); + expect(providedContext).to.equal(context); + }); + }); +});