import { test } from '@japa/runner'
import { File } from '../../../../src/index.js'

test.group('File.addLabel()', () => {
  const label = 'test-label'

  test('creates the labels array', ({ assert }) => {
    const file = new File()
    file.addLabel(label)
    assert.typeOf(file.labels, 'array')
  })

  test('adds the label to the array', ({ assert }) => {
    const file = new File()
    file.addLabel(label)
    assert.deepEqual(file.labels, [label])
  })

  test('ignores duplicates', ({ assert }) => {
    const file = new File()
    file.addLabel(label)
    file.addLabel(label)
    assert.deepEqual(file.labels, [label])
  })

  test('throws when invalid argument', ({ assert }) => {
    const file = new File()
    assert.throws(() => {
      // @ts-expect-error Undefined for testing
      file.addLabel()
    })
  })

  test('throws when empty string', ({ assert }) => {
    const file = new File()
    assert.throws(() => {
      file.addLabel('')
    })
  })

  test('throws when empty string after trimming', ({ assert }) => {
    const file = new File()
    assert.throws(() => {
      file.addLabel('    ')
    })
  })
})
