mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-23 23:02:17 +10:00
fix: address Greptile review on margin clamping
Add .catch() fallbacks for marginX/marginY so oversized stored values recover instead of failing schema parse, and allow transient empty numeric input in the form without persisting invalid metadata. Co-authored-by: Amruth Pillai <im.amruth@gmail.com>
This commit is contained in:
co-authored by
Amruth Pillai
parent
f55e584e34
commit
1aca52b0d7
@@ -260,6 +260,19 @@ describe("pageSchema", () => {
|
||||
expect(pageSchema.safeParse(invalid).success).toBe(false);
|
||||
});
|
||||
|
||||
it("falls back to default margins when out of range via .catch", () => {
|
||||
const result = pageSchema.safeParse({
|
||||
...defaultResumeData.metadata.page,
|
||||
marginX: 1224,
|
||||
marginY: 999,
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.marginX).toBe(14);
|
||||
expect(result.data.marginY).toBe(12);
|
||||
}
|
||||
});
|
||||
|
||||
it("falls back to 'a4' for unknown format via .catch", () => {
|
||||
const invalid = { ...defaultResumeData.metadata.page, format: "huge" };
|
||||
const result = pageSchema.safeParse(invalid);
|
||||
|
||||
@@ -444,8 +444,8 @@ export const layoutSchema = z.object({
|
||||
export const pageSchema = z.object({
|
||||
gapX: z.number().min(0).describe("The horizontal gap between the sections of the page, defined in points (pt)."),
|
||||
gapY: z.number().min(0).describe("The vertical gap between the sections of the page, defined in points (pt)."),
|
||||
marginX: z.number().min(0).max(100).describe("The horizontal margin of the page, defined in points (pt)."),
|
||||
marginY: z.number().min(0).max(100).describe("The vertical margin of the page, defined in points (pt)."),
|
||||
marginX: z.number().min(0).max(100).catch(14).describe("The horizontal margin of the page, defined in points (pt)."),
|
||||
marginY: z.number().min(0).max(100).catch(12).describe("The vertical margin of the page, defined in points (pt)."),
|
||||
format: z
|
||||
.enum(["a4", "letter", "free-form"])
|
||||
.describe("The format of the page. Can be 'a4', 'letter', or 'free-form'.")
|
||||
|
||||
Reference in New Issue
Block a user