import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'

const currentDir = dirname(fileURLToPath(import.meta.url))

function readComponent(name) {
  return readFileSync(resolve(currentDir, name), 'utf8')
}

test('app module diagram view exposes shared editor controls', () => {
  const source = readComponent('AppModuleDiagramView.vue')

  assert.equal(source.includes('sourceMode'), true)
  assert.equal(source.includes('outlineText'), true)
  assert.equal(source.includes('layoutOptions'), true)
  assert.equal(source.includes('update:sourceMode'), true)
  assert.equal(source.includes('update:outlineText'), true)
  assert.equal(source.includes('update:layoutOptions'), true)
  assert.equal(source.includes('自动蓝图'), true)
  assert.equal(source.includes('缩进结构'), true)
  assert.equal(source.includes('标准'), true)
  assert.equal(source.includes('宽松'), true)
  assert.equal(source.includes('紧凑'), true)
  assert.equal(source.includes('横向'), true)
  assert.equal(source.includes('竖向'), true)
})

test('app module diagram view supports svg and png export from the same graph', () => {
  const source = readComponent('AppModuleDiagramView.vue')

  assert.equal(source.includes('exportSvg'), true)
  assert.equal(source.includes('exportPng'), true)
  assert.equal(source.includes('buildAppModuleExportSvg(graph.value)'), true)
  assert.equal(source.includes('saveBlob'), true)
  assert.equal(source.includes('system-module-diagram.svg'), true)
  assert.equal(source.includes('system-module-diagram.png'), true)
})

test('app module diagram view renders outline warnings next to the editor', () => {
  const source = readComponent('AppModuleDiagramView.vue')

  assert.equal(source.includes('outlineWarnings'), true)
  assert.equal(source.includes('module-warning-list'), true)
  assert.equal(source.includes('v-for="warning in outlineWarnings"'), true)
})
