import { describe, it, expect } from 'vitest'
import { useHomeFilters } from '@/features/listings/composables/useHomeFilters'
import { ref } from 'vue'
import { emptyListingPublishOptions } from '@/features/listings/api/listingOptions'

describe('useHomeFilters', () => {
  it('应该初始化空的筛选器', () => {
    const publishOptions = ref(emptyListingPublishOptions)
    const listings = ref([])

    const { filters } = useHomeFilters(publishOptions, listings)

    expect(filters.keyword).toBe('')
    expect(filters.minCoin).toBeUndefined()
    expect(filters.maxCoin).toBeUndefined()
  })

  it('应该正确重置筛选器', () => {
    const publishOptions = ref(emptyListingPublishOptions)
    const listings = ref([])

    const { filters, resetFilters } = useHomeFilters(publishOptions, listings)

    filters.keyword = '测试'
    filters.minCoin = 100
    filters.region = '北京'

    resetFilters()

    expect(filters.keyword).toBe('')
    expect(filters.minCoin).toBeUndefined()
    expect(filters.region).toBe('')
  })

  it('应该正确设置字符串筛选器', () => {
    const publishOptions = ref(emptyListingPublishOptions)
    const listings = ref([])

    const { filters, setStringFilter, closeFilterPopover } = useHomeFilters(publishOptions, listings)

    setStringFilter('region', '上海')

    expect(filters.region).toBe('上海')
  })

  it('应该正确设置范围筛选器', () => {
    const publishOptions = ref(emptyListingPublishOptions)
    const listings = ref([])

    const { filters, setCoinRange } = useHomeFilters(publishOptions, listings)

    setCoinRange(100, 500)

    expect(filters.minCoin).toBe(100)
    expect(filters.maxCoin).toBe(500)
  })
})
