// LV-8: the @zxcvbn-ts replacement must score the master-password strength // meter on the same 0-4 scale as the old zxcvbn, with dictionaries loaded // (language-common is what keeps weak passwords from scoring optimistically). import { beforeAll, describe, expect, it } from "vitest"; import { zxcvbn, zxcvbnOptions } from "@zxcvbn-ts/core"; import * as common from "@zxcvbn-ts/language-common"; import * as en from "@zxcvbn-ts/language-en"; beforeAll(() => { // Mirror the loader in Lock.tsx exactly. zxcvbnOptions.setOptions({ translations: en.translations, graphs: common.adjacencyGraphs, dictionary: { ...common.dictionary, ...en.dictionary }, }); }); describe("LV-8 password strength scoring", () => { it("scores a common weak password low (<= 1)", () => { expect(zxcvbn("password123").score).toBeLessThanOrEqual(1); }); it("scores a long random passphrase at the top of the scale (4)", () => { expect(zxcvbn("9xQ!vZ2pLm74Tr#Ke8Wd5Bn").score).toBe(4); }); it("keeps the 0-4 integer scale", () => { const s = zxcvbn("correct horse battery staple").score; expect(Number.isInteger(s)).toBe(true); expect(s).toBeGreaterThanOrEqual(0); expect(s).toBeLessThanOrEqual(4); }); });