app

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

privacy-output.spec.ts (3192B)


      1 import { expect, test } from '@playwright/test';
      2 import { encodeProductReference } from '../../src/lib/nostr/references.ts';
      3 import { createStaticHarness } from '../integration/harness/static.ts';
      4 
      5 test('HCP128 actual Messages SSR describes the connection and unlock condition', async ({
      6   request
      7 }) => {
      8   const server = await createStaticHarness();
      9   try {
     10     const response = await request.get(server.url + '/messages', {
     11       headers: { Accept: 'text/html' }
     12     });
     13     expect(response.status()).toBe(200);
     14     const html = await response.text();
     15     expect(html).toContain(
     16       'Messages stay hidden until you connect and explicitly unlock your inbox.'
     17     );
     18     expect(html).not.toContain('unavailable during development');
     19   } finally {
     20     await server.close();
     21   }
     22 });
     23 
     24 test('HCP128 real private routes keep generic noindex metadata through hydration and reload without extension effects', async ({
     25   page
     26 }) => {
     27   const coordinate = encodeProductReference({
     28     kind: 30402,
     29     pubkey: '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
     30     identifier: 'HCP128_TEST_ONLY_PUBLIC_COORDINATE'
     31   });
     32   expect(coordinate).toBeTruthy();
     33   const handle = '12345678-1234-4234-8234-123456789abc';
     34   // Generic means independent of private content or peer identity. The
     35   // approved editor uses finite route-mode labels, not a product-only title.
     36   const paths = [
     37     ['/messages', 'HarvestCircle'],
     38     ['/messages/' + handle, 'HarvestCircle'],
     39     ['/sell', 'New listing · HarvestCircle'],
     40     ['/selling', 'HarvestCircle'],
     41     ['/selling/drafts/' + handle, 'Continue draft · HarvestCircle'],
     42     ['/products/' + coordinate + '/edit', 'Edit listing · HarvestCircle']
     43   ] as const;
     44   const server = await createStaticHarness();
     45   const errors: string[] = [];
     46   const external: string[] = [];
     47   page.on('pageerror', (error) => errors.push(error.message));
     48   try {
     49     await page.route('**/*', (route) => {
     50       if (new URL(route.request().url()).origin === server.url)
     51         return route.continue();
     52       external.push(route.request().url());
     53       return route.abort();
     54     });
     55     await page.addInitScript(() => {
     56       Object.defineProperty(window, 'nostr', {
     57         configurable: true,
     58         get() {
     59           throw Error('HCP128 unrequested extension access');
     60         }
     61       });
     62     });
     63     for (const [pathname, title] of paths) {
     64       for (const navigate of [
     65         () => page.goto(server.url + pathname),
     66         () => page.reload()
     67       ]) {
     68         expect((await navigate())?.status()).toBe(200);
     69         await expect(
     70           page
     71             .getByRole('navigation', { name: 'Primary' })
     72             .getByRole('button', { name: 'Connect extension', exact: true })
     73         ).toBeEnabled();
     74         await expect(page).toHaveTitle(title);
     75         await expect(page.locator('meta[name="robots"]')).toHaveAttribute(
     76           'content',
     77           'noindex'
     78         );
     79         expect(new URL(page.url()).pathname).toBe(pathname);
     80         expect(new URL(page.url()).search + new URL(page.url()).hash).toBe('');
     81       }
     82     }
     83     expect(errors).toEqual([]);
     84     expect(external).toEqual([]);
     85   } finally {
     86     await server.close();
     87   }
     88 });