mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-23 15:19:41 +02:00
chore: frontend testing setup (#1739)
* add vitest * initialize lib w/ tests * move to dev dep * run tests in CI * update file names * move api folder to lib * move api and api types to same folder * update generator outpath * rm husky * i guess i _did_ need those types * reorg types * extract validators into testable components * (WIP) start composable testing * fix import type * fix linter complaint * simplify icon type def * fix linter errors (maybe?) * rename client file for sorting
This commit is contained in:
parent
9f6bcc83d5
commit
fcc5d99d40
182 changed files with 902 additions and 487 deletions
70
frontend/lib/validators/inputs.test.ts
Normal file
70
frontend/lib/validators/inputs.test.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
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);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue