feat(renderer): zod validators for settings + export schemas

This commit is contained in:
2026-06-05 18:25:13 +05:30
parent 53870d58bb
commit d0a26126cc
2 changed files with 101 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import { describe, it, expect } from 'vitest';
import {
settingsSchema,
exportPdfSchema,
exportDocxSchema,
exportHtmlSchema,
exportBatchSchema,
} from '@/lib/validators';
describe('settingsSchema', () => {
it('accepts an empty object (all fields have defaults)', () => {
const r = settingsSchema.safeParse({});
expect(r.success).toBe(true);
});
it('rejects out-of-range fontSize', () => {
const r = settingsSchema.safeParse({ fontSize: 100 });
expect(r.success).toBe(false);
});
});
describe('exportPdfSchema', () => {
it('accepts a4 + normal margins + embedFonts true', () => {
expect(exportPdfSchema.safeParse({ format: 'a4', margins: 'normal', embedFonts: true }).success).toBe(true);
});
it('rejects unknown format', () => {
expect(exportPdfSchema.safeParse({ format: 'b4' }).success).toBe(false);
});
});
describe('exportDocxSchema', () => {
it('accepts standard template', () => {
expect(exportDocxSchema.safeParse({ template: 'standard' }).success).toBe(true);
});
it('rejects unknown template', () => {
expect(exportDocxSchema.safeParse({ template: 'fancy' }).success).toBe(false);
});
});
describe('exportHtmlSchema', () => {
it('accepts github highlight style', () => {
expect(exportHtmlSchema.safeParse({ standalone: true, highlightStyle: 'github' }).success).toBe(true);
});
});
describe('exportBatchSchema', () => {
it('accepts a non-empty file list', () => {
expect(exportBatchSchema.safeParse({ format: 'pdf', concurrency: 4, filePaths: ['/a.md'] }).success).toBe(true);
});
it('rejects empty file list', () => {
expect(exportBatchSchema.safeParse({ format: 'pdf', concurrency: 4, filePaths: [] }).success).toBe(false);
});
});