From 4e442b769bd3e61065cc32df2cd59cfba51fb188 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 13 Dec 2024 11:12:08 -0500 Subject: [PATCH 1/3] Add test coverage for both built-in processor strategies Existing test coverage lacked tests that exercised _both_ the default `processPropertyIdentity` strategy alongside the optional `propertyIdentityOrBooleanAttribute` strategy. This commit doesn't contain any implementation changes, but broadens test coverage instead. --- test/template-instance.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/template-instance.ts b/test/template-instance.ts index 76e691a..fac7297 100644 --- a/test/template-instance.ts +++ b/test/template-instance.ts @@ -28,14 +28,32 @@ describe('template-instance', () => { root.appendChild(instance) expect(root.innerHTML).to.equal(`
Hello world
`) }) - it('applies data to nested templated element nodes', () => { + it('applies data to nested templated element nodes with the default processPropertyIdentity', () => { const root = document.createElement('div') const template = Object.assign(document.createElement('template'), { innerHTML: '', }) - root.appendChild(new TemplateInstance(template, {x: 'Hello world'})) + const instance = new TemplateInstance(template, {x: 'Hello world'}) + root.appendChild(instance) expect(root.innerHTML).to.equal('') + expect(template.innerHTML).to.equal('') + instance.update({x: 'Goodbye world'}) + expect(root.innerHTML).to.equal('') + expect(template.innerHTML).to.equal('') + }) + it('applies data to nested templated element nodes with propertyIdentityOrBooleanAttribute', () => { + const template = Object.assign(document.createElement('template'), { + innerHTML: '', + }) + const instance = new TemplateInstance(template, {hidden: true}, propertyIdentityOrBooleanAttribute) + + const root = document.createElement('div') + root.appendChild(instance) + expect(root.innerHTML).to.equal('') + expect(template.innerHTML).to.equal('') + instance.update({hidden: false}) + expect(root.innerHTML).to.equal('') }) it('applies data to templated DocumentFragment nodes', () => { const template = document.createElement('template') @@ -357,7 +375,7 @@ describe('template-instance', () => { }) describe('handling InnerTemplatePart', () => { - it('makes outer state available to inner parts', () => { + it('makes outer state available to InnerTemplatePart elements with [directive]', () => { const processor = createProcessor((part, value, state) => { if (part instanceof InnerTemplatePart && part.directive === 'if') { if (typeof state === 'object' && (state as Record)[part.expression]) { From 8e8475790d7bb6d69d07449fc50965d8ebadeff7 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 13 Dec 2024 23:29:39 -0500 Subject: [PATCH 2/3] Export `InnerTemplatePart` Add an entry to the `src/index.ts` to export the new `InnerTemplatePart`. Since consumers are most likely to import `TemplateInstance`, change the `test/template-instance.ts` test file to import properties from the module in a way that more closely resembles the end-user consumer experience. --- src/index.ts | 1 + test/template-instance.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5ea3b61..176d5d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export {TemplateInstance} from './template-instance.js' export {parse} from './template-string-parser.js' export {AttributeTemplatePart, AttributeValueSetter} from './attribute-template-part.js' +export {InnerTemplatePart} from './inner-template-part.js' export {NodeTemplatePart} from './node-template-part.js' export { createProcessor, diff --git a/test/template-instance.ts b/test/template-instance.ts index 76e691a..6bea832 100644 --- a/test/template-instance.ts +++ b/test/template-instance.ts @@ -1,8 +1,12 @@ import {expect} from '@open-wc/testing' -import {TemplateInstance} from '../src/template-instance' -import {NodeTemplatePart} from '../src/node-template-part' -import {InnerTemplatePart} from '../src/inner-template-part' -import {processPropertyIdentity, propertyIdentityOrBooleanAttribute, createProcessor} from '../src/processors' +import { + TemplateInstance, + NodeTemplatePart, + InnerTemplatePart, + processPropertyIdentity, + propertyIdentityOrBooleanAttribute, + createProcessor, +} from '../src/index' describe('template-instance', () => { it('applies data to templated text nodes', () => { From b98aa52203f2fe88b3fb41e9f207a3e35c060fef Mon Sep 17 00:00:00 2001 From: Leslie Cohn-Wein Date: Fri, 10 Jan 2025 11:59:26 -0600 Subject: [PATCH 3/3] Update CODEOWNERS to Web Systems --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 68f394d..e6bf555 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @github/primer-reviewers +* @github/web-systems-reviewers