import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import test from 'node:test';

const introSource = await readFile(new URL('../frontend/src/js/dc-intro.js', import.meta.url), 'utf8');
const celebrationSource = await readFile(new URL('../frontend/src/js/dc-celebration.js', import.meta.url), 'utf8');

test('intro animation guards optional GSAP access', () => {
  assert.match(introSource, /globalThis\.gsap/);
  assert.doesNotMatch(introSource, /(?<!globalThis\.)\bgsap\?\./);
});

test('celebration animation skips GSAP-only effects when GSAP is unavailable', () => {
  assert.match(celebrationSource, /globalThis\.gsap/);
  assert.match(celebrationSource, /Promise\.resolve\(\)/);
  assert.doesNotMatch(celebrationSource, /(?<!globalThis\.)\bgsap\.(set|to)/);
});
