app

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

listing-editor.spec.ts (24476B)


      1 import type { PublicDraftRecord } from '../../src/lib/contracts/local-records.ts';
      2 import { expect, test } from '@playwright/test';
      3 import { build } from 'vite';
      4 import { svelte } from '@sveltejs/vite-plugin-svelte';
      5 import { fileURLToPath } from 'node:url';
      6 import { createStaticHarness } from '../integration/harness/static.ts';
      7 import type * as Fixture from './harness/listing-editor.ts';
      8 declare global {
      9   interface Window {
     10     hcp115: typeof Fixture;
     11     hcp115Fixture: Awaited<ReturnType<typeof Fixture.createFixture>>;
     12     hcp115Observation: ReturnType<typeof Fixture.nativeObservation>;
     13     hcp115Pending: Promise<unknown>;
     14   }
     15 }
     16 let server: Awaited<ReturnType<typeof createStaticHarness>>, bundle: string;
     17 const partial = {
     18   title: 'Unfinished local product',
     19   description: '  Retain exact lines\n',
     20   location: '',
     21   amount: '2,50',
     22   currency: '',
     23   unit: 'kg',
     24   quantity: '03',
     25   contactType: '',
     26   contactValue: ''
     27 } as const;
     28 test.beforeAll(async () => {
     29   server = await createStaticHarness();
     30   const built = await build({
     31     configFile: false,
     32     plugins: [svelte({ configFile: false })],
     33     resolve: { conditions: ['browser'] },
     34     logLevel: 'silent',
     35     build: {
     36       write: false,
     37       minify: false,
     38       lib: {
     39         entry: fileURLToPath(
     40           new URL('./harness/listing-editor.ts', import.meta.url)
     41         ),
     42         name: 'hcp115',
     43         formats: ['iife']
     44       }
     45     }
     46   });
     47   const output = Array.isArray(built) ? built[0] : built;
     48   if (!('output' in output)) throw Error('actual bundle missing');
     49   const chunks = output.output.filter((row) => row.type === 'chunk');
     50   expect(chunks).toHaveLength(1);
     51   bundle = chunks[0].code;
     52 });
     53 test.afterAll(async () => {
     54   await server?.close();
     55 });
     56 test.beforeEach(async ({ page }) => {
     57   await page.addInitScript(() => {
     58     window.WebSocket = class extends WebSocket {
     59       constructor() {
     60         super(
     61           (() => {
     62             throw Error('HCP115 source assertions authorize no relay traffic');
     63           })()
     64         );
     65       }
     66     };
     67   });
     68   await page.goto(server.url + '/search');
     69   await page.addScriptTag({ content: bundle });
     70   await page.evaluate(async () => {
     71     window.hcp115Fixture = await window.hcp115.createFixture();
     72   });
     73 });
     74 test.afterEach(async ({ page }) => {
     75   await page.evaluate(async () => {
     76     window.hcp115Observation?.restore();
     77     await window.hcp115Fixture?.close();
     78   });
     79 });
     80 test('new GET hydrates nine empty strings without creating a draft or requesting a signature', async ({
     81   page
     82 }) => {
     83   const result = await page.evaluate(async () => {
     84     const f = window.hcp115Fixture;
     85     const before = f.counts();
     86     const opened = await f.open({ mode: 'new' });
     87     return { opened, rows: await f.inspect(), before, after: f.counts() };
     88   });
     89   expect(result.opened.status).toBe('ready');
     90   if (result.opened.status !== 'ready') return;
     91   expect(result.opened.snapshot?.form).toEqual({
     92     title: '',
     93     description: '',
     94     location: '',
     95     amount: '',
     96     currency: '',
     97     unit: '',
     98     quantity: '',
     99     contactType: '',
    100     contactValue: ''
    101   });
    102   expect(result.opened.snapshot?.draftId).toBeNull();
    103   expect(result.rows.drafts).toHaveLength(0);
    104   expect(result.after).toEqual(result.before);
    105 });
    106 test('sign-only owner saves incomplete exact strings without messaging admission or invalid paint', async ({
    107   page
    108 }) => {
    109   await page.evaluate(async () => {
    110     await window.hcp115Fixture.render({ mode: 'new' });
    111   });
    112   await expect(page.locator('#hcp115-editor form')).toBeVisible();
    113   await page.getByLabel('Product name', { exact: true }).fill(partial.title);
    114   await page.getByLabel('Price', { exact: true }).fill(partial.amount);
    115   await page.getByLabel('Per', { exact: true }).selectOption('kg');
    116   await page
    117     .getByLabel('Advertised quantity (optional)', { exact: true })
    118     .fill('03');
    119   await expect(
    120     page.getByText('Saved in this browser.', { exact: true })
    121   ).toBeVisible();
    122   const actual = await page.evaluate(async () => ({
    123     rows: await window.hcp115Fixture.inspect(),
    124     identity: window.hcp115Fixture.identity(),
    125     counts: window.hcp115Fixture.counts()
    126   }));
    127   const rows = actual.rows.drafts as { wire: string }[];
    128   expect(rows).toHaveLength(1);
    129   expect((JSON.parse(rows[0].wire) as PublicDraftRecord).form).toMatchObject({
    130     title: partial.title,
    131     amount: '2,50',
    132     currency: '',
    133     unit: 'kg',
    134     quantity: '03'
    135   });
    136   expect(actual.counts.signs).toBe(0);
    137   await expect(
    138     page.locator('#hcp115-editor [aria-invalid="true"]')
    139   ).toHaveCount(0);
    140 });
    141 test('resume opens the exact original incomplete draft without replacement or validation paint', async ({
    142   page
    143 }) => {
    144   const id = await page.evaluate(async (form) => {
    145     const f = window.hcp115Fixture;
    146     await f.open({ mode: 'new' });
    147     if (!(await f.edit(form))) throw Error('actual partial save failed');
    148     return f.snapshot()?.draftId;
    149   }, partial);
    150   expect(id).toBeTruthy();
    151   const result = await page.evaluate(async (id) => {
    152     const f = window.hcp115Fixture;
    153     const before = await f.inspect();
    154     const opened = await f.open({ mode: 'draft', draftId: id! });
    155     await f.render({ mode: 'draft', draftId: id! });
    156     return { before, opened, after: await f.inspect() };
    157   }, id);
    158   expect(result.opened.status).toBe('ready');
    159   if (result.opened.status === 'ready')
    160     expect(result.opened.snapshot?.form).toEqual(partial);
    161   expect(result.after).toEqual(result.before);
    162   await expect(page.locator('#hcp115-editor form')).toBeVisible();
    163   await expect(
    164     page.locator('#hcp115-editor [aria-invalid="true"]')
    165   ).toHaveCount(0);
    166 });
    167 test('all three modes share mandatory fields and optional public contact without SKU image or shipping', async ({
    168   page
    169 }) => {
    170   const prototype = await page.evaluate(
    171     async () => await window.hcp115Fixture.prototype()
    172   );
    173   for (const route of [
    174     { mode: 'new' } as const,
    175     { mode: 'draft', draftId: prototype.draftId } as const,
    176     { mode: 'edit', naddr: prototype.naddr } as const
    177   ]) {
    178     await page.evaluate(async (route) => {
    179       await window.hcp115Fixture.render(route);
    180     }, route);
    181     await expect(page.locator('#hcp115-editor form')).toBeVisible();
    182     await expect(
    183       page.locator(
    184         '#hcp115-editor input, #hcp115-editor textarea, #hcp115-editor select'
    185       )
    186     ).toHaveCount(9);
    187     await expect(
    188       page.getByLabel('Product name', { exact: true })
    189     ).toBeVisible();
    190     await expect(page.getByLabel('Public area', { exact: true })).toBeVisible();
    191     await expect(page.getByLabel('Price', { exact: true })).toHaveAttribute(
    192       'type',
    193       'text'
    194     );
    195     await page
    196       .getByText('Add public contact details (optional)', { exact: true })
    197       .click();
    198     await expect(
    199       page.getByText('Only add contact details you want to include publicly.', {
    200         exact: true
    201       })
    202     ).toBeVisible();
    203     await expect(page.locator('#hcp115-editor')).not.toContainText(
    204       /SKU|shipping/i
    205     );
    206     await expect(
    207       page.locator(
    208         '#hcp115-editor input[type="file"],#hcp115-editor img,[aria-invalid="true"]'
    209       )
    210     ).toHaveCount(0);
    211   }
    212 });
    213 test('edit hydrates only genuine exact original source values and remains read-only without effects', async ({
    214   page
    215 }) => {
    216   const result = await page.evaluate(async () => {
    217     const f = window.hcp115Fixture,
    218       p = await f.prototype(),
    219       before = await f.inspect(),
    220       counts = f.counts();
    221     const opened = await f.open({ mode: 'edit', naddr: p.naddr });
    222     const edit = await f.edit(window.hcp115.blank()),
    223       flush = await f.flush();
    224     return {
    225       p,
    226       before,
    227       opened,
    228       edit,
    229       flush,
    230       after: await f.inspect(),
    231       counts,
    232       afterCounts: f.counts()
    233     };
    234   });
    235   expect(result.opened.status).toBe('ready');
    236   if (result.opened.status === 'ready') {
    237     expect(result.opened.snapshot?.editable).toBe(false);
    238     expect(result.opened.snapshot?.sourceEventId).toBe(result.p.eventId);
    239     const native = result.before.drafts as { wire: string }[];
    240     const source = native
    241       .map((row) => JSON.parse(row.wire) as PublicDraftRecord)
    242       .find((row) => row.id === result.p.draftId);
    243     if (!source) throw Error('actual original source draft missing');
    244     expect(result.opened.snapshot?.form).toEqual(source.form);
    245   }
    246   expect(result.edit).toBe(false);
    247   expect(result.flush).toBe(false);
    248   expect(result.after).toEqual(result.before);
    249   expect(result.afterCounts).toEqual(result.counts);
    250 });
    251 for (const damage of [
    252   'advanced',
    253   'deleted',
    254   'mismatched',
    255   'ambiguous',
    256   'external'
    257 ] as const)
    258   test(`edit refuses ${damage} original source without capture inversion or data reset`, async ({
    259     page
    260   }) => {
    261     const result = await page.evaluate(async (damage) => {
    262       const f = window.hcp115Fixture,
    263         p = await f.prototype();
    264       await f.damageSource(damage, p.draftId);
    265       const before = await f.inspect(),
    266         counts = f.counts(),
    267         opened = await f.open({ mode: 'edit', naddr: p.naddr });
    268       return {
    269         before,
    270         opened,
    271         after: await f.inspect(),
    272         counts,
    273         afterCounts: f.counts()
    274       };
    275     }, damage);
    276     expect(result.opened).toEqual({ status: 'unavailable', reason: 'source' });
    277     expect(result.after).toEqual(result.before);
    278     expect(result.afterCounts).toEqual(result.counts);
    279   });
    280 test('foreign edit author is rejected before native opening or hydration', async ({
    281   page
    282 }) => {
    283   const actual = await page.evaluate(async () => {
    284     window.hcp115Observation = window.hcp115.nativeObservation();
    285     return {
    286       result: await window.hcp115Fixture.open({
    287         mode: 'edit',
    288         naddr: window.hcp115.reference('foreign')!
    289       }),
    290       native: window.hcp115Observation.state()
    291     };
    292   });
    293   expect(actual.result).toEqual({ status: 'unavailable', reason: 'resource' });
    294   expect(actual.native).toMatchObject({ opens: 0, gets: 0, puts: 0 });
    295 });
    296 test('missing original draft never creates a replacement', async ({ page }) => {
    297   const actual = await page.evaluate(async () => ({
    298     result: await window.hcp115Fixture.open({
    299       mode: 'draft',
    300       draftId: crypto.randomUUID()
    301     }),
    302     rows: await window.hcp115Fixture.inspect()
    303   }));
    304   expect(actual.result.status).toBe('unavailable');
    305   expect(actual.rows.drafts).toHaveLength(0);
    306 });
    307 test('copied editor cannot subscribe close save or flush while original remains usable', async ({
    308   page
    309 }) => {
    310   const actual = await page.evaluate(async (form) => {
    311     const f = window.hcp115Fixture;
    312     await f.open({ mode: 'new' });
    313     const copied = await f.edit(form, true),
    314       flush = await f.flush(true),
    315       calls = f.copiedSubscribe();
    316     f.copiedClose();
    317     const before = await f.inspect(),
    318       alive = !!f.snapshot(),
    319       original = await f.edit(form);
    320     return {
    321       copied,
    322       flush,
    323       calls,
    324       before,
    325       alive,
    326       original,
    327       after: await f.inspect()
    328     };
    329   }, partial);
    330   expect(actual).toMatchObject({
    331     copied: false,
    332     flush: false,
    333     calls: 0,
    334     alive: true,
    335     original: true
    336   });
    337   expect(actual.before.drafts).toHaveLength(0);
    338   expect(actual.after.drafts).toHaveLength(1);
    339 });
    340 test('malformed route and copied identity are rejected before native opening', async ({
    341   page
    342 }) => {
    343   const actual = await page.evaluate(async () => {
    344     window.hcp115Observation = window.hcp115.nativeObservation();
    345     const f = window.hcp115Fixture;
    346     return {
    347       malformed: await f.open({ mode: 'draft', draftId: '../other' }),
    348       copied: await f.open({ mode: 'new' }, true),
    349       native: window.hcp115Observation.state()
    350     };
    351   });
    352   expect(actual.malformed.status).toBe('unavailable');
    353   expect(actual.copied).toEqual({ status: 'unavailable', reason: 'owner' });
    354   expect(actual.native).toMatchObject({ opens: 0, gets: 0, puts: 0 });
    355 });
    356 test('logout hides protected mounted values and retains original native draft bytes', async ({
    357   page
    358 }) => {
    359   await page.evaluate(async () => {
    360     await window.hcp115Fixture.render({ mode: 'new' });
    361   });
    362   await expect(page.locator('#hcp115-editor form')).toBeVisible();
    363   await page
    364     .getByLabel('Product name', { exact: true })
    365     .fill('Private unfinished input');
    366   await expect(
    367     page.getByText('Saved in this browser.', { exact: true })
    368   ).toBeVisible();
    369   const before = await page.evaluate(
    370     async () => await window.hcp115Fixture.inspect()
    371   );
    372   await page.evaluate(() => window.hcp115Fixture.disconnect());
    373   await expect(page.locator('#hcp115-editor form')).toHaveCount(0);
    374   await expect(page.locator('#hcp115-editor')).not.toContainText(
    375     'Private unfinished input'
    376   );
    377   expect(
    378     await page.evaluate(async () => await window.hcp115Fixture.inspect())
    379   ).toEqual(before);
    380 });
    381 test('cancel during genuine open completion closes the late connection before protected hydration', async ({
    382   page
    383 }) => {
    384   await page.evaluate(() => {
    385     window.hcp115Observation = window.hcp115.nativeObservation();
    386     window.hcp115Observation.holdOpen();
    387     window.hcp115Pending = window.hcp115Fixture.open({ mode: 'new' });
    388   });
    389   await expect
    390     .poll(
    391       async () =>
    392         await page.evaluate(() => window.hcp115Observation.state().held)
    393     )
    394     .toBe(true);
    395   await page.evaluate(() => {
    396     window.hcp115Fixture.cancel();
    397     window.hcp115Observation.release();
    398   });
    399   const result = await page.evaluate(async () => ({
    400     result: await window.hcp115Pending,
    401     native: window.hcp115Observation.state(),
    402     snapshot: window.hcp115Fixture.snapshot()
    403   }));
    404   expect(result.result).toMatchObject({ status: 'unavailable' });
    405   expect(result.native).toMatchObject({
    406     opens: 1,
    407     closes: 1,
    408     gets: 0,
    409     puts: 0,
    410     completions: 1
    411   });
    412   expect(result.snapshot).toBeUndefined();
    413 });
    414 test('cancellation between original open resolution and await custody closes the actual ready owner', async ({
    415   page
    416 }) => {
    417   const result = await page.evaluate(async () => {
    418     window.hcp115Observation = window.hcp115.nativeObservation();
    419     window.hcp115Observation.afterOpen(() => window.hcp115Fixture.cancel());
    420     return {
    421       result: await window.hcp115Fixture.open({ mode: 'new' }),
    422       native: window.hcp115Observation.state()
    423     };
    424   });
    425   expect(result.result).toMatchObject({ status: 'unavailable' });
    426   expect(result.native).toMatchObject({
    427     opens: 1,
    428     closes: 1,
    429     gets: 0,
    430     puts: 0,
    431     completions: 1
    432   });
    433 });
    434 test('cancel after original draft native read completion retires the late controller without writes', async ({
    435   page
    436 }) => {
    437   const id = await page.evaluate(async (form) => {
    438     const f = window.hcp115Fixture;
    439     await f.open({ mode: 'new' });
    440     await f.edit(form);
    441     return f.snapshot()?.draftId;
    442   }, partial);
    443   await page.evaluate((id) => {
    444     window.hcp115Observation = window.hcp115.nativeObservation();
    445     window.hcp115Observation.holdDraft();
    446     window.hcp115Pending = window.hcp115Fixture.open({
    447       mode: 'draft',
    448       draftId: id!
    449     });
    450   }, id);
    451   await expect
    452     .poll(
    453       async () =>
    454         await page.evaluate(() => window.hcp115Observation.state().held)
    455     )
    456     .toBe(true);
    457   await page.evaluate(() => {
    458     window.hcp115Fixture.cancel();
    459     window.hcp115Observation.release();
    460   });
    461   const result = await page.evaluate(async () => ({
    462     result: await window.hcp115Pending,
    463     native: window.hcp115Observation.state(),
    464     snapshot: window.hcp115Fixture.snapshot()
    465   }));
    466   expect(result.result).toMatchObject({ status: 'unavailable' });
    467   expect(result.native.gets).toBeGreaterThan(0);
    468   expect(result.native.puts).toBe(0);
    469   expect(result.native.closes).toBeGreaterThan(0);
    470   expect(result.snapshot).toBeUndefined();
    471 });
    472 test('superseded pending acquisition cannot replace or retire the newer editor', async ({
    473   page
    474 }) => {
    475   await page.evaluate(() => {
    476     window.hcp115Observation = window.hcp115.nativeObservation();
    477     window.hcp115Observation.holdOpen();
    478     window.hcp115Pending = window.hcp115Fixture.open({ mode: 'new' });
    479   });
    480   await expect
    481     .poll(
    482       async () =>
    483         await page.evaluate(() => window.hcp115Observation.state().held)
    484     )
    485     .toBe(true);
    486   const newer = await page.evaluate(
    487     async () => await window.hcp115Fixture.open({ mode: 'new' })
    488   );
    489   expect(newer.status).toBe('ready');
    490   await page.evaluate(() => window.hcp115Observation.release());
    491   const actual = await page.evaluate(async () => ({
    492     old: await window.hcp115Pending,
    493     current: window.hcp115Fixture.snapshot(),
    494     native: window.hcp115Observation.state()
    495   }));
    496   expect(actual.old).toMatchObject({ status: 'unavailable' });
    497   expect(actual.current?.editable).toBe(true);
    498   expect(actual.native.puts).toBe(0);
    499   expect(actual.native.closes).toBeGreaterThan(0);
    500 });
    501 test('component unmount cancels genuine pending acquisition before late resources arrive', async ({
    502   page
    503 }) => {
    504   await page.evaluate(async () => {
    505     window.hcp115Observation = window.hcp115.nativeObservation();
    506     window.hcp115Observation.holdOpen();
    507     await window.hcp115Fixture.render({ mode: 'new' });
    508   });
    509   await expect
    510     .poll(
    511       async () =>
    512         await page.evaluate(() => window.hcp115Observation.state().held)
    513     )
    514     .toBe(true);
    515   await page.evaluate(async () => {
    516     await window.hcp115Fixture.unmount();
    517     window.hcp115Observation.release();
    518   });
    519   await expect
    520     .poll(
    521       async () =>
    522         await page.evaluate(() => window.hcp115Observation.state().closes)
    523     )
    524     .toBe(1);
    525   await expect(page.locator('#hcp115-editor')).toHaveCount(0);
    526   expect(await page.evaluate(() => window.hcp115Observation.state().puts)).toBe(
    527     0
    528   );
    529 });
    530 test('genuine submitted save shows Saving and late acknowledgment cannot repaint after unmount', async ({
    531   page
    532 }) => {
    533   await page.evaluate(
    534     async () => await window.hcp115Fixture.render({ mode: 'new' })
    535   );
    536   await expect(page.locator('#hcp115-editor form')).toBeVisible();
    537   await page.evaluate(() => {
    538     window.hcp115Observation = window.hcp115.nativeObservation();
    539     window.hcp115Observation.holdSave();
    540   });
    541   await page
    542     .getByLabel('Product name', { exact: true })
    543     .fill('Actual submitted native partial draft');
    544   await expect
    545     .poll(
    546       async () =>
    547         await page.evaluate(() => window.hcp115Observation.state().held)
    548     )
    549     .toBe(true);
    550   await expect(
    551     page.getByText('Saving in this browser.', { exact: true })
    552   ).toBeVisible();
    553   await page.evaluate(async () => {
    554     await window.hcp115Fixture.unmount();
    555     window.hcp115Observation.release();
    556   });
    557   await expect(page.locator('#hcp115-editor')).toHaveCount(0);
    558   const actual = await page.evaluate(async () => ({
    559     rows: await window.hcp115Fixture.inspect(),
    560     native: window.hcp115Observation.state()
    561   }));
    562   expect(actual.rows.drafts).toHaveLength(1);
    563   expect(
    564     (
    565       JSON.parse(
    566         (actual.rows.drafts[0] as { wire: string }).wire
    567       ) as PublicDraftRecord
    568     ).form.title
    569   ).toBe('Actual submitted native partial draft');
    570   expect(actual.native.puts).toBe(1);
    571 });
    572 test('actual compiled guest routes never hydrate protected listing fields or connect implicitly', async ({
    573   page
    574 }) => {
    575   const naddr = await page.evaluate(() => window.hcp115.reference('guest')!);
    576   for (const route of [
    577     '/sell',
    578     '/selling/drafts/' + crypto.randomUUID(),
    579     '/products/' + naddr + '/edit'
    580   ]) {
    581     await page.goto(server.url + route);
    582     await expect(page.locator('main h1')).toBeVisible();
    583     await expect(page.locator('main form')).toHaveCount(0);
    584     await expect(
    585       page
    586         .getByRole('button', { name: 'Connect extension', exact: true })
    587         .last()
    588     ).toBeVisible();
    589   }
    590 });
    591 test('actual compiled connected routes share original new draft and read-only edit hydration', async ({
    592   page
    593 }) => {
    594   const prototype = await page.evaluate(
    595     async () => await window.hcp115Fixture.prototype()
    596   );
    597   async function navigate(path: string) {
    598     await page.evaluate((path) => {
    599       const anchor = document.createElement('a');
    600       anchor.href = path;
    601       anchor.textContent = 'HCP115 controlled local route';
    602       anchor.id = 'hcp115-route-link';
    603       document.body.append(anchor);
    604     }, path);
    605     await page.locator('#hcp115-route-link').click();
    606     await expect(page).toHaveURL(server.url + path);
    607     await page.evaluate(() =>
    608       document.querySelector('#hcp115-route-link')?.remove()
    609     );
    610   }
    611   await navigate('/sell');
    612   await page
    613     .getByRole('button', { name: 'Connect extension', exact: true })
    614     .last()
    615     .click();
    616   await expect(page.locator('main form')).toBeVisible();
    617   await expect(
    618     page.locator('main input,main textarea,main select')
    619   ).toHaveCount(9);
    620   await expect(page.getByLabel('Product name', { exact: true })).toHaveValue(
    621     ''
    622   );
    623   await page
    624     .getByLabel('Product name', { exact: true })
    625     .fill('Compiled partial route value');
    626   await expect(
    627     page.getByText('Saved in this browser.', { exact: true })
    628   ).toBeVisible();
    629   const native = await page.evaluate(
    630     async () => await window.hcp115.inspectNative()
    631   );
    632   const draft = (native.drafts as { wire: string }[])
    633     .map((row) => JSON.parse(row.wire) as PublicDraftRecord)
    634     .find((row) => row.form.title === 'Compiled partial route value');
    635   expect(draft).toBeTruthy();
    636   if (!draft) throw Error('actual compiled route draft missing');
    637   await navigate('/selling/drafts/' + draft.id);
    638   await expect(page.getByLabel('Product name', { exact: true })).toHaveValue(
    639     'Compiled partial route value'
    640   );
    641   await expect(
    642     page.locator('main input,main textarea,main select')
    643   ).toHaveCount(9);
    644   await navigate('/products/' + prototype.naddr + '/edit');
    645   await expect(page.locator('main form')).toBeVisible();
    646   await expect(
    647     page.getByLabel('Product name', { exact: true })
    648   ).toHaveAttribute('readonly', '');
    649   await expect(page.getByLabel('Per', { exact: true })).toBeDisabled();
    650   await expect(
    651     page.getByText(
    652       'These retained local values are read-only until the current listing is checked.',
    653       { exact: true }
    654     )
    655   ).toBeVisible();
    656 });
    657 test('actual native versionchange retires editor instead of saving new input through a closed owner', async ({
    658   page
    659 }) => {
    660   await page.evaluate(
    661     async () => await window.hcp115Fixture.render({ mode: 'new' })
    662   );
    663   await expect(page.locator('#hcp115-editor form')).toBeVisible();
    664   await page
    665     .getByLabel('Product name', { exact: true })
    666     .fill('Persisted before native closure');
    667   await expect(
    668     page.getByText('Saved in this browser.', { exact: true })
    669   ).toBeVisible();
    670   const native = await page.evaluate(
    671     async () => await window.hcp115.nativeVersionChange()
    672   );
    673   expect(native.drafts).toHaveLength(1);
    674   await page
    675     .getByLabel('Product name', { exact: true })
    676     .fill('Must not save through closed native owner');
    677   await expect(page.locator('#hcp115-editor form')).toHaveCount(0);
    678   await expect(
    679     page.getByText(
    680       'Browser storage is unavailable. Your existing local data has not been reset.',
    681       { exact: true }
    682     )
    683   ).toBeVisible();
    684   expect(
    685     (
    686       JSON.parse(
    687         (native.drafts[0] as { wire: string }).wire
    688       ) as PublicDraftRecord
    689     ).form.title
    690   ).toBe('Persisted before native closure');
    691 });
    692 
    693 test('foreign retained draft stays unavailable to a different genuine connected author without reset', async ({
    694   page
    695 }) => {
    696   const actual = await page.evaluate(async () => {
    697     const first = window.hcp115Fixture,
    698       prototype = await first.prototype(),
    699       owner = first.owner,
    700       before = await first.inspect();
    701     await first.close();
    702     window.hcp115Fixture = await window.hcp115.createFixture();
    703     const next = window.hcp115Fixture;
    704     if (next.owner === owner)
    705       throw Error('controlled independent authors must differ');
    706     const opened = await next.open({
    707       mode: 'draft',
    708       draftId: prototype.draftId
    709     });
    710     await next.render({ mode: 'draft', draftId: prototype.draftId });
    711     return {
    712       opened,
    713       snapshot: next.snapshot(),
    714       before,
    715       after: await next.inspect(),
    716       counts: next.counts()
    717     };
    718   });
    719   expect(actual.opened.status).toBe('unavailable');
    720   expect(actual.snapshot).toBeUndefined();
    721   expect(actual.after).toEqual(actual.before);
    722   expect(actual.counts.signs).toBe(0);
    723   await expect(
    724     page.getByText('This draft is not available here.', { exact: true })
    725   ).toBeVisible();
    726   await expect(page.locator('#hcp115-editor form')).toHaveCount(0);
    727 });