import type { TransformedToken } from 'style-dictionary/types'

import { describe, expect, it } from 'vitest'

import { hasPixelUnits, hasRemUnits, isTokenUnitLocked } from './advanced.mjs'

describe('hasPixelUnits', () => {
  it('should return true if the token value contains pixel units', () => {
    const token = {
      $value: '10px',
      value: '10px',
    } as TransformedToken
    expect(hasPixelUnits(token, { usesDtcg: true })).toBeTruthy()
    expect(hasPixelUnits(token, { usesDtcg: false })).toBeTruthy()
  })

  it('should return false if the token value does not contain pixel units', () => {
    const token = {
      $value: '10rem',
      value: '10rem',
    } as TransformedToken
    expect(hasPixelUnits(token, { usesDtcg: true })).toBeFalsy()
    expect(hasPixelUnits(token, { usesDtcg: false })).toBeFalsy()
  })
})

describe('hasRemUnits', () => {
  it('should return true if the token value contains rem units', () => {
    const token = {
      $value: '10rem',
      value: '10rem',
    } as TransformedToken

    expect(hasRemUnits(token, { usesDtcg: true })).toBeTruthy()
    expect(hasRemUnits(token, { usesDtcg: false })).toBeTruthy()
  })

  it('should return false if the token value has any other unit', () => {
    const token = {
      $value: '10px',
      value: '10px',
    } as TransformedToken
    expect(hasRemUnits(token, { usesDtcg: true })).toBeFalsy()
    expect(hasRemUnits(token, { usesDtcg: false })).toBeFalsy()
  })
})

describe('isTokenUnitLocked', () => {
  it('should return true if the token has the "preserveUnits" extension', () => {
    const token = {
      $extensions: {
        preserveUnits: true,
      },
    } as unknown as TransformedToken
    const options = {}
    expect(isTokenUnitLocked(token, options)).toBeTruthy()
  })

  it('should return false if the token does not have the "preserveUnits" extension', () => {
    const token = {
      $value: '10px',
    } as TransformedToken
    const options = {}
    expect(isTokenUnitLocked(token, options)).toBeFalsy()
  })
})
