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

const renderSource = await readFile(new URL('../frontend/src/js/render.js', import.meta.url), 'utf8');
const electricBorderSource = await readFile(new URL('../frontend/src/js/electric-border.js', import.meta.url), 'utf8');
const stylesSource = await readFile(new URL('../frontend/src/css/styles.css', import.meta.url), 'utf8');

test('charging cards include the ElectricBorder DOM layers', () => {
  assert.match(renderSource, /electric-border/);
  assert.match(renderSource, /eb-canvas/);
  assert.match(renderSource, /eb-glow-1/);
  assert.match(renderSource, /eb-glow-2/);
  assert.match(renderSource, /eb-background-glow/);
});

test('rendering refreshes ElectricBorder after station updates and filters', () => {
  assert.match(renderSource, /initElectricBorders/);
  assert.match(renderSource, /cleanupElectricBorders/);
  assert.match(electricBorderSource, /requestAnimationFrame/);
  assert.match(electricBorderSource, /ResizeObserver/);
});

test('ElectricBorder styles are present for canvas and glow layers', () => {
  assert.match(stylesSource, /\.electric-border/);
  assert.match(stylesSource, /\.eb-canvas-container/);
  assert.match(stylesSource, /\.eb-canvas/);
  assert.match(stylesSource, /\.eb-layers/);
});

test('ElectricBorder uses a strong enough glow for online visibility', () => {
  assert.match(renderSource, /data-electric-thickness="3"/);
  assert.match(electricBorderSource, /ctx\.shadowBlur = 16/);
  assert.match(stylesSource, /border-color: rgba\(125, 249, 255, 0\.42\)/);
  assert.match(stylesSource, /opacity: 0\.48/);
});
