/* @vitest-environment node */

import { describe, it, expect } from "vitest";
import {
	getPasswordPolicyHintLinesDe,
	reasonsToHintLinesDe,
	buildWeakPasswordMessageDe,
} from "./passwordPolicyUi.js";

describe("lib/frontend/profile/passwordPolicyUi", () => {
	it("returns stable policy hint lines (German)", () => {
		const lines = getPasswordPolicyHintLinesDe();
		expect(lines.length).toBeGreaterThanOrEqual(3);
		expect(lines[0]).toMatch(/Mindestens/i);
	});

	it("maps ordered reasons to German hint lines", () => {
		const lines = reasonsToHintLinesDe({
			reasons: ["MISSING_NUMBER", "MIN_LENGTH"],
			minLength: 8,
		});

		expect(lines).toEqual(["Mindestens 8 Zeichen", "Mindestens 1 Zahl (0–9)"]);
	});

	it("buildWeakPasswordMessageDe joins hint lines with separators", () => {
		const msg = buildWeakPasswordMessageDe({
			reasons: ["MIN_LENGTH", "MISSING_LETTER"],
			minLength: 8,
		});

		expect(msg).toBe("Mindestens 8 Zeichen • Mindestens 1 Buchstabe (A–Z)");
	});

	it("returns a generic message when reasons are missing", () => {
		expect(buildWeakPasswordMessageDe({ reasons: null })).toMatch(/stärkeres/i);
	});
});
