import { buildColInfoHtml } from './col-info-html'
import { DataFormat } from '../../models/sas/common/DateFormat'

describe('buildColInfoHtml', () => {
  it('returns "No info found" when colInfo is undefined', () => {
    expect(buildColInfoHtml('SOME_CHAR', undefined)).toBe('No info found')
  })

  it('renders NAME first, then LABEL/TYPE/LENGTH/FORMAT', () => {
    const colInfo: DataFormat = {
      label: 'Some Character Column',
      type: 'char',
      length: '1024',
      format: '$1024.'
    }

    expect(buildColInfoHtml('SOME_CHAR', colInfo)).toBe(
      'NAME: SOME_CHAR<br>LABEL: Some Character Column<br>TYPE: char<br>LENGTH: 1024<br>FORMAT: $1024.'
    )
  })

  it('appends a REGEX line when only a HARDREGEX value is provided', () => {
    const colInfo: DataFormat = {
      label: 'Some Character Column',
      type: 'char',
      length: '1024',
      format: '$1024.'
    }

    expect(
      buildColInfoHtml('SOME_CHAR', colInfo, '/^[A-Z]+$/i', undefined)
    ).toBe(
      'NAME: SOME_CHAR<br>LABEL: Some Character Column<br>TYPE: char<br>LENGTH: 1024<br>FORMAT: $1024.<br>REGEX: /^[A-Z]+$/i'
    )
  })

  it('appends a REGEX line when only a SOFTREGEX value is provided', () => {
    const colInfo: DataFormat = {
      label: 'Some Character Column',
      type: 'char',
      length: '1024',
      format: '$1024.'
    }

    expect(
      buildColInfoHtml('SOME_CHAR', colInfo, undefined, '/^[a-z]+$/')
    ).toBe(
      'NAME: SOME_CHAR<br>LABEL: Some Character Column<br>TYPE: char<br>LENGTH: 1024<br>FORMAT: $1024.<br>REGEX: /^[a-z]+$/'
    )
  })

  it('appends separate HARDREGEX/SOFTREGEX lines when a column has both', () => {
    const colInfo: DataFormat = {
      label: 'Some Character Column',
      type: 'char',
      length: '1024',
      format: '$1024.'
    }

    expect(
      buildColInfoHtml('SOME_CHAR', colInfo, '/^[A-Z]+$/i', '/^.{5,10}$/')
    ).toBe(
      'NAME: SOME_CHAR<br>LABEL: Some Character Column<br>TYPE: char<br>LENGTH: 1024<br>FORMAT: $1024.<br>HARDREGEX: /^[A-Z]+$/i<br>SOFTREGEX: /^.{5,10}$/'
    )
  })

  it('omits the REGEX line when no regex rule value is provided', () => {
    const colInfo: DataFormat = {
      label: 'Some Character Column',
      type: 'char',
      length: '1024',
      format: '$1024.'
    }

    expect(buildColInfoHtml('SOME_CHAR', colInfo)).not.toContain('REGEX:')
  })
})
