forked from basecamp/trix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for CSP-
<style>
integration
Follow-up to [basecamp#1151][]. Add unit test coverage for the `installDefaultCSSForTagName` functions support for both `meta[content]` and `meta[nonce]` attribute support. [basecamp#1151]: basecamp#1151
- Loading branch information
1 parent
d34ebea
commit e6cbae4
Showing
2 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { assert, test, testGroup } from "test/test_helper" | ||
import { installDefaultCSSForTagName, makeElement } from "trix/core/helpers" | ||
|
||
let meta = null | ||
|
||
const insertMeta = (attributes) => { | ||
meta = makeElement("meta", attributes) | ||
document.head.append(meta) | ||
} | ||
|
||
const installDefaultCSS = (tagName, css) => { | ||
installDefaultCSSForTagName(tagName, css) | ||
|
||
return document.querySelector(`style[data-tag-name=${tagName}]`) | ||
} | ||
|
||
const teardown = () => meta.remove() | ||
|
||
testGroup("Helpers: Custom Elements", { teardown }, () => { | ||
test("reads from meta[name=csp-nonce][content]", () => { | ||
insertMeta({ name: "csp-nonce", content: "abc123" }) | ||
|
||
const style = installDefaultCSS("trix-element", "trix-element { display: block; }") | ||
|
||
assert.equal(style.getAttribute("nonce"), "abc123") | ||
assert.equal(style.innerHTML, "trix-element { display: block; }") | ||
}) | ||
|
||
test("reads from meta[name=trix-csp-nonce][content]", () => { | ||
insertMeta({ name: "trix-csp-nonce", content: "abc123" }) | ||
|
||
const style = installDefaultCSS("trix-element", "trix-element { display: block; }") | ||
|
||
assert.equal(style.getAttribute("nonce"), "abc123") | ||
assert.equal(style.innerHTML, "trix-element { display: block; }") | ||
}) | ||
|
||
test("reads from meta[name=csp-nonce][nonce]", () => { | ||
insertMeta({ name: "csp-nonce", nonce: "abc123" }) | ||
|
||
const style = installDefaultCSS("trix-element", "trix-element { display: block; }") | ||
|
||
assert.equal(style.getAttribute("nonce"), "abc123") | ||
assert.equal(style.innerHTML, "trix-element { display: block; }") | ||
}) | ||
|
||
test("reads from meta[name=trix-csp-nonce][nonce]", () => { | ||
insertMeta({ name: "trix-csp-nonce", nonce: "abc123" }) | ||
|
||
const style = installDefaultCSS("trix-element", "trix-element { display: block; }") | ||
|
||
assert.equal(style.getAttribute("nonce"), "abc123") | ||
assert.equal(style.innerHTML, "trix-element { display: block; }") | ||
}) | ||
}) |