import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';

const fixtureDir = resolve('tests/fixtures/page-editor');

function readFixture(name) {
  return JSON.parse(readFileSync(resolve(fixtureDir, name), 'utf8'));
}

function assertSectionProp(prop, expectedType = 'static') {
  assert.equal(typeof prop, 'object');
  assert.equal(prop.type, expectedType);
  assert.ok('value' in prop || 'source' in prop);
}

describe('page editor fixtures', () => {
  it('uses canonical feature-grid.items for v1 fixtures', () => {
    const fixture = readFixture('feature-grid-v1.json');
    const section = fixture.sections[0];

    assert.equal(fixture.schemaVersion, 1);
    assert.equal(section.type, 'feature-grid');
    assertSectionProp(section.props.heading);
    assertSectionProp(section.props.items);
    assert.ok(Array.isArray(section.props.items.value));
    assert.equal(section.props.features, undefined);
  });

  it('keeps a legacy feature-grid.features fixture for migration coverage', () => {
    const fixture = readFixture('feature-grid-legacy-features.json');
    const section = fixture.sections[0];

    assert.equal(fixture.schemaVersion, 0);
    assert.equal(section.type, 'feature-grid');
    assertSectionProp(section.props.heading);
    assertSectionProp(section.props.features);
    assert.ok(Array.isArray(section.props.features.value));
  });
});
