24 lines
1.5 KiB
TypeScript
24 lines
1.5 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { emailStyleValue, validateEmailStyleValue } from "../src/style-values.ts";
|
|
|
|
test("base style syntax rejects ignored or injected values and accepts supported units", () => {
|
|
for (const [key, value] of [["padding","12"],["padding","1px 2px 3px 4px 5px"],["color","#12345"],["fontWeight","heavy"],["fontSize","12px;color:red"],["position","fixed"],["constructor","x"]]) {
|
|
expect(emailStyleValue(key!, value)).toBe("");
|
|
expect(() => validateEmailStyleValue(key!, value!)).toThrow();
|
|
}
|
|
for (const [key, value] of [["padding","0 12px"],["margin","1rem 2%"],["color","#1234"],["fontWeight","700"],["fontSize","16px"],["borderRadius","0"],["textAlign","end"]]) {
|
|
expect(emailStyleValue(key!, value)).toBe(value!);
|
|
expect(() => validateEmailStyleValue(key!, value!)).not.toThrow();
|
|
}
|
|
});
|
|
|
|
test("RGB functions require correct channel counts, units and bounded components", () => {
|
|
for (const value of ["rgb(1)", "rgb(1,2,3,4)", "rgba(1,2,3)", "rgb(256,0,0)", "rgb(100%,0,0)", "rgba(1,2,3,1.1)", "rgb(1..2,2,3)", "rgba(0,0,0,101%)"])
|
|
expect(emailStyleValue("color", value)).toBe("");
|
|
for (const value of ["rgb(255, 0, 12)", "rgb(100%, 0%, 50%)", "rgba(0,0,0,.5)", "rgba(0,0,0,50%)", "transparent"])
|
|
expect(emailStyleValue("backgroundColor", value)).toBe(value);
|
|
expect(emailStyleValue("padding", "0 4000px")).toBe("0 4000px");
|
|
expect(emailStyleValue("padding", "0 4001px")).toBe("");
|
|
expect(emailStyleValue("fontSize", "999999999999999999999px")).toBe("");
|
|
});
|