listing-editor.test.ts (1967B)
1 import { expect, it } from 'vitest'; 2 import { render } from 'svelte/server'; 3 import ListingEditor from '../../src/lib/components/ListingEditor.svelte'; 4 import { 5 openListingEditor, 6 listingEditorSnapshot, 7 editListingEditor, 8 flushListingEditor, 9 closeListingEditor, 10 subscribeListingEditor, 11 type ListingEditor as Editor, 12 type ListingEditorRoute 13 } from '../../src/lib/publishing/listing-editor.ts'; 14 import type { IdentityViewContext } from '../../src/lib/runtime/view-context.ts'; 15 it('HCP115 copied unmounted identity cannot admit or hydrate a protected editor', async () => { 16 expect( 17 await openListingEditor({} as IdentityViewContext, { mode: 'new' }) 18 ).toEqual({ status: 'unavailable', reason: 'owner' }); 19 }); 20 it('HCP115 copied success data cannot become an editor or borrow edit effects', async () => { 21 const copied = { 22 mode: 'new', 23 editable: true, 24 owner: '0'.repeat(64) 25 } as unknown as Editor; 26 expect(listingEditorSnapshot(copied)).toBeUndefined(); 27 expect(await editListingEditor(copied, {})).toBe(false); 28 expect(await flushListingEditor(copied)).toBe(false); 29 }); 30 it('HCP115 copied Close and subscriptions cannot retire an original owner', () => { 31 const copied = {} as Editor; 32 let calls = 0; 33 const off = subscribeListingEditor(copied, () => { 34 calls++; 35 }); 36 closeListingEditor(copied); 37 off(); 38 expect(calls).toBe(0); 39 }); 40 it('HCP115 all three SSR routes show connection before protected values or effects', () => { 41 for (const route of [ 42 { mode: 'new' }, 43 { mode: 'draft', draftId: '00000000-0000-4000-8000-000000000001' }, 44 { mode: 'edit', naddr: 'unsupported' } 45 ] as ListingEditorRoute[]) { 46 const html = render(ListingEditor, { props: { route } }).body; 47 expect(html).toContain('Connect to continue'); 48 expect(html).not.toMatch(/<input|<textarea|<form|<select/); 49 expect(html).not.toMatch( 50 /Public contact details|Saved in this browser|Account-specific draft/ 51 ); 52 } 53 });