import test from 'node:test'
import assert from 'node:assert/strict'
import { buildErExportSvg } from './erExport.js'

test('buildErExportSvg renders a pure SVG that can be drawn to canvas safely', () => {
  const svg = buildErExportSvg({
    width: 900,
    height: 480,
    nodes: [
      {
        id: 'student_info',
        title: 'student_info',
        comment: 'Student table',
        x: 20,
        y: 30,
        width: 260,
        height: 132,
        fields: [
          { name: 'id', comment: 'ID', primary: true, required: true },
          { name: 'department_id', comment: 'Department', primary: false, required: false }
        ]
      }
    ],
    edges: [
      {
        id: 'student_info.department_id->department.id',
        path: 'M 280 120 C 340 120, 420 120, 480 120',
        labelX: 380,
        labelY: 112,
        fieldName: 'department_id',
        inferred: true
      }
    ]
  })

  assert.match(svg, /^<\?xml version="1.0" encoding="UTF-8"\?>/)
  assert.equal(svg.includes('<foreignObject'), false)
  assert.equal(svg.includes('xmlns="http://www.w3.org/2000/svg"'), true)
  assert.equal(svg.includes('student_info'), true)
  assert.equal(svg.includes('department_id'), true)
})
