// A timer the popup started and that fires after cleanupPopup() has removed // the page throws "document is not defined", and the throw fails whatever test // the jest worker is running by then, in this file or another // (https://git.eeqj.de/sneak/AutistMask/issues/578). The flash message's // timer is the one that did it. A throw from a timer during a test fails that // test, so each test here passes only if nothing throws. const { bootPopup, cleanupPopup, unversionedValidProfile, ADDRESS, } = require("./support/popupBoot"); const FLASH_MS = 10; function wait(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } afterEach(() => { cleanupPopup(); }); test("a flash message clears while the page is up", async () => { const page = await bootPopup(unversionedValidProfile()); const { showFlash } = require("../src/popup/views/helpers"); showFlash("Copied.", FLASH_MS); expect(page.text("flash-msg")).toBe("Copied."); await wait(FLASH_MS * 5); expect(page.text("flash-msg")).toBe(""); }); test("a flash message's timer does not fire after cleanupPopup()", async () => { await bootPopup(unversionedValidProfile()); const { showFlash } = require("../src/popup/views/helpers"); showFlash("Copied.", FLASH_MS); cleanupPopup(); await wait(FLASH_MS * 5); }); // A boot onto a screen whose requests no mocked module answers: they reach the // boot's fetch() stub, never the internet // (https://git.eeqj.de/sneak/AutistMask/issues/559). function restoringOnto(view, viewData) { return unversionedValidProfile({ currentView: view, selectedWallet: 0, selectedAddress: 0, viewStack: ["main"], viewData, }); } test("the transaction screen's Blockscout request reaches the stub", async () => { const page = await bootPopup( restoringOnto("transaction", { tx: { hash: "0x1", from: ADDRESS, to: ADDRESS }, }), ); expect(page.visibleViews()).toEqual(["transaction"]); expect(globalThis.fetch.mock.calls.map((call) => call[0])).toEqual([ "https://eth.blockscout.com/api/v2/transactions/0x1", ]); }); test("the confirmation screen's Etherscan lookup reaches the stub", async () => { const page = await bootPopup( restoringOnto("confirm-tx", { pendingTx: { token: "ETH", from: ADDRESS, to: ADDRESS, amount: "1", }, }), ); expect(page.visibleViews()).toEqual(["confirm-tx"]); expect(globalThis.fetch.mock.calls.map((call) => call[0])).toEqual([ "https://etherscan.io/address/" + ADDRESS, ]); });