editor-workflow.test.ts (2352B)
1 import { expect, it } from 'vitest'; 2 import { render } from 'svelte/server'; 3 import ListingEditor from '../../src/lib/components/ListingEditor.svelte'; 4 import ListingReview from '../../src/lib/components/ListingReview.svelte'; 5 import { 6 validateEditorForm, 7 editorReviewSnapshot, 8 closeEditorReview, 9 type EditorReview 10 } from '../../src/lib/publishing/editor-workflow.ts'; 11 12 const form = { 13 title: '菜', 14 description: ' Complete\r\npublic description 菜 ', 15 location: 'Town', 16 amount: '2.5', 17 currency: 'GBP', 18 unit: 'kg', 19 quantity: '3', 20 contactType: '' as const, 21 contactValue: '' 22 }; 23 it('HCP117 validation preserves raw values and uses the exact Food writer bounds', () => { 24 const before = JSON.stringify(form); 25 expect(validateEditorForm(form)).toEqual([]); 26 expect(JSON.stringify(form)).toBe(before); 27 for (const [change, field] of [ 28 [{ title: 'x'.repeat(161) }, 'title'], 29 [{ description: ' ' }, 'description'], 30 [{ description: '菜'.repeat(6000) }, 'description'], 31 [{ amount: '2,50' }, 'amount'], 32 [{ amount: '2.50' }, 'amount'], 33 [{ quantity: '03' }, 'quantity'], 34 [{ contactValue: 'unapproved private contact' }, 'contactValue'], 35 [ 36 { contactType: 'https', contactValue: 'javascript:alert(1)' }, 37 'contactValue' 38 ] 39 ] as const) { 40 const input = { ...form, ...change }; 41 const original = JSON.stringify(input); 42 expect(validateEditorForm(input)[0]?.field).toBe(field); 43 expect(JSON.stringify(input)).toBe(original); 44 } 45 }); 46 it('HCP117 copied display values cannot mint a review or disclose a fabricated template', () => { 47 const fake = { 48 owner: 'a'.repeat(64), 49 content: 'FABRICATED_PUBLIC_REVIEW' 50 } as unknown as EditorReview; 51 expect(editorReviewSnapshot(fake)).toBeUndefined(); 52 closeEditorReview(fake); 53 const html = render(ListingReview, { 54 props: { review: fake, onedit: () => {} } 55 }).body; 56 expect(html).not.toContain('FABRICATED_PUBLIC_REVIEW'); 57 expect(html).not.toMatch(/Publish|<form|<input|<textarea/); 58 }); 59 it('HCP117 SSR connection gate exposes no protected review or inbox effects', () => { 60 const html = render(ListingEditor, { 61 props: { route: { mode: 'new' } } 62 }).body; 63 expect(html).toContain('Connect to continue'); 64 expect(html).not.toMatch( 65 /Review listing|Public review|Inbox setup|<form|<textarea|<input/ 66 ); 67 });