-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d8774
commit f7dfa84
Showing
1 changed file
with
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {modifyRoot} from "phoenix_live_view/rendered" | ||
|
||
describe("modifyRoot stripping comments", () => { | ||
test("starting comments", () => { | ||
// starting comments | ||
let html = ` | ||
<!-- start --> | ||
<!-- start2 --> | ||
<div class="px-5"><!-- MENU --><div id="menu">MENU</div></div> | ||
` | ||
let [strippedHTML, commentBefore, commentAfter] = modifyRoot(html, {}) | ||
expect(strippedHTML).toEqual("<div class=\"px-5\"><!-- MENU --><div id=\"menu\">MENU</div></div>") | ||
expect(commentBefore).toEqual(`<!-- start --> | ||
<!-- start2 -->`) | ||
expect(commentAfter).toEqual(null) | ||
}) | ||
|
||
test("ending comments", () => { | ||
let html = ` | ||
<div class="px-5"><!-- MENU --><div id="menu">MENU</div></div> | ||
<!-- ending --> | ||
` | ||
let [strippedHTML, commentBefore, commentAfter] = modifyRoot(html, {}) | ||
expect(strippedHTML).toEqual("<div class=\"px-5\"><!-- MENU --><div id=\"menu\">MENU</div></div>") | ||
expect(commentBefore).toEqual(null) | ||
expect(commentAfter).toEqual("<!-- ending -->") | ||
}) | ||
|
||
test("staring and ending comments", () => { | ||
let html = ` | ||
<!-- starting --> | ||
<div class="px-5"><!-- MENU --><div id="menu">MENU</div></div> | ||
<!-- ending --> | ||
` | ||
let [strippedHTML, commentBefore, commentAfter] = modifyRoot(html, {}) | ||
expect(strippedHTML).toEqual("<div class=\"px-5\"><!-- MENU --><div id=\"menu\">MENU</div></div>") | ||
expect(commentBefore).toEqual(`<!-- starting -->`) | ||
expect(commentAfter).toEqual(`<!-- ending -->`) | ||
}) | ||
describe("modifyRoot attrs", () => { | ||
test("merges new attrs", () => { | ||
let html = ` | ||
<div class="px-5"><div id="menu">MENU</div></div> | ||
` | ||
expect(modifyRoot(html, {id: 123})[0]).toEqual(`<div class="px-5" id="123"><div id="menu">MENU</div></div>`) | ||
expect(modifyRoot(html, {id: 123, class: ""})[0]).toEqual(`<div class="px-5" id="123"><div id="menu">MENU</div></div>`) | ||
expect(modifyRoot(html, {id: 123, another: ""})[0]).toEqual(`<div class="px-5" id="123" another=""><div id="menu">MENU</div></div>`) | ||
// clearing innerHTML | ||
expect(modifyRoot(html, {id: 123, another: ""}, "")[0]).toEqual(`<div class="px-5" id="123" another=""></div>`) | ||
// self closing | ||
let selfClose = ` | ||
<input class="px-5"/> | ||
` | ||
expect(modifyRoot(selfClose, {id: 123, another: ""})[0]).toEqual(`<input class="px-5" id="123" another=""/>`) | ||
}) | ||
}) | ||
}) |