fix: the private key export screen opens again in the same session (closes #460)
show() found the address line through the element inside it, then replaced the line's contents with renderAddressHtml(), which deleted that element, so the next show() in the same popup session threw before it navigated. The line now carries the export-privkey-address id itself and is looked up by it. No other view that renders an address finds its container through a child. The jest DOM stub now takes an element out of the document when its parent's contents are replaced, and a new test opens the screen twice. The #253 e2e case no longer reopens the popup before its second open. Model: opus-5-5
This commit was merged in pull request #478.
This commit is contained in:
@@ -58,7 +58,20 @@ function makeElement(id, withParent) {
|
||||
remove: () => {},
|
||||
querySelectorAll: () => [],
|
||||
};
|
||||
el.parentElement = withParent ? makeElement(id + "-parent", false) : null;
|
||||
el.parentElement = null;
|
||||
if (withParent) {
|
||||
// As in a browser, replacing the parent's contents takes this
|
||||
// element out of the document: getElementById no longer finds it.
|
||||
el.parentElement = makeElement(id + "-parent", false);
|
||||
let html = "";
|
||||
Object.defineProperty(el.parentElement, "innerHTML", {
|
||||
get: () => html,
|
||||
set: (value) => {
|
||||
html = value;
|
||||
el.removed = true;
|
||||
},
|
||||
});
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
@@ -70,7 +83,8 @@ function makeDocument() {
|
||||
// is the state a non-debug, non-testnet popup is in.
|
||||
if (id === "debug-banner") return null;
|
||||
if (!els.has(id)) els.set(id, makeElement(id, true));
|
||||
return els.get(id);
|
||||
const el = els.get(id);
|
||||
return el.removed ? null : el;
|
||||
},
|
||||
createElement: () => makeElement("created", false),
|
||||
addEventListener: () => {},
|
||||
@@ -300,6 +314,28 @@ describe("leaving the screen after the key is on it", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("opening the screen again in the same popup session", () => {
|
||||
// https://git.eeqj.de/sneak/AutistMask/issues/460: show() found the
|
||||
// address line through an element inside it, which its own rendering
|
||||
// deleted, so the second open threw before it navigated.
|
||||
test("shows it for the address chosen the second time", async () => {
|
||||
const { state, exportPrivkey } = load();
|
||||
exportPrivkey.show(0, 0);
|
||||
await click("btn-export-privkey-back");
|
||||
expect(state.currentView).toBe("address");
|
||||
|
||||
exportPrivkey.show(0, 1);
|
||||
|
||||
expect(state.currentView).toBe(VIEW);
|
||||
expect(node("export-privkey-title").textContent).toBe(
|
||||
"Wallet 1 — Address 2",
|
||||
);
|
||||
expect(node("export-privkey-address").innerHTML).toContain(
|
||||
"0x" + "22".repeat(20),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("views the popup may reopen onto", () => {
|
||||
// Restoring onto this screen would put a private key on display with no
|
||||
// password prompt in front of it, on a popup reopened by accident.
|
||||
|
||||
Reference in New Issue
Block a user