From 3485dde961101bcc332254f114f9435657d482d1 Mon Sep 17 00:00:00 2001 From: MichaelWest22 Date: Thu, 9 Jan 2025 01:49:09 +1300 Subject: [PATCH] Improve test coverage --- test/head.js | 20 +++++++++++++++++--- test/htmx-integration.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/test/head.js b/test/head.js index 64e87e9..4156c30 100644 --- a/test/head.js +++ b/test/head.js @@ -193,13 +193,27 @@ describe("Tests to ensure that the head tag merging works correctly", function ( ); }); - it("can handle scripts with block mode", async function () { + it("can handle scripts with block mode with innerHTML morph", async function () { Idiomorph.morph( window.document, - ``, - { head: { block: true, style: "append" } }, + `${window.document.body.outerHTML}`, + { morphStyle: "innerHTML", head: { block: true, style: "append" } }, ); await waitFor(() => window.hasOwnProperty("fixture")); window.fixture.should.equal("FIXTURE"); + delete(window.fixture); + window.document.head.querySelector('script[src="/test/lib/fixture.js"]').remove(); + }); + + it("can handle scripts with block mode with outerHTML morph", async function () { + Idiomorph.morph( + window.document, + `${window.document.body.outerHTML}`, + { morphStyle: "outerHTML", head: { block: true, style: "append" } }, + ); + await waitFor(() => window.hasOwnProperty("fixture")); + window.fixture.should.equal("FIXTURE"); + delete(window.fixture); + window.document.head.querySelector('script[src="/test/lib/fixture.js"]').remove(); }); }); diff --git a/test/htmx-integration.js b/test/htmx-integration.js index fc3572e..eb5b8fe 100644 --- a/test/htmx-integration.js +++ b/test/htmx-integration.js @@ -147,4 +147,40 @@ describe("Tests for the htmx integration", function () { initialBtn.should.equal(newBtn); initialBtn.classList.contains("bar").should.equal(true); }); + + it("keeps the element stable in an outer morph with oob-swap", function () { + this.server.respondWith( + "GET", + "/test", + "", + ); + let div = makeForHtmxTest( + "
", + ); + let initialBtn = document.getElementById("b1"); + div.click(); + this.server.respond(); + let newBtn = document.getElementById("b1"); + initialBtn.should.equal(newBtn); + initialBtn.innerHTML.should.equal("Bar"); + }); + + /* Currently unable to test innerHTML style oob swaps because oob-swap syntax uses a : which conflicts with morph:innerHTML + it("keeps the element stable in an inner morph with oob-swap", function () { + this.server.respondWith( + "GET", + "/test", + "
", + ); + let div = makeForHtmxTest( + "
", + ); + let initialBtn = document.getElementById("b1"); + div.click(); + this.server.respond(); + let newBtn = document.getElementById("b1"); + initialBtn.should.equal(newBtn); + initialBtn.innerHTML.should.equal("Bar"); + }); + */ });