mealie/frontend/lib/validators/inputs.test.ts
Hoa (Kyle) Trinh c24d532608
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend Tests (push) Waiting to run
Docker Nightly Production / Build Package (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Release Drafter / ✏️ Draft release (push) Waiting to run
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
2025-06-19 17:09:12 +00:00

71 lines
1.7 KiB
TypeScript

import { expect, test } from "vitest";
import { required, email, whitespace, url, minLength, maxLength } from "./inputs";
export { scorePassword } from "./password";
test("validator required", () => {
const falsey = "This Field is Required";
expect(required("123")).toBe(true);
expect(required("")).toBe(falsey);
expect(required(undefined)).toBe(falsey);
expect(required(null)).toBe(falsey);
});
const nulls = [undefined, null];
test("validator email", () => {
const falsey = "Email Must Be Valid";
expect(email("123")).toBe(falsey);
expect(email("email@example.com")).toBe(true);
for (const n of nulls) {
expect(email(n)).toBe(falsey);
}
});
test("whitespace", () => {
const falsey = "No Whitespace Allowed";
expect(whitespace("123")).toBe(true);
expect(whitespace(" ")).toBe(falsey);
expect(whitespace("123 123")).toBe(falsey);
for (const n of nulls) {
expect(whitespace(n)).toBe(falsey);
}
});
test("url", () => {
const falsey = "Must Be A Valid URL";
expect(url("https://example.com")).toBe(true);
expect(url("")).toBe(falsey);
for (const n of nulls) {
expect(url(n)).toBe(falsey);
}
});
test("minLength", () => {
const min = 3;
const falsey = `Must Be At Least ${min} Characters`;
const fn = minLength(min);
expect(fn("123")).toBe(true);
expect(fn("12")).toBe(falsey);
expect(fn("")).toBe(falsey);
for (const n of nulls) {
expect(fn(n)).toBe(falsey);
}
});
test("maxLength", () => {
const max = 3;
const falsey = `Must Be At Most ${max} Characters`;
const fn = maxLength(max);
expect(fn("123")).toBe(true);
expect(fn("1234")).toBe(falsey);
expect(fn("")).toBe(true);
for (const n of nulls) {
expect(fn(n)).toBe(true);
}
});