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

test("full access uses the shared app dialog and applies the option only after confirmation", async () => {
  const [menu, dialog] = await Promise.all([
    readFile(new URL("./ComposerPermissionMenu.jsx", import.meta.url), "utf8"),
    readFile(new URL("./FullAccessDialog.jsx", import.meta.url), "utf8")
  ]);

  assert.match(menu, /requiresFullAccessConfirmation\(selected, id\)/);
  assert.match(menu, /setFullAccessConfirmationOpen\(true\)/);
  assert.match(menu, /<FullAccessDialog/);
  assert.match(dialog, /<ActionDialog/);
  assert.match(dialog, /tone="danger"/);
  assert.match(dialog, /onConfirm=\{onConfirm\}/);
  assert.doesNotMatch(menu, /window\.(?:confirm|alert)/);
});

test("full access warning describes this app's actual capability groups", async () => {
  const i18n = await readFile(new URL("../../shared/i18n.js", import.meta.url), "utf8");

  for (const key of [
    "composer.fullAccessConfirmTitle",
    "composer.fullAccessConfirmDescription",
    "composer.fullAccessFiles",
    "composer.fullAccessCommands",
    "composer.fullAccessConnections",
    "composer.fullAccessConfirm"
  ]) {
    assert.match(i18n, new RegExp(`"${key}"`));
  }
});
