const test = require('node:test')
const assert = require('node:assert')
const { templateFromJsxBlockedReason } = require('../src/commands/template-from-jsx-shared')

test('templateFromJsxBlockedReason: *.template.tsx basename', () => {
  assert.ok(
    templateFromJsxBlockedReason('/proj/Hero.template.tsx', 'export function Hero() { return null }'),
  )
})

test('templateFromJsxBlockedReason: *.template.jsx basename', () => {
  assert.ok(templateFromJsxBlockedReason('/proj/Hero.template.jsx', 'export default function H() {}'))
})

test('templateFromJsxBlockedReason: plain component path', () => {
  assert.strictEqual(
    templateFromJsxBlockedReason('/proj/Hero.tsx', 'export function Hero() { return null }'),
    null,
  )
})

test('templateFromJsxBlockedReason: $() in source', () => {
  assert.ok(
    templateFromJsxBlockedReason(
      '/proj/Hero.tsx',
      'const t = $(title:String="x")\nexport function Hero() { return null }',
    ),
  )
})

test('templateFromJsxBlockedReason: Hero.tsx without $()', () => {
  assert.strictEqual(
    templateFromJsxBlockedReason('/proj/Hero.tsx', 'const x = 1\nexport function Hero() { return x }'),
    null,
  )
})
