-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from foretagsplatsen/40698660/Make_asJquery_w…
…ork_within_a_shadow_DOM 40698660: Make asJquery() work within a shadow DOM
- Loading branch information
Showing
4 changed files
with
141 additions
and
44 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,58 @@ | ||
import { beforeEach, describe, expect, it } from "vitest"; | ||
import htmlCanvas from "../htmlCanvas.js"; | ||
import jQuery from "jquery"; | ||
import Widget2 from "../Widget2.js"; | ||
|
||
describe("Widget", () => { | ||
beforeEach(() => { | ||
document.body.replaceChildren(); | ||
}); | ||
|
||
describe("isRendered()", () => { | ||
it("returns false if the widget isn't attached to the DOM", () => { | ||
const widget = makeWidget(); | ||
|
||
expect(widget.isRendered()).toBeFalsy(); | ||
}); | ||
|
||
it("returns true if the widget is attached to the DOM", () => { | ||
const widget = makeWidget(); | ||
|
||
makeHtml().render(widget); | ||
|
||
expect(widget.isRendered()).toBeTruthy(); | ||
}); | ||
|
||
it("returns true if the widget is attached to the DOM under a special shadow host", () => { | ||
const host = document.createElement("div"); | ||
host.setAttribute("widgetjs-shadow", "document"); | ||
|
||
document.body.appendChild(host); | ||
|
||
const shadowRoot = host.attachShadow({ mode: "open" }); | ||
|
||
const widget = makeWidget(); | ||
|
||
htmlCanvas(jQuery(shadowRoot)).render(widget); | ||
|
||
expect(widget.isRendered()).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
|
||
function makeWidget() { | ||
class Foo extends Widget2 { | ||
renderContentOn(html) { | ||
html.p("content"); | ||
} | ||
} | ||
|
||
return new Foo(); | ||
} | ||
|
||
function makeHtml() { | ||
jQuery("BODY").append('<div id="sandbox"></div>'); | ||
const sandbox = jQuery("#sandbox"); | ||
|
||
return htmlCanvas(sandbox); | ||
} |
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