import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

test("capture mosaic setting covers every visible account identity", async () => {
  const [app, settings, accountManagement, accountsPanel, usageSettings, header, conversationAccount, identity, css] = await Promise.all([
    readFile(new URL("../../App.jsx", import.meta.url), "utf8"),
    readFile(new URL("../context/SettingsWindow.jsx", import.meta.url), "utf8"),
    readFile(new URL("./AccountManagementPage.jsx", import.meta.url), "utf8"),
    readFile(new URL("./AccountsPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("../status/UsageSettingsPage.jsx", import.meta.url), "utf8"),
    readFile(new URL("../context/ContextBar.jsx", import.meta.url), "utf8"),
    readFile(new URL("../status/StatusPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("./AccountIdentity.jsx", import.meta.url), "utf8"),
    readFile(new URL("../context/context.css", import.meta.url), "utf8")
  ]);

  assert.match(app, /readAccountMosaicPreference/);
  assert.match(app, /accountMosaic=\{accountMosaic\}/);
  assert.match(app, /onAccountMosaicChange=\{setAccountMosaic\}/);
  assert.match(app, /<ConversationAccountBar session=\{visibleSession\} accounts=\{app\.accounts\} accountMosaic=\{accountMosaic\} \/>/);
  assert.match(settings, /<AccountManagementPage[^>]*accountMosaic=\{accountMosaic\}/);
  assert.match(accountManagement, /t\("settings\.accountMosaic"\)/);
  assert.match(accountManagement, /onAccountMosaicChange\(!accountMosaic\)/);
  assert.match(accountManagement, /className="settings-account-mosaic-copy"/);
  assert.match(accountManagement, /<button type="button" className="settings-choice settings-account-mosaic"/);
  assert.match(accountManagement, /<span className="settings-account-mosaic-copy">\{t\("settings\.accountMosaic"\)\}<\/span><span className=\{accountMosaic \? "settings-switch active" : "settings-switch"\}/);
  assert.doesNotMatch(accountManagement, /settings\.accountMosaicDescription/);
  assert.match(accountManagement, /aria-label=\{t\("settings\.accountMosaic"\)\}/);
  assert.match(accountManagement, /aria-pressed=\{accountMosaic\}/);
  assert.doesNotMatch(accountManagement, /className="sr-only"/);
  assert.match(accountManagement, /<AccountsPanel accounts=\{accounts\} manager=\{manager\} accountMosaic=\{accountMosaic\} \/>/);
  assert.match(settings, /<UsageSettingsPage accounts=\{accounts\} accountMosaic=\{accountMosaic\} onBack=\{closeUsage\} \/>/);
  assert.match(accountsPanel, /<AccountIdentity account=\{account\} accounts=\{accounts\} mosaic=\{accountMosaic\} \/>/);
  assert.match(usageSettings, /<AccountIdentity identity=\{usageAccountLabel\(account, accounts\)\} mosaic=\{accountMosaic\} \/>/);
  assert.match(usageSettings, /<AccountIdentity identity=\{accountName\} mosaic=\{accountMosaic\} \/>/);
  assert.match(header, /<AccountIdentity account=\{account\} accounts=\{accounts\} mosaic=\{accountMosaic\} \/>/);
  assert.match(header, /<AccountIdentity account=\{accountOption\} accounts=\{accounts\} mosaic=\{accountMosaic\} \/>/);
  assert.match(conversationAccount, /<AccountIdentity identity=\{lastConversationAccountName\(session, accounts, language\)\} mosaic=\{accountMosaic\} \/>/);
  assert.match(identity, /accountDisplayParts/);
  assert.match(identity, /accountIdentityParts/);
  assert.match(identity, /if \(!mosaic\) return value;/);
  assert.match(identity, /<span className="account-identity-local account-identity-local--mosaic">\{parts\.local\}<span className="account-identity-mosaic-overlay" aria-hidden="true"><\/span><\/span>\{parts\.domain\}/);
  assert.match(css, /\.account-identity-local\{[^}]*display:inline-block/);
  assert.match(css, /\.account-identity-local--mosaic\{[^}]*position:relative/);
  assert.match(css, /\.account-identity-mosaic-overlay\{[^}]*position:absolute[^}]*inset:0[^}]*backdrop-filter:blur\(5px\)/);
  assert.doesNotMatch(css, /\.account-identity-local--mosaic\{[^}]*filter:/);
  assert.doesNotMatch(css, /-webkit-text-fill-color:transparent/);
  assert.match(css, /\.settings-account-mosaic\{[^}]*height:48px[^}]*padding:0 14px[^}]*gap:14px/);
  assert.match(css, /\.settings-account-mosaic>span\{[^}]*min-width:0/);
  assert.doesNotMatch(css, /\.settings-account-mosaic-copy\{[^}]*font-size:/);
  assert.match(css, /\.settings-switch\{[^}]*width:48px[^}]*height:24px/);
});
