new-listing-readiness.spec.ts (4282B)
1 import { expect, test } from '@playwright/test'; 2 import { build } from 'vite'; 3 import { fileURLToPath } from 'node:url'; 4 import { createStaticHarness } from '../integration/harness/static.ts'; 5 import type * as Fixture from './harness/new-listing-readiness.ts'; 6 declare global { 7 interface Window { 8 hcp109: typeof Fixture; 9 hcp109Fixture: Awaited<ReturnType<typeof Fixture.createFixture>>; 10 } 11 } 12 let server: Awaited<ReturnType<typeof createStaticHarness>>, bundle: string; 13 test.beforeAll(async () => { 14 server = await createStaticHarness(); 15 const result = await build({ 16 configFile: false, 17 logLevel: 'silent', 18 build: { 19 write: false, 20 minify: false, 21 lib: { 22 entry: fileURLToPath( 23 new URL('./harness/new-listing-readiness.ts', import.meta.url) 24 ), 25 name: 'hcp109', 26 formats: ['iife'] 27 } 28 } 29 }); 30 const output = Array.isArray(result) ? result[0] : result; 31 if (!('output' in output)) throw Error('fixture bundle missing'); 32 const chunks = output.output.filter((row) => row.type === 'chunk'); 33 expect(chunks).toHaveLength(1); 34 bundle = chunks[0].code; 35 }); 36 test.afterAll(async () => server.close()); 37 test.beforeEach(async ({ page }) => { 38 await page.goto(server.url + '/search'); 39 await page.addScriptTag({ content: bundle }); 40 }); 41 test.afterEach(async ({ page }) => { 42 if (!page.isClosed()) 43 await page.evaluate(() => window.hcp109Fixture?.close()); 44 }); 45 for (const mode of ['guest', 'signing_only', 'compatible_unqualified'] as const) 46 test( 47 'HCP109 actual unfinished IndexedDB draft saves while new-listing review is blocked: ' + 48 mode, 49 async ({ page }) => { 50 await page.evaluate(async (mode) => { 51 window.hcp109Fixture = await window.hcp109.createFixture(mode); 52 }, mode); 53 const before = await page.evaluate(() => window.hcp109Fixture.snapshot()); 54 expect(before.readiness).toMatchObject({ 55 draft: true, 56 readyToReview: false, 57 preferenceWrite: 'not_requested' 58 }); 59 expect(before.captured).toBe(false); 60 expect(before.current).toBe(false); 61 const actual = await page.evaluate(() => window.hcp109Fixture.save()); 62 expect(actual.saved).toBe(true); 63 expect(actual.snapshot?.state).toBe('saved'); 64 expect(actual.snapshot?.draft?.form).toMatchObject({ 65 title: '', 66 amount: '.', 67 description: 'unfinished local public description' 68 }); 69 expect(actual.rows.ok).toBe(true); 70 if (!actual.rows.ok) throw Error(actual.rows.reason); 71 expect(actual.rows.value).toHaveLength(1); 72 expect(actual.rows.value[0]).toEqual(actual.snapshot?.draft); 73 expect(actual.counts).toEqual(actual.baseline); 74 expect(actual.counts.signs).toBe(0); 75 } 76 ); 77 test('HCP109 qualified existing signed inbox admits original review with no redundant preference write or signature', async ({ 78 page 79 }) => { 80 await page.evaluate(async () => { 81 window.hcp109Fixture = await window.hcp109.createFixture('qualified'); 82 }); 83 const actual = await page.evaluate(() => window.hcp109Fixture.snapshot()); 84 expect(actual.readiness.readyToReview).toBe(true); 85 expect(actual.captured).toBe(true); 86 expect(actual.current).toBe(true); 87 expect(actual.counts).toEqual(actual.baseline); 88 expect(actual.counts.signs).toBe(0); 89 expect(await page.evaluate(() => window.hcp109Fixture.copies())).toEqual({ 90 copiedSetup: false, 91 copiedProof: false, 92 genuine: true 93 }); 94 }); 95 test('HCP109 original Stop revokes held new-listing proof while incomplete draft remains saveable', async ({ 96 page 97 }) => { 98 await page.evaluate(async () => { 99 window.hcp109Fixture = await window.hcp109.createFixture('qualified'); 100 }); 101 expect( 102 (await page.evaluate(() => window.hcp109Fixture.snapshot())).current 103 ).toBe(true); 104 await page.evaluate(() => window.hcp109Fixture.stop()); 105 const stopped = await page.evaluate(() => window.hcp109Fixture.snapshot()); 106 expect(stopped.current).toBe(false); 107 expect(stopped.readiness.readyToReview).toBe(false); 108 const saved = await page.evaluate(() => window.hcp109Fixture.save()); 109 expect(saved.saved).toBe(true); 110 expect(saved.rows.ok).toBe(true); 111 expect(saved.counts.signs).toBe(0); 112 expect(saved.counts).toEqual(saved.baseline); 113 });