-
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.
config for ways to omit declarative shadow dom (
lightMode
) (#19)
* config for various ways to omit declarative shadow dom * non shadow dom styling * includeShadowRoots config spec * refactor out double getInnerHTML call * refactor to lightMode config * documentation * quick docs update
- Loading branch information
1 parent
9f12d4c
commit 71cf93f
Showing
10 changed files
with
215 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Use Case | ||
* Run wcc against nested custom elements with nested declarative shadow dom and ensure no shadow is included | ||
* | ||
* User Result | ||
* Should return the expected HTML output for all levels of element nesting. | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* navigation.js | ||
* header.js | ||
* pages/ | ||
* index.js | ||
* | ||
* Config | ||
* { | ||
* lightMode: true | ||
* } | ||
*/ | ||
|
||
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 = 'Nested Custom Element w/ no using Light Mode configuration'; | ||
let dom; | ||
|
||
before(async function() { | ||
const { html } = await renderToString(new URL('./src/pages/index.js', import.meta.url), { | ||
lightMode: true | ||
}); | ||
|
||
dom = new JSDOM(html); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
it('should not have one top level <template> with an open shadowroot', function() { | ||
expect(dom.window.document.querySelectorAll('template[shadowroot="open"]').length).to.equal(0); | ||
expect(dom.window.document.querySelectorAll('template').length).to.equal(0); | ||
}); | ||
|
||
describe('static page content', function() { | ||
it('should have the expected static content for the page', function() { | ||
expect(dom.window.document.querySelector('h1').textContent).to.equal('Home Page'); | ||
}); | ||
}); | ||
|
||
describe('custom header element with nested navigation element', function() { | ||
let headerContentsDom; | ||
|
||
before(function() { | ||
headerContentsDom = new JSDOM(dom.window.document.querySelectorAll('header')[0].innerHTML); | ||
}); | ||
|
||
it('should have a <header> tag within the <template> shadowroot', function() { | ||
expect(dom.window.document.querySelectorAll('header').length).to.equal(1); | ||
}); | ||
|
||
it('should have expected content within the <header> tag', function() { | ||
const content = headerContentsDom.window.document.querySelector('a h4').textContent; | ||
|
||
expect(content).to.contain('My Personal Blog'); | ||
}); | ||
|
||
describe('nested navigation element', function() { | ||
let navigationContentsDom; | ||
|
||
before(function() { | ||
navigationContentsDom = new JSDOM(headerContentsDom.window.document.querySelectorAll('wcc-navigation')[0].innerHTML); | ||
}); | ||
|
||
it('should have a <nav> tag within the <template> shadowroot', function() { | ||
expect(navigationContentsDom.window.document.querySelectorAll('nav').length).to.equal(1); | ||
}); | ||
|
||
it('should have three links within the <nav> element', function() { | ||
const links = navigationContentsDom.window.document.querySelectorAll('nav ul li a'); | ||
|
||
expect(links.length).to.equal(3); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,43 @@ | ||
// intentionally nested to test wcc nested dependency resolution logic | ||
import './navigation.js'; | ||
|
||
class Header extends HTMLElement { | ||
connectedCallback() { | ||
if (!this.shadowRoot) { | ||
this.attachShadow({ mode: 'open' }); | ||
this.shadowRoot.innerHTML = this.render(); | ||
} | ||
} | ||
|
||
render() { | ||
return ` | ||
<header class="header"> | ||
<div class="head-wrap"> | ||
<div class="brand"> | ||
<a href="/"> | ||
<img src="/www/assets/greenwood-logo.jpg" alt="Greenwood logo"/> | ||
<h4>My Personal Blog</h4> | ||
</a> | ||
</div> | ||
<wcc-navigation></wcc-navigation> | ||
<div class="social"> | ||
<a href="https://github.com/ProjectEvergreen/greenwood"> | ||
<img | ||
src="https://img.shields.io/github/stars/ProjectEvergreen/greenwood.svg?style=social&logo=github&label=github" | ||
alt="Greenwood GitHub badge" | ||
class="github-badge"/> | ||
</a> | ||
</div> | ||
</div> | ||
</header> | ||
`; | ||
} | ||
} | ||
|
||
export { | ||
Header | ||
}; | ||
|
||
customElements.define('wcc-header', Header); |
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 @@ | ||
// intentionally nested in the assets/ directory to test wcc nested dependency resolution logic | ||
const template = document.createElement('template'); | ||
|
||
template.innerHTML = ` | ||
<nav> | ||
<ul> | ||
<li><a href="/">Home</a></li> | ||
<li><a href="/about">About</a></li> | ||
<li><a href="/artists">Artists</a></li> | ||
<ul> | ||
</nav> | ||
`; | ||
|
||
class Navigation extends HTMLElement { | ||
connectedCallback() { | ||
if (!this.shadowRoot) { | ||
this.attachShadow({ mode: 'open' }); | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
} | ||
} | ||
} | ||
|
||
export { | ||
Navigation | ||
}; | ||
|
||
customElements.define('wcc-navigation', Navigation); |
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,25 @@ | ||
import '../components/header.js'; | ||
|
||
export default class HomePage extends HTMLElement { | ||
constructor() { | ||
super(); | ||
|
||
if (this.shadowRoot) { | ||
// console.debug('HomePage => shadowRoot detected!'); | ||
} else { | ||
this.attachShadow({ mode: 'open' }); | ||
} | ||
} | ||
|
||
connectedCallback() { | ||
this.shadowRoot.innerHTML = this.getTemplate(); | ||
} | ||
|
||
getTemplate() { | ||
return ` | ||
<wcc-header></wcc-header> | ||
<h1>Home Page</h1> | ||
`; | ||
} | ||
} |