app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

listing-continuity.test.ts (1606B)


      1 import { expect, it } from 'vitest';
      2 import { render } from 'svelte/server';
      3 import ListingEditor from '../../src/lib/components/ListingEditor.svelte';
      4 import * as editor from '../../src/lib/publishing/listing-editor.ts';
      5 import { draftHref } from '../../src/lib/routes.ts';
      6 import type { ListingEditorRoute } from '../../src/lib/publishing/listing-editor.ts';
      7 
      8 it('HCP116 SSR never offers save-close before genuine protected owner admission', () => {
      9   for (const route of [
     10     { mode: 'new' },
     11     { mode: 'draft', draftId: '00000000-0000-4000-8000-000000000001' },
     12     { mode: 'edit', naddr: 'unsupported' }
     13   ] as ListingEditorRoute[]) {
     14     const html = render(ListingEditor, { props: { route } }).body;
     15     expect(html).toContain('Connect to continue');
     16     expect(html).not.toMatch(/Save and close|<input|<textarea|<form/);
     17   }
     18 });
     19 it('HCP116 draft href admits only canonical durable native id, never arbitrary navigation', () => {
     20   expect(draftHref('00000000-0000-4000-8000-000000000001')).toBe(
     21     '/selling/drafts/00000000-0000-4000-8000-000000000001'
     22   );
     23   for (const value of ['../selling', 'https://outside.invalid', '', {}, null])
     24     expect(draftHref(value)).toBeUndefined();
     25 });
     26 it('HCP116 copied presentation cannot gain original save-close custody', async () => {
     27   const action: unknown = Reflect.get(editor, 'saveAndCloseListingEditor');
     28   expect(typeof action).toBe('function');
     29   if (typeof action !== 'function') return;
     30   const close = action as (value: object) => Promise<boolean>;
     31   expect(await close({ mode: 'draft', editable: true, saved: true })).toBe(
     32     false
     33   );
     34 });