import { describe, expect, test, vi } from 'vitest'

vi.mock('@/api', () => ({
  uploadFile: vi.fn(),
}))

vi.mock('notivue', () => ({
  push: {
    error: vi.fn(),
  },
}))

import { appendImageUrl, removeImageUrl, toImageList } from '@/hooks/useUploadImg'

describe('hook 辅助函数：useUploadImg', () => {
  test('toImageList 能统一处理字符串和数组格式的图片值', () => {
    expect(toImageList('a,,b,')).toEqual(['a', 'b'])
    expect(toImageList(['a', 'b'])).toEqual(['a', 'b'])
  })

  test('appendImageUrl 追加图片后保持原有数据格式', () => {
    expect(appendImageUrl('a,b', 'c')).toBe('a,b,c')
    expect(appendImageUrl(['a', 'b'], 'c')).toEqual(['a', 'b', 'c'])
  })

  test('removeImageUrl 删除图片后保持原有数据格式', () => {
    expect(removeImageUrl('a,b,c', 'b')).toBe('a,c')
    expect(removeImageUrl(['a', 'b', 'c'], 'b')).toEqual(['a', 'c'])
  })
})
