Skip to content

Commit

Permalink
plug a hole in test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine committed Dec 25, 2024
1 parent 8dc5d27 commit 6efe380
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/two-pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,39 @@ describe("Two-pass option for retaining more state", function () {
states.should.eql([true, true]);
});

it("preserves focus state when focused element is moved", function () {
getWorkArea().innerHTML = `
<div>
<input type="text" id="first">
</div>
<div>
<input type="text" id="second">
</div>
`;
document.getElementById("second").focus();

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

getWorkArea().innerHTML.should.equal(finalSrc);
if (document.body.moveBefore) {
document.activeElement.outerHTML.should.equal(
document.getElementById("second").outerHTML,
);
} else {
document.activeElement.outerHTML.should.equal(document.body.outerHTML);
console.log(
"preserves focus state when focused element is moved needs moveBefore enabled to work properly",
);
}
});


it("preserves focus state with two-pass option and outerHTML morphStyle", function () {
const div = make(`
<div>
Expand Down

0 comments on commit 6efe380

Please sign in to comment.