-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug/issue 128 fix shadow root rendering for JSX (#129)
* fix shadow root rendering for JSX * output JSX DSD as a template element * JSX + DSD sandbox demo working * JSX + DSD + inferredObservability sandbox demo working * add random reset feature to counter sandbox demos * rename test to match feature being tested * refine test cases * constructor not a prerequiste for using inferredObservability anymore * runtime render refactoring * document DSD interop * misc clean and docs
- Loading branch information
1 parent
05401bd
commit 6abeca4
Showing
13 changed files
with
190 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Use Case | ||
* Run wcc against a nested custom elements using JSX render function and Declarative Shadow DOM. | ||
* | ||
* User Result | ||
* Should return the expected HTML and JavaScript output. | ||
* | ||
* User Workspace | ||
* src/ | ||
* heading.jsx | ||
*/ | ||
import chai from 'chai'; | ||
import { JSDOM } from 'jsdom'; | ||
import { renderToString } from '../../../src/wcc.js'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Run WCC For ', function() { | ||
const LABEL = 'Single Custom Element using JSX and Declarative Shadow DOM'; | ||
let dom; | ||
let meta; | ||
|
||
before(async function() { | ||
const { html, metadata } = await renderToString(new URL('./src/heading.jsx', import.meta.url)); | ||
|
||
meta = metadata; | ||
dom = new JSDOM(html); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
|
||
describe('<wcc-heading> component', function() { | ||
let heading; | ||
|
||
before(async function() { | ||
heading = dom.window.document.querySelector('wcc-heading template[shadowrootmode="open"]'); | ||
}); | ||
|
||
describe('Metadata', () => { | ||
it('should return a JSX definition in metadata', () => { | ||
expect(Object.keys(meta).length).to.equal(1); | ||
expect(meta['wcc-heading'].source).to.not.be.undefined; | ||
}); | ||
}); | ||
|
||
describe('Declarative Shadow DOM (<template> tag)', () => { | ||
it('should handle a this expression', () => { | ||
expect(heading).to.not.be.undefined; | ||
}); | ||
}); | ||
|
||
describe('Event Handling', () => { | ||
it('should handle a this expression', () => { | ||
const wrapper = new JSDOM(heading.innerHTML); | ||
const button = wrapper.window.document.querySelector('button'); | ||
|
||
expect(button.getAttribute('onclick')).to.be.equal('this.parentElement.parentNode.host.sayHello()'); | ||
}); | ||
}); | ||
|
||
describe('Attribute Contents', () => { | ||
it('should handle a this expression', () => { | ||
const wrapper = new JSDOM(heading.innerHTML); | ||
const header = wrapper.window.document.querySelector('h1'); | ||
|
||
expect(header.textContent).to.be.equal('Hello, World!'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export default class HeadingComponent extends HTMLElement { | ||
sayHello() { | ||
alert(`Hello, ${this.greeting}!`); | ||
} | ||
|
||
connectedCallback() { | ||
if (!this.shadowRoot) { | ||
this.greeting = this.getAttribute('greeting') || 'World'; | ||
|
||
this.attachShadow({ mode: 'open' }); | ||
this.render(); | ||
} | ||
} | ||
|
||
render() { | ||
const { greeting } = this; | ||
|
||
return ( | ||
<div> | ||
<h1>Hello, {greeting}!</h1> | ||
<button onclick={this.sayHello}>Get a greeting!</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
customElements.define('wcc-heading', HeadingComponent); |