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

test("reset-credit entry points share the app reset dialog instead of browser dialogs", async () => {
  const [contextBar, usagePage, resetDialog] = await Promise.all([
    readFile(new URL("../features/context/ContextBar.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/status/UsageSettingsPage.jsx", import.meta.url), "utf8"),
    readFile(new URL("./ResetCreditDialog.jsx", import.meta.url), "utf8")
  ]);

  assert.match(contextBar, /<ResetCreditDialog/);
  assert.match(usagePage, /<ResetCreditDialog/);
  assert.doesNotMatch(contextBar, /window\.(?:confirm|alert)/);
  assert.doesNotMatch(usagePage, /window\.(?:confirm|alert)/);
  assert.match(resetDialog, /<ActionDialog/);
});

test("native and mobile-PWA settings expose a scoped this-device reset through the same dialog style", async () => {
  const [settings, dialog, contextCss] = await Promise.all([
    readFile(new URL("../features/context/SettingsWindow.jsx", import.meta.url), "utf8"),
    readFile(new URL("./ActionDialog.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/context/context.css", import.meta.url), "utf8")
  ]);

  assert.match(settings, /settings-device-data/);
  assert.doesNotMatch(settings, /platformRuntime\.isNative && <section[^>]+settings-device-data-title/);
  assert.match(contextCss, /\.settings-device-data\.native\{display:flex!important\}/);
  assert.match(contextCss, /@media\(max-width:640px\)\{\.settings-device-data\{display:flex!important\}\}/);
  assert.match(settings, /<ActionDialog/);
  assert.match(dialog, /role="dialog"/);
  assert.match(dialog, /aria-modal="true"/);
});
