contracts.test.tsx

25.3 KB · raw

1// @vitest-environment jsdom23import 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        accentColor="peach"292        onBreachMonitoringChange={vi.fn()}293        onLockOnCloseChange={vi.fn()}294        onAutoLockMinutesChange={vi.fn()}295        onTrashRetentionChange={vi.fn()}296        onThemeChange={vi.fn()}297        onAccentChange={vi.fn()}298        onBack={vi.fn()}299        onImport={vi.fn()}300        onExport={vi.fn()}301        onBreachCheckDone={vi.fn()}302      />303    );304    await flushView();305306    const changeButton = Array.from(container.querySelectorAll("button")).find(307      (candidate) => candidate.textContent?.trim() === "change"308    ) as HTMLButtonElement;309    changeButton.click();310    await flushView();311312    const saveButton = Array.from(container.querySelectorAll("button")).find(313      (candidate) => candidate.textContent?.trim() === "save new password"314    ) as HTMLButtonElement;315    expect(saveButton.disabled).toBe(true);316317    const inputs = container.querySelectorAll('input[type="password"]');318    inputText(inputs[0] as HTMLInputElement, "current-pass");319    inputText(inputs[1] as HTMLInputElement, "new-pass-12345");320    await flushView();321    expect(saveButton.disabled).toBe(true);322323    inputText(inputs[2] as HTMLInputElement, "new-pass-12345");324    await flushView();325    expect(saveButton.disabled).toBe(false);326  });327328  it("Settings sends CHANGE_PASSWORD and forwards auto-lock/theme changes through callbacks", async () => {329    sendMessageMock.mockResolvedValue({ ok: true, data: null });330    const onAutoLockMinutesChange = vi.fn();331    const onThemeChange = vi.fn();332    const container = mount(333      <SettingsView334        entriesCount={1}335        breachMonitoring={true}336        lockOnClose={true}337        autoLockMinutes={5}338        trashRetentionDays={30}339        theme="dark"340        accentColor="peach"341        onBreachMonitoringChange={vi.fn()}342        onLockOnCloseChange={vi.fn()}343        onAutoLockMinutesChange={onAutoLockMinutesChange}344        onTrashRetentionChange={vi.fn()}345        onThemeChange={onThemeChange}346        onAccentChange={vi.fn()}347        onBack={vi.fn()}348        onImport={vi.fn()}349        onExport={vi.fn()}350        onBreachCheckDone={vi.fn()}351      />352    );353    await flushView();354    sendMessageMock.mockClear();355356    const selects = container.querySelectorAll("select");357    changeSelect(selects[0] as HTMLSelectElement, "15");358    expect(onAutoLockMinutesChange).toHaveBeenCalledWith(15);359360    const themeButton = Array.from(container.querySelectorAll("button")).find(361      (candidate) => candidate.textContent?.trim() === "Switch to light"362    ) as HTMLButtonElement;363    themeButton.click();364    expect(onThemeChange).toHaveBeenCalledWith("light");365366    const changeButton = Array.from(container.querySelectorAll("button")).find(367      (candidate) => candidate.textContent?.trim() === "change"368    ) as HTMLButtonElement;369    changeButton.click();370    await flushView();371372    const inputs = container.querySelectorAll('input[type="password"]');373    inputText(inputs[0] as HTMLInputElement, "current-pass");374    inputText(inputs[1] as HTMLInputElement, "new-password-123");375    inputText(inputs[2] as HTMLInputElement, "new-password-123");376    await flushView();377378    const saveButton = Array.from(container.querySelectorAll("button")).find(379      (candidate) => candidate.textContent?.trim() === "save new password"380    ) as HTMLButtonElement;381    saveButton.click();382    await flushView();383384    expect(sendMessageMock).toHaveBeenCalledWith({385      type: "CHANGE_PASSWORD",386      payload: {387        currentPassword: "current-pass",388        newPassword: "new-password-123",389      },390    });391  });392393  it("Entry copy actions send COPY and canary ping messages for password and username", async () => {394    sendMessageMock.mockResolvedValue({ ok: true });395    const container = mount(396      <EntryView397        entry={sampleEntry()}398        onDelete={vi.fn()}399        onFieldSaved={vi.fn(async () => undefined)}400      />401    );402403    const passwordButton = container.querySelector('button[aria-label="Copy password"]') as HTMLButtonElement;404    passwordButton.click();405    await flushView();406407    expect(sendMessageMock).toHaveBeenNthCalledWith(1, {408      type: "COPY",409      payload: { text: "secret123", label: "password" },410    });411    expect(sendMessageMock).toHaveBeenNthCalledWith(2, {412      type: "FIRE_CANARY_PING",413      payload: {414        webhookUrl: "https://example.com/hook",415        entryTitle: "GitHub",416        trigger: "password_copied",417      },418    });419420    sendMessageMock.mockClear();421    const usernameButton = container.querySelector('button[aria-label="Copy username"]') as HTMLButtonElement;422    usernameButton.click();423    await flushView();424425    expect(sendMessageMock).toHaveBeenNthCalledWith(1, {426      type: "COPY",427      payload: { text: "june", label: "username" },428    });429    expect(sendMessageMock).toHaveBeenNthCalledWith(2, {430      type: "FIRE_CANARY_PING",431      payload: {432        webhookUrl: "https://example.com/hook",433        entryTitle: "GitHub",434        trigger: "username_copied",435      },436    });437  });438439  it("Entry refuses to send an empty password update and copies TOTP through COPY", async () => {440    sendMessageMock.mockResolvedValue({ ok: true });441    const onFieldSaved = vi.fn(async () => undefined);442    const container = mount(443      <EntryView444        entry={sampleEntry()}445        onDelete={vi.fn()}446        onFieldSaved={onFieldSaved}447      />448    );449450    const passwordValue = container.querySelector(".peach-password-value") as HTMLSpanElement;451    passwordValue.click();452    await flushView();453454    const passwordInput = container.querySelector('input[placeholder="paste or type a password"]') as HTMLInputElement;455    inputText(passwordInput, "");456    await flushView();457458    const saveButton = container.querySelector('button[aria-label="Save"]') as HTMLButtonElement;459    saveButton.click();460    await flushView();461462    expect(sendMessageMock).not.toHaveBeenCalledWith(463      expect.objectContaining({ type: "UPDATE_ENTRY" })464    );465    expect(onFieldSaved).not.toHaveBeenCalled();466467    const totpButton = container.querySelector('button[aria-label="Copy TOTP code"]') as HTMLButtonElement;468    totpButton.click();469    await flushView();470471    expect(sendMessageMock).toHaveBeenLastCalledWith({472      type: "COPY",473      payload: { text: "123456", label: "totp" },474    });475  });476477  it("Entry closes an unchanged inline editor when focus leaves it", async () => {478    sendMessageMock.mockResolvedValue({ ok: true });479    const container = mount(480      <EntryView481        entry={sampleEntry()}482        onDelete={vi.fn()}483        onFieldSaved={vi.fn(async () => undefined)}484      />485    );486487    const usernameValue = container.querySelector(".peach-field-value.peach-inline-clickable") as HTMLSpanElement;488    usernameValue.click();489    await flushView();490491    const usernameInput = container.querySelector(".peach-inline-input[autocomplete=\"off\"]") as HTMLInputElement;492    usernameInput.blur();493    await flushView();494495    expect(container.querySelector(".peach-inline-input[autocomplete=\"off\"]")).toBeNull();496    expect(sendMessageMock).not.toHaveBeenCalledWith(497      expect.objectContaining({ type: "UPDATE_ENTRY" })498    );499  });500501  it("Entry lets TOTP secrets be edited inline", async () => {502    sendMessageMock.mockResolvedValue({ ok: true });503    const onFieldSaved = vi.fn(async () => undefined);504    const container = mount(505      <EntryView506        entry={sampleEntry()}507        onDelete={vi.fn()}508        onFieldSaved={onFieldSaved}509      />510    );511512    const totpMain = container.querySelector(".peach-totp-main.peach-inline-clickable") as HTMLDivElement;513    totpMain.click();514    await flushView();515516    const totpInput = container.querySelector('input[placeholder="otpauth://... or base32 secret"]') as HTMLInputElement;517    inputText(totpInput, "otpauth://totp/Example?secret=NB2W45DFOIZA====&issuer=Peach");518    await flushView();519520    const saveButton = container.querySelector('button[aria-label="Save"]') as HTMLButtonElement;521    saveButton.click();522    await flushView();523524    expect(sendMessageMock).toHaveBeenCalledWith({525      type: "UPDATE_ENTRY",526      payload: {527        id: "entry-1",528        patch: { totp: "NB2W45DFOIZA====" },529      },530    });531    expect(onFieldSaved).toHaveBeenCalled();532  });533534  it("Vault seeds and focuses search when a search seed is provided", async () => {535    const container = mount(536      <VaultView537        entries={[sampleEntry(), sampleEntry({ id: "entry-2", title: "GitLab" })]}538        sortOrder="url-first"539        searchSeed="g"540        searchSeedNonce={1}541        onSelectEntry={vi.fn()}542        onSortOrderChange={vi.fn()}543        onAdd={vi.fn()}544        onClose={vi.fn()}545      />546    );547548    await flushView();549550    const search = container.querySelector(".peach-list-top .peach-search-input") as HTMLInputElement;551    expect(search.value).toBe("g");552    expect(document.activeElement).toBe(search);553  });554555  it("Import existing-vault add mode parses a file and batches entries into the vault", async () => {556    parseImportSourceMock.mockResolvedValue(557      sampleImportResult({558        entries: [559          {560            type: "login",561            title: "Imported site",562            username: "imported-user",563            password: "imported-pass",564            url: "https://imported.test",565          },566        ],567      })568    );569    sendMessageMock.mockImplementation(async (msg: unknown) => {570      const type = (msg as { type?: string }).type;571      if (type === "GET_ENTRIES") {572        return {573          ok: true,574          data: [575            sampleEntry({576              id: "existing-1",577              title: "Imported site",578              username: "imported-user",579              url: "https://imported.test",580            }),581          ],582        };583      }584      if (type === "BATCH_ADD_ENTRIES") {585        return { ok: true, data: [sampleEntry({ id: "imported-1" })] };586      }587      return { ok: true };588    });589    const onImport = vi.fn(async () => undefined);590    const container = mount(<ImportView onBack={vi.fn()} onImport={onImport} />);591    await flushView();592    sendMessageMock.mockClear();593594    await selectImportFile(container);595    findButton(container, "Import 1").click();596    await flushView();597598    expect(parseImportSourceMock).toHaveBeenCalledWith('{"export":"test"}', undefined);599    expect(sendMessageMock).toHaveBeenCalledWith({600      type: "BATCH_ADD_ENTRIES",601      payload: {602        entries: [603          expect.objectContaining({604            title: "Imported site",605            username: "imported-user",606            password: "imported-pass",607            url: "https://imported.test",608          }),609        ],610      },611    });612    expect(onImport).toHaveBeenCalled();613    expect(container.textContent).toContain("1 entry appears to be duplicates");614  });615616  it("Import replace mode requires confirmation before clearing and replacing the vault", async () => {617    parseImportSourceMock.mockResolvedValue(sampleImportResult());618    sendMessageMock.mockImplementation(async (msg: unknown) => {619      const type = (msg as { type?: string }).type;620      if (type === "GET_ENTRIES") {621        return { ok: true, data: [sampleEntry({ id: "existing-1" })] };622      }623      if (type === "CLEAR_VAULT_ENTRIES") {624        return { ok: true };625      }626      if (type === "BATCH_ADD_ENTRIES") {627        return { ok: true, data: [sampleEntry({ id: "imported-1" })] };628      }629      return { ok: true };630    });631    const onImport = vi.fn(async () => undefined);632    const container = mount(<ImportView onBack={vi.fn()} onImport={onImport} />);633    await flushView();634    sendMessageMock.mockClear();635636    await selectImportFile(container);637    (container.querySelector('input[value="replace"]') as HTMLInputElement).click();638    await flushView();639640    findButton(container, "Replace vault with 1").click();641    await flushView();642643    expect(sendMessageMock).not.toHaveBeenCalledWith(644      expect.objectContaining({ type: "CLEAR_VAULT_ENTRIES" })645    );646    expect(container.textContent).toContain("Replace forever? This cannot be undone.");647648    findButton(container, "Yes, replace forever").click();649    await flushView();650651    expect(sendMessageMock).toHaveBeenCalledWith({ type: "CLEAR_VAULT_ENTRIES" });652    expect(sendMessageMock).toHaveBeenCalledWith({653      type: "BATCH_ADD_ENTRIES",654      payload: { entries: [expect.objectContaining({ title: "Imported site" })] },655    });656    expect(onImport).toHaveBeenCalled();657  });658659  it("Import onboarding mode waits for a matching master password before creating a vault", async () => {660    parseImportSourceMock.mockResolvedValue(sampleImportResult());661    sendMessageMock.mockImplementation(async (msg: unknown) => {662      const type = (msg as { type?: string }).type;663      if (type === "CREATE_VAULT") return { ok: true };664      if (type === "BATCH_ADD_ENTRIES") {665        return { ok: true, data: [sampleEntry({ id: "imported-1" })] };666      }667      return { ok: true };668    });669    const onImport = vi.fn(async () => undefined);670    const container = mount(671      <ImportView672        mode="onboarding"673        replacesExistingVault={true}674        onBack={vi.fn()}675        onImport={onImport}676      />677    );678679    await selectImportFile(container);680681    const createButton = findButton(container, "Create vault + import 1");682    expect(createButton.disabled).toBe(true);683    expect(container.textContent).toContain("Restoring now replaces the locked local vault");684685    const inputs = container.querySelectorAll('input[type="password"]');686    inputText(inputs[0] as HTMLInputElement, "fresh-master-password");687    inputText(inputs[1] as HTMLInputElement, "fresh-master-password");688    await flushView();689690    expect(createButton.disabled).toBe(false);691    createButton.click();692    await flushView();693694    expect(sendMessageMock).toHaveBeenCalledWith({695      type: "CREATE_VAULT",696      payload: { password: "fresh-master-password" },697    });698    expect(sendMessageMock).toHaveBeenCalledWith({699      type: "BATCH_ADD_ENTRIES",700      payload: { entries: [expect.objectContaining({ title: "Imported site" })] },701    });702    expect(onImport).toHaveBeenCalled();703  });704705  it("Import encrypted backups reparse with the backup password before import", async () => {706    parseImportSourceMock707      .mockResolvedValueOnce(708        sampleImportResult({709          format: "peach-json",710          label: "Peach encrypted backup",711          entries: [],712          totalItems: 0,713          requiresPassword: true,714        })715      )716      .mockResolvedValueOnce(717        sampleImportResult({718          format: "peach-json",719          label: "Peach encrypted backup",720        })721      );722    sendMessageMock.mockImplementation(async (msg: unknown) => {723      const type = (msg as { type?: string }).type;724      if (type === "GET_ENTRIES") return { ok: true, data: [] };725      if (type === "BATCH_ADD_ENTRIES") {726        return { ok: true, data: [sampleEntry({ id: "imported-1" })] };727      }728      return { ok: true };729    });730    const onImport = vi.fn(async () => undefined);731    const container = mount(<ImportView onBack={vi.fn()} onImport={onImport} />);732    await flushView();733    sendMessageMock.mockClear();734735    await selectImportFile(container, '{"type":"peach-export"}');736    const password = container.querySelector('input[placeholder="backup password"]') as HTMLInputElement;737    inputText(password, "backup-passphrase");738    pressEnter(password);739    await flushView();740    await flushView();741742    expect(parseImportSourceMock).toHaveBeenNthCalledWith(1, '{"type":"peach-export"}', undefined);743    expect(parseImportSourceMock).toHaveBeenNthCalledWith(2, '{"type":"peach-export"}', "backup-passphrase");744745    findButton(container, "Import 1").click();746    await flushView();747748    expect(sendMessageMock).toHaveBeenCalledWith({749      type: "BATCH_ADD_ENTRIES",750      payload: { entries: [expect.objectContaining({ title: "Imported site" })] },751    });752    expect(onImport).toHaveBeenCalled();753  });754});