123import type { JSX } from "solid-js";4import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";56import type { ImportParseResult } from "../../shared/import";7import type { VaultEntry } from "../../shared/types";8import { LockView } from "./Lock";9import { ExportView } from "./Export";10import { SettingsView } from "./Settings";11import { EntryView } from "./Entry";12import { ImportView } from "./Import";13import { VaultView } from "./Vault";14import { changeSelect, flushView, inputText, pressEnter, renderView } from "./view-test-utils";1516const sendMessageMock = vi.fn<(msg: unknown) => Promise<unknown>>();17const triggerRingMock = vi.fn();18const triggerPipPulseMock = vi.fn();19const exportEntriesToPeachJsonMock = vi.fn();20const parseImportSourceMock = vi.fn<(raw: string, password?: string) => Promise<ImportParseResult>>();21const zxcvbnMock = vi.fn((value: string) => ({ score: value.length >= 16 ? 3 : 1 }));2223vi.mock("../App", () => ({24 sendMessage: (msg: unknown) => sendMessageMock(msg),25 triggerRing: () => triggerRingMock(),26 triggerPipPulse: () => triggerPipPulseMock(),27}));2829vi.mock("../../shared/backup", () => ({30 exportEntriesToPeachJson: (...args: unknown[]) => exportEntriesToPeachJsonMock(...args),31}));3233vi.mock("../../shared/import", () => ({34 parseImportSource: (...args: [string, string | undefined]) => parseImportSourceMock(...args),35}));3637vi.mock("../../shared/favicon", () => ({38 faviconUrl: () => null,39}));4041vi.mock("../../crypto/totp", () => ({42 generateTOTP: () => ({ code: "123 456", remaining: 24 }),43 parseOtpauthURI: (value: string) =>44 value.startsWith("otpauth://")45 ? { secret: "NB2W45DFOIZA====", algorithm: "SHA1" as const }46 : null,47}));4849vi.mock("../components/GeneratorDrawer", () => ({50 GeneratorDrawer: () => null,51}));5253vi.mock("./CJKImport", () => ({54 CJKImportView: () => null,55}));5657vi.mock("./CJKExport", () => ({58 CJKExportView: () => null,59}));6061vi.mock("zxcvbn", () => ({62 default: (value: string) => zxcvbnMock(value),63}));6465describe("popup contract tests", () => {66 const disposers: Array<() => void> = [];6768 beforeEach(() => {69 document.body.innerHTML = "";70 sendMessageMock.mockReset();71 triggerRingMock.mockReset();72 triggerPipPulseMock.mockReset();73 exportEntriesToPeachJsonMock.mockReset();74 parseImportSourceMock.mockReset();75 zxcvbnMock.mockReset();76 zxcvbnMock.mockImplementation((value: string) => ({ score: value.length >= 16 ? 3 : 1 }));77 parseImportSourceMock.mockResolvedValue({78 format: "unknown",79 label: "Unknown format",80 entries: [],81 totalItems: 0,82 skippedItems: 0,83 requiresPassword: false,84 });8586 vi.stubGlobal("requestAnimationFrame", (cb: FrameRequestCallback) => {87 return window.setTimeout(() => cb(0), 0) as unknown as number;88 });89 vi.stubGlobal("cancelAnimationFrame", (id: number) => window.clearTimeout(id));90 vi.stubGlobal("URL", {91 createObjectURL: vi.fn(() => "blob:peach-test"),92 revokeObjectURL: vi.fn(),93 });94 vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => {});9596 (globalThis as { chrome?: typeof chrome }).chrome = {97 runtime: {98 getManifest: () => ({ version: "1.4.47" }),99 onMessage: { addListener: vi.fn() },100 },101 } as unknown as typeof chrome;102 });103104 afterEach(() => {105 while (disposers.length > 0) {106 disposers.pop()?.();107 }108 vi.unstubAllGlobals();109 });110111 function mount(view: JSX.Element) {112 const mounted = renderView(view);113 disposers.push(mounted.dispose);114 return mounted.container;115 }116117 function sampleEntry(overrides: Partial<VaultEntry> = {}): VaultEntry {118 return {119 id: "entry-1",120 type: "login",121 title: "GitHub",122 username: "june",123 password: "secret123",124 url: "https://github.com",125 totp: "JBSWY3DPEHPK3PXP",126 canary: {127 webhookUrl: "https://example.com/hook",128 },129 createdAt: 1,130 modifiedAt: 1,131 ...overrides,132 };133 }134135 function sampleImportResult(136 overrides: Partial<ImportParseResult> = {}137 ): ImportParseResult {138 return {139 format: "csv",140 label: "CSV import",141 entries: [142 {143 type: "login",144 title: "Imported site",145 username: "imported-user",146 password: "imported-pass",147 url: "https://imported.test",148 },149 ],150 totalItems: 1,151 skippedItems: 0,152 requiresPassword: false,153 ...overrides,154 };155 }156157 async function selectImportFile(158 container: HTMLElement,159 contents = '{"export":"test"}'160 ) {161 const input = container.querySelector('input[type="file"]') as HTMLInputElement;162 const file = new File([contents], "import.json", { type: "application/json" });163 Object.defineProperty(input, "files", {164 configurable: true,165 value: [file],166 });167 input.dispatchEvent(new Event("change", { bubbles: true }));168 await flushView();169 await flushView();170 }171172 function findButton(container: HTMLElement, text: string): HTMLButtonElement {173 return Array.from(container.querySelectorAll("button")).find(174 (candidate) => candidate.textContent?.trim() === text175 ) as HTMLButtonElement;176 }177178 it("Lock sends UNLOCK with the entered passphrase", async () => {179 sendMessageMock.mockResolvedValue({ ok: true });180 const onUnlock = vi.fn(async () => undefined);181 const container = mount(<LockView hasVault={true} ready={true} onUnlock={onUnlock} />);182183 const password = container.querySelector("#unlock-password") as HTMLInputElement;184 inputText(password, "correct horse battery staple");185 (container.querySelector(".peach-lock-submit") as HTMLButtonElement).click();186 await flushView();187188 expect(sendMessageMock).toHaveBeenCalledWith({189 type: "UNLOCK",190 payload: { password: "correct horse battery staple" },191 });192 expect(onUnlock).toHaveBeenCalled();193 });194195 it("Lock keeps create-vault disabled for short passwords and weak passphrases", async () => {196 const container = mount(<LockView hasVault={false} ready={true} onUnlock={vi.fn()} />);197 const createButton = container.querySelector(".peach-lock-submit") as HTMLButtonElement;198 const password = container.querySelector("#master-password") as HTMLInputElement;199 const confirm = container.querySelector("#confirm-password") as HTMLInputElement;200201 inputText(password, "short");202 inputText(confirm, "short");203 await flushView();204 expect(createButton.disabled).toBe(true);205206 zxcvbnMock.mockImplementation(() => ({ score: 1 }));207 inputText(password, "weakweakweak");208 inputText(confirm, "weakweakweak");209 await flushView();210 expect(createButton.disabled).toBe(true);211 });212213 it("Lock sends CREATE_VAULT when the onboarding passphrase is strong enough", async () => {214 sendMessageMock.mockResolvedValue({ ok: true });215 zxcvbnMock.mockImplementation(() => ({ score: 3 }));216 const onUnlock = vi.fn(async () => undefined);217 const container = mount(<LockView hasVault={false} ready={true} onUnlock={onUnlock} />);218219 const password = container.querySelector("#master-password") as HTMLInputElement;220 const confirm = container.querySelector("#confirm-password") as HTMLInputElement;221 const createButton = container.querySelector(".peach-lock-submit") as HTMLButtonElement;222223 inputText(password, "correct horse battery staple");224 inputText(confirm, "correct horse battery staple");225 await flushView();226 expect(createButton.disabled).toBe(false);227228 pressEnter(confirm);229 await flushView();230231 expect(sendMessageMock).toHaveBeenCalledWith({232 type: "CREATE_VAULT",233 payload: { password: "correct horse battery staple" },234 });235 expect(onUnlock).toHaveBeenCalled();236 });237238 it("Export keeps encrypted export disabled until the password meets the minimum length", async () => {239 const container = mount(<ExportView onBack={vi.fn()} />);240241 const password = container.querySelector('input[placeholder*="backup password"]') as HTMLInputElement;242 const button = Array.from(container.querySelectorAll("button")).find(243 (candidate) => candidate.textContent?.trim() === "Download backup file"244 ) as HTMLButtonElement;245246 inputText(password, "too-short");247 await flushView();248249 expect(button.disabled).toBe(true);250 expect(exportEntriesToPeachJsonMock).not.toHaveBeenCalled();251 });252253 it("Export requests entries and sends the correct payload to the encrypted backup exporter", async () => {254 sendMessageMock.mockResolvedValue({255 ok: true,256 data: [sampleEntry(), sampleEntry({ id: "deleted", deletedAt: 2 })],257 });258 exportEntriesToPeachJsonMock.mockResolvedValue({259 version: 2,260 type: "peach-export",261 });262 const container = mount(<ExportView onBack={vi.fn()} />);263264 const password = container.querySelector('input[placeholder*="backup password"]') as HTMLInputElement;265 const button = Array.from(container.querySelectorAll("button")).find(266 (candidate) => candidate.textContent?.trim() === "Download backup file"267 ) as HTMLButtonElement;268269 inputText(password, "correct horse battery staple");270 await flushView();271 button.click();272 await flushView();273274 expect(sendMessageMock).toHaveBeenCalledWith({ type: "GET_ENTRIES" });275 expect(exportEntriesToPeachJsonMock).toHaveBeenCalledWith(276 [expect.objectContaining({ id: "entry-1" })],277 "correct horse battery staple"278 );279 });280281 it("Settings requires current, new, and confirm passwords before enabling save", async () => {282 sendMessageMock.mockResolvedValue({ ok: true, data: null });283 const container = mount(284 <SettingsView285 entriesCount={1}286 breachMonitoring={true}287 lockOnClose={true}288 autoLockMinutes={5}289 trashRetentionDays={30}290 theme="dark"291 onBreachMonitoringChange={vi.fn()}292 onLockOnCloseChange={vi.fn()}293 onAutoLockMinutesChange={vi.fn()}294 onTrashRetentionChange={vi.fn()}295 onThemeChange={vi.fn()}296 onBack={vi.fn()}297 onImport={vi.fn()}298 onExport={vi.fn()}299 onBreachCheckDone={vi.fn()}300 />301 );302 await flushView();303304 const changeButton = Array.from(container.querySelectorAll("button")).find(305 (candidate) => candidate.textContent?.trim() === "change"306 ) as HTMLButtonElement;307 changeButton.click();308 await flushView();309310 const saveButton = Array.from(container.querySelectorAll("button")).find(311 (candidate) => candidate.textContent?.trim() === "save new password"312 ) as HTMLButtonElement;313 expect(saveButton.disabled).toBe(true);314315 const inputs = container.querySelectorAll('input[type="password"]');316 inputText(inputs[0] as HTMLInputElement, "current-pass");317 inputText(inputs[1] as HTMLInputElement, "new-pass-12345");318 await flushView();319 expect(saveButton.disabled).toBe(true);320321 inputText(inputs[2] as HTMLInputElement, "new-pass-12345");322 await flushView();323 expect(saveButton.disabled).toBe(false);324 });325326 it("Settings sends CHANGE_PASSWORD and forwards auto-lock/theme changes through callbacks", async () => {327 sendMessageMock.mockResolvedValue({ ok: true, data: null });328 const onAutoLockMinutesChange = vi.fn();329 const onThemeChange = vi.fn();330 const container = mount(331 <SettingsView332 entriesCount={1}333 breachMonitoring={true}334 lockOnClose={true}335 autoLockMinutes={5}336 trashRetentionDays={30}337 theme="dark"338 onBreachMonitoringChange={vi.fn()}339 onLockOnCloseChange={vi.fn()}340 onAutoLockMinutesChange={onAutoLockMinutesChange}341 onTrashRetentionChange={vi.fn()}342 onThemeChange={onThemeChange}343 onBack={vi.fn()}344 onImport={vi.fn()}345 onExport={vi.fn()}346 onBreachCheckDone={vi.fn()}347 />348 );349 await flushView();350 sendMessageMock.mockClear();351352 const selects = container.querySelectorAll("select");353 changeSelect(selects[0] as HTMLSelectElement, "15");354 expect(onAutoLockMinutesChange).toHaveBeenCalledWith(15);355356 const themeButton = Array.from(container.querySelectorAll("button")).find(357 (candidate) => candidate.textContent?.trim() === "Switch to light"358 ) as HTMLButtonElement;359 themeButton.click();360 expect(onThemeChange).toHaveBeenCalledWith("light");361362 const changeButton = Array.from(container.querySelectorAll("button")).find(363 (candidate) => candidate.textContent?.trim() === "change"364 ) as HTMLButtonElement;365 changeButton.click();366 await flushView();367368 const inputs = container.querySelectorAll('input[type="password"]');369 inputText(inputs[0] as HTMLInputElement, "current-pass");370 inputText(inputs[1] as HTMLInputElement, "new-password-123");371 inputText(inputs[2] as HTMLInputElement, "new-password-123");372 await flushView();373374 const saveButton = Array.from(container.querySelectorAll("button")).find(375 (candidate) => candidate.textContent?.trim() === "save new password"376 ) as HTMLButtonElement;377 saveButton.click();378 await flushView();379380 expect(sendMessageMock).toHaveBeenCalledWith({381 type: "CHANGE_PASSWORD",382 payload: {383 currentPassword: "current-pass",384 newPassword: "new-password-123",385 },386 });387 });388389 it("Entry copy actions send COPY and canary ping messages for password and username", async () => {390 sendMessageMock.mockResolvedValue({ ok: true });391 const container = mount(392 <EntryView393 entry={sampleEntry()}394 onDelete={vi.fn()}395 onFieldSaved={vi.fn(async () => undefined)}396 />397 );398399 const passwordButton = container.querySelector('button[aria-label="Copy password"]') as HTMLButtonElement;400 passwordButton.click();401 await flushView();402403 expect(sendMessageMock).toHaveBeenNthCalledWith(1, {404 type: "COPY",405 payload: { text: "secret123", label: "password" },406 });407 expect(sendMessageMock).toHaveBeenNthCalledWith(2, {408 type: "FIRE_CANARY_PING",409 payload: {410 webhookUrl: "https://example.com/hook",411 entryTitle: "GitHub",412 trigger: "password_copied",413 },414 });415416 sendMessageMock.mockClear();417 const usernameButton = container.querySelector('button[aria-label="Copy username"]') as HTMLButtonElement;418 usernameButton.click();419 await flushView();420421 expect(sendMessageMock).toHaveBeenNthCalledWith(1, {422 type: "COPY",423 payload: { text: "june", label: "username" },424 });425 expect(sendMessageMock).toHaveBeenNthCalledWith(2, {426 type: "FIRE_CANARY_PING",427 payload: {428 webhookUrl: "https://example.com/hook",429 entryTitle: "GitHub",430 trigger: "username_copied",431 },432 });433 });434435 it("Entry refuses to send an empty password update and copies TOTP through COPY", async () => {436 sendMessageMock.mockResolvedValue({ ok: true });437 const onFieldSaved = vi.fn(async () => undefined);438 const container = mount(439 <EntryView440 entry={sampleEntry()}441 onDelete={vi.fn()}442 onFieldSaved={onFieldSaved}443 />444 );445446 const passwordValue = container.querySelector(".peach-password-value") as HTMLSpanElement;447 passwordValue.click();448 await flushView();449450 const passwordInput = container.querySelector('input[placeholder="paste or type a password"]') as HTMLInputElement;451 inputText(passwordInput, "");452 await flushView();453454 const saveButton = container.querySelector('button[aria-label="Save"]') as HTMLButtonElement;455 saveButton.click();456 await flushView();457458 expect(sendMessageMock).not.toHaveBeenCalledWith(459 expect.objectContaining({ type: "UPDATE_ENTRY" })460 );461 expect(onFieldSaved).not.toHaveBeenCalled();462463 const totpButton = container.querySelector('button[aria-label="Copy TOTP code"]') as HTMLButtonElement;464 totpButton.click();465 await flushView();466467 expect(sendMessageMock).toHaveBeenLastCalledWith({468 type: "COPY",469 payload: { text: "123456", label: "totp" },470 });471 });472473 it("Entry closes an unchanged inline editor when focus leaves it", async () => {474 sendMessageMock.mockResolvedValue({ ok: true });475 const container = mount(476 <EntryView477 entry={sampleEntry()}478 onDelete={vi.fn()}479 onFieldSaved={vi.fn(async () => undefined)}480 />481 );482483 const usernameValue = container.querySelector(".peach-field-value.peach-inline-clickable") as HTMLSpanElement;484 usernameValue.click();485 await flushView();486487 const usernameInput = container.querySelector(".peach-inline-input[autocomplete=\"off\"]") as HTMLInputElement;488 usernameInput.blur();489 await flushView();490491 expect(container.querySelector(".peach-inline-input[autocomplete=\"off\"]")).toBeNull();492 expect(sendMessageMock).not.toHaveBeenCalledWith(493 expect.objectContaining({ type: "UPDATE_ENTRY" })494 );495 });496497 it("Entry lets TOTP secrets be edited inline", async () => {498 sendMessageMock.mockResolvedValue({ ok: true });499 const onFieldSaved = vi.fn(async () => undefined);500 const container = mount(501 <EntryView502 entry={sampleEntry()}503 onDelete={vi.fn()}504 onFieldSaved={onFieldSaved}505 />506 );507508 const totpMain = container.querySelector(".peach-totp-main.peach-inline-clickable") as HTMLDivElement;509 totpMain.click();510 await flushView();511512 const totpInput = container.querySelector('input[placeholder="otpauth://... or base32 secret"]') as HTMLInputElement;513 inputText(totpInput, "otpauth://totp/Example?secret=NB2W45DFOIZA====&issuer=Peach");514 await flushView();515516 const saveButton = container.querySelector('button[aria-label="Save"]') as HTMLButtonElement;517 saveButton.click();518 await flushView();519520 expect(sendMessageMock).toHaveBeenCalledWith({521 type: "UPDATE_ENTRY",522 payload: {523 id: "entry-1",524 patch: { totp: "NB2W45DFOIZA====" },525 },526 });527 expect(onFieldSaved).toHaveBeenCalled();528 });529530 it("Vault seeds and focuses search when a search seed is provided", async () => {531 const container = mount(532 <VaultView533 entries={[sampleEntry(), sampleEntry({ id: "entry-2", title: "GitLab" })]}534 sortOrder="url-first"535 searchSeed="g"536 searchSeedNonce={1}537 onSelectEntry={vi.fn()}538 onSortOrderChange={vi.fn()}539 onAdd={vi.fn()}540 onClose={vi.fn()}541 />542 );543544 await flushView();545546 const search = container.querySelector(".peach-list-top .peach-search-input") as HTMLInputElement;547 expect(search.value).toBe("g");548 expect(document.activeElement).toBe(search);549 });550551 it("Import existing-vault add mode parses a file and batches entries into the vault", async () => {552 parseImportSourceMock.mockResolvedValue(553 sampleImportResult({554 entries: [555 {556 type: "login",557 title: "Imported site",558 username: "imported-user",559 password: "imported-pass",560 url: "https://imported.test",561 },562 ],563 })564 );565 sendMessageMock.mockImplementation(async (msg: unknown) => {566 const type = (msg as { type?: string }).type;567 if (type === "GET_ENTRIES") {568 return {569 ok: true,570 data: [571 sampleEntry({572 id: "existing-1",573 title: "Imported site",574 username: "imported-user",575 url: "https://imported.test",576 }),577 ],578 };579 }580 if (type === "BATCH_ADD_ENTRIES") {581 return { ok: true, data: [sampleEntry({ id: "imported-1" })] };582 }583 return { ok: true };584 });585 const onImport = vi.fn(async () => undefined);586 const container = mount(<ImportView onBack={vi.fn()} onImport={onImport} />);587 await flushView();588 sendMessageMock.mockClear();589590 await selectImportFile(container);591 findButton(container, "Import 1").click();592 await flushView();593594 expect(parseImportSourceMock).toHaveBeenCalledWith('{"export":"test"}', undefined);595 expect(sendMessageMock).toHaveBeenCalledWith({596 type: "BATCH_ADD_ENTRIES",597 payload: {598 entries: [599 expect.objectContaining({600 title: "Imported site",601 username: "imported-user",602 password: "imported-pass",603 url: "https://imported.test",604 }),605 ],606 },607 });608 expect(onImport).toHaveBeenCalled();609 expect(container.textContent).toContain("1 entry appears to be duplicates");610 });611612 it("Import replace mode requires confirmation before clearing and replacing the vault", async () => {613 parseImportSourceMock.mockResolvedValue(sampleImportResult());614 sendMessageMock.mockImplementation(async (msg: unknown) => {615 const type = (msg as { type?: string }).type;616 if (type === "GET_ENTRIES") {617 return { ok: true, data: [sampleEntry({ id: "existing-1" })] };618 }619 if (type === "CLEAR_VAULT_ENTRIES") {620 return { ok: true };621 }622 if (type === "BATCH_ADD_ENTRIES") {623 return { ok: true, data: [sampleEntry({ id: "imported-1" })] };624 }625 return { ok: true };626 });627 const onImport = vi.fn(async () => undefined);628 const container = mount(<ImportView onBack={vi.fn()} onImport={onImport} />);629 await flushView();630 sendMessageMock.mockClear();631632 await selectImportFile(container);633 (container.querySelector('input[value="replace"]') as HTMLInputElement).click();634 await flushView();635636 findButton(container, "Replace vault with 1").click();637 await flushView();638639 expect(sendMessageMock).not.toHaveBeenCalledWith(640 expect.objectContaining({ type: "CLEAR_VAULT_ENTRIES" })641 );642 expect(container.textContent).toContain("Replace forever? This cannot be undone.");643644 findButton(container, "Yes, replace forever").click();645 await flushView();646647 expect(sendMessageMock).toHaveBeenCalledWith({ type: "CLEAR_VAULT_ENTRIES" });648 expect(sendMessageMock).toHaveBeenCalledWith({649 type: "BATCH_ADD_ENTRIES",650 payload: { entries: [expect.objectContaining({ title: "Imported site" })] },651 });652 expect(onImport).toHaveBeenCalled();653 });654655 it("Import onboarding mode waits for a matching master password before creating a vault", async () => {656 parseImportSourceMock.mockResolvedValue(sampleImportResult());657 sendMessageMock.mockImplementation(async (msg: unknown) => {658 const type = (msg as { type?: string }).type;659 if (type === "CREATE_VAULT") return { ok: true };660 if (type === "BATCH_ADD_ENTRIES") {661 return { ok: true, data: [sampleEntry({ id: "imported-1" })] };662 }663 return { ok: true };664 });665 const onImport = vi.fn(async () => undefined);666 const container = mount(667 <ImportView668 mode="onboarding"669 replacesExistingVault={true}670 onBack={vi.fn()}671 onImport={onImport}672 />673 );674675 await selectImportFile(container);676677 const createButton = findButton(container, "Create vault + import 1");678 expect(createButton.disabled).toBe(true);679 expect(container.textContent).toContain("Restoring now replaces the locked local vault");680681 const inputs = container.querySelectorAll('input[type="password"]');682 inputText(inputs[0] as HTMLInputElement, "fresh-master-password");683 inputText(inputs[1] as HTMLInputElement, "fresh-master-password");684 await flushView();685686 expect(createButton.disabled).toBe(false);687 createButton.click();688 await flushView();689690 expect(sendMessageMock).toHaveBeenCalledWith({691 type: "CREATE_VAULT",692 payload: { password: "fresh-master-password" },693 });694 expect(sendMessageMock).toHaveBeenCalledWith({695 type: "BATCH_ADD_ENTRIES",696 payload: { entries: [expect.objectContaining({ title: "Imported site" })] },697 });698 expect(onImport).toHaveBeenCalled();699 });700701 it("Import encrypted backups reparse with the backup password before import", async () => {702 parseImportSourceMock703 .mockResolvedValueOnce(704 sampleImportResult({705 format: "peach-json",706 label: "Peach encrypted backup",707 entries: [],708 totalItems: 0,709 requiresPassword: true,710 })711 )712 .mockResolvedValueOnce(713 sampleImportResult({714 format: "peach-json",715 label: "Peach encrypted backup",716 })717 );718 sendMessageMock.mockImplementation(async (msg: unknown) => {719 const type = (msg as { type?: string }).type;720 if (type === "GET_ENTRIES") return { ok: true, data: [] };721 if (type === "BATCH_ADD_ENTRIES") {722 return { ok: true, data: [sampleEntry({ id: "imported-1" })] };723 }724 return { ok: true };725 });726 const onImport = vi.fn(async () => undefined);727 const container = mount(<ImportView onBack={vi.fn()} onImport={onImport} />);728 await flushView();729 sendMessageMock.mockClear();730731 await selectImportFile(container, '{"type":"peach-export"}');732 const password = container.querySelector('input[placeholder="backup password"]') as HTMLInputElement;733 inputText(password, "backup-passphrase");734 pressEnter(password);735 await flushView();736 await flushView();737738 expect(parseImportSourceMock).toHaveBeenNthCalledWith(1, '{"type":"peach-export"}', undefined);739 expect(parseImportSourceMock).toHaveBeenNthCalledWith(2, '{"type":"peach-export"}', "backup-passphrase");740741 findButton(container, "Import 1").click();742 await flushView();743744 expect(sendMessageMock).toHaveBeenCalledWith({745 type: "BATCH_ADD_ENTRIES",746 payload: { entries: [expect.objectContaining({ title: "Imported site" })] },747 });748 expect(onImport).toHaveBeenCalled();749 });750});