Zum Inhalt

tests/share/embedCode.test.ts

import { describe, expect, it } from 'vitest';
import { DEFAULT_PRESET } from '~/presets/builtIn';
import { embedSnippet } from '~/share/embedCode';
import { decodePreset } from '~/share/encodePreset';

describe('embedSnippet', () => {
  it('produces a <physarum-player> tag with a round-trippable token', () => {
    const snippet = embedSnippet(DEFAULT_PRESET);
    expect(snippet).toContain('<physarum-player');
    const match = snippet.match(/preset="token:([^"]+)"/);
    expect(match).not.toBeNull();
    const decoded = decodePreset(match?.[1] ?? '');
    expect(decoded?.params.agentCount).toBe(DEFAULT_PRESET.params.agentCount);
  });
  it('honours a custom bundle url', () => {
    const snippet = embedSnippet(DEFAULT_PRESET, { bundleUrl: 'https://x.test/p.js' });
    expect(snippet).toContain('src="https://x.test/p.js"');
  });
});