Skip to content

Commit

Permalink
some minor contortions to get us back to 100% coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine committed Jan 15, 2025
1 parent 0bd9214 commit 572ea6e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,10 @@ var Idiomorph = (function () {
* @returns {number}
*/
function getIdIntersectionCount(oldNode, newNode, ctx) {
let oldSet = ctx.idMap.get(oldNode) || EMPTY_SET;
let newSet = ctx.idMap.get(newNode) || EMPTY_SET;
let oldSet = ctx.idMap.get(oldNode);
let newSet = ctx.idMap.get(newNode);

if(!newSet || !oldSet) return 0

let matchCount = 0;
for (const id of oldSet) {
Expand Down
30 changes: 30 additions & 0 deletions test/retain-hidden-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,36 @@ describe("Hidden state preservation tests", function () {
states.should.eql([true, true]);
});

it("preserves all non-attribute element state and innerHTML morphStyle when morphing to two top level nodes with nesting", function () {
getWorkArea().innerHTML = `
<div>
<input type="checkbox" id="first">
</div>
<div></div><!-- here just to trigger for 100% code coverage getIdInterSectionCount -->
<div>
<input type="checkbox" id="second">
</div>
`;
document.getElementById("first").indeterminate = true;
document.getElementById("second").indeterminate = true;

let finalSrc = `
<div>
<input type="checkbox" id="second">
</div>
<div>
<input type="checkbox" id="first">
</div>
`;
Idiomorph.morph(getWorkArea(), finalSrc, { morphStyle: "innerHTML" });

getWorkArea().innerHTML.should.equal(finalSrc);
const states = Array.from(getWorkArea().querySelectorAll("input")).map(
(e) => e.indeterminate,
);
states.should.eql([true, true]);
});

it("preserves all non-attribute element state when wrapping element changes tag", function () {
// just changing the type from div to span of the wrapper causes softmatch to fail so it abandons all hope
// of morphing and just inserts the node so we need to check this still handles preserving state here.
Expand Down

0 comments on commit 572ea6e

Please sign in to comment.