app

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

bootstrap.test.ts (2307B)


      1 import { render } from 'svelte/server';
      2 import { describe, expect, it, vi } from 'vitest';
      3 import Shell from './Shell.svelte';
      4 import { prerender, ssr } from '../../src/routes/+layout';
      5 
      6 vi.mock('$app/state', () => ({
      7   page: { url: new URL('https://ssr.invalid/') }
      8 }));
      9 
     10 describe('static guest shell', () => {
     11   it('keeps browser globals absent and enforces effect tripwires', () => {
     12     expect('window' in globalThis).toBe(false);
     13     expect('document' in globalThis).toBe(false);
     14     for (const name of ['indexedDB', 'WebSocket', 'nostr']) {
     15       expect(() => {
     16         Reflect.get(globalThis, name);
     17       }).toThrow(`SSR accessed ${name}`);
     18     }
     19     expect(() => fetch('https://invalid.example')).toThrow(
     20       'SSR attempted network access'
     21     );
     22   });
     23   it('imports and renders on the server without browser capabilities', () => {
     24     const output = render(Shell);
     25     expect(output.body).toMatch(/<a[^>]*href="\/"[^>]*>HarvestCircle<\/a>/);
     26     expect(output.head).toContain('<title>HarvestCircle</title>');
     27     expect(prerender).toBe(true);
     28     expect(ssr).toBe(true);
     29   });
     30   it('renders the shared anonymous form exactly once with an explicit search caller', () => {
     31     const html = render(Shell).body;
     32     expect(html.match(/<textarea\b/g)).toHaveLength(1);
     33     expect(html).toContain('What are you looking for?');
     34     expect(html).toContain('For example, carrots or carrots Victoria.');
     35     expect(html).toContain('rows="2"');
     36     expect(html).toMatch(/<button[^>]*type="submit"[^>]*disabled[^>]*>Search/);
     37     expect(html).toMatch(/<textarea[^>]*disabled/);
     38     expect(html).not.toContain('Search is unavailable during development.');
     39     expect(html.match(/<h1\b/g)).toHaveLength(1);
     40     expect(html).toContain('<h1>Find food</h1>');
     41   });
     42   it('composes the actual shared shell and preserves the route body without a global h1', () => {
     43     const output = render(Shell);
     44     expect(output.body).toMatch(
     45       /<main id="main-content" tabindex="-1"[^>]*>[\s\S]*<\/main>/
     46     );
     47     expect(output.body).toContain('aria-label="Primary"');
     48     expect(output.body).toContain('aria-label="Footer"');
     49     expect(output.body).toContain('Unavailable during development');
     50     expect(output.body).not.toContain('<h1>HarvestCircle');
     51     expect(output.body).not.toContain('private');
     52   });
     53 });