import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const source = readFileSync(join(__dirname, "App.vue"), "utf8");

describe("App reset password account picker", () => {
  it("uses a searchable system-user select instead of free text input", () => {
    assert.match(source, /<select[\s\S]*?v-model="resetPasswordForm\.username"[\s\S]*?required[\s\S]*?>/);
    assert.doesNotMatch(source, /placeholder="请输入需要重置密码的账号"/);
  });

  it("loads reset password account options from system permission users", () => {
    assert.match(source, /fetchResource\("\/system-permissions\/users", \[\]\)/);
    assert.match(source, /resetPasswordUserOptions/);
    assert.match(source, /formatResetPasswordUserLabel\(user\)/);
  });
});
