passwordPolicyUi.test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* @vitest-environment node */
  2. import { describe, it, expect } from "vitest";
  3. import {
  4. getPasswordPolicyHintLinesDe,
  5. reasonsToHintLinesDe,
  6. buildWeakPasswordMessageDe,
  7. } from "./passwordPolicyUi.js";
  8. describe("lib/frontend/profile/passwordPolicyUi", () => {
  9. it("returns stable policy hint lines (German)", () => {
  10. const lines = getPasswordPolicyHintLinesDe();
  11. expect(lines.length).toBeGreaterThanOrEqual(3);
  12. expect(lines[0]).toMatch(/Mindestens/i);
  13. });
  14. it("maps ordered reasons to German hint lines", () => {
  15. const lines = reasonsToHintLinesDe({
  16. reasons: ["MISSING_NUMBER", "MIN_LENGTH"],
  17. minLength: 8,
  18. });
  19. expect(lines).toEqual(["Mindestens 8 Zeichen", "Mindestens 1 Zahl (0–9)"]);
  20. });
  21. it("buildWeakPasswordMessageDe joins hint lines with separators", () => {
  22. const msg = buildWeakPasswordMessageDe({
  23. reasons: ["MIN_LENGTH", "MISSING_LETTER"],
  24. minLength: 8,
  25. });
  26. expect(msg).toBe("Mindestens 8 Zeichen • Mindestens 1 Buchstabe (A–Z)");
  27. });
  28. it("returns a generic message when reasons are missing", () => {
  29. expect(buildWeakPasswordMessageDe({ reasons: null })).toMatch(/stärkeres/i);
  30. });
  31. });