import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import ItemList from '../components/shared/ItemList.vue'

const systemItem = { id: 'sys1', name: 'System Task', user_id: null }
const userItem = { id: 'user1', name: 'User Task', user_id: 'abc123' }

describe('ItemList.vue', () => {
  it('does not show delete button for system items', async () => {
    const wrapper = mount(ItemList, {
      props: {
        fetchUrl: '',
        itemKey: 'items',
        itemFields: ['name'],
        deletable: true,
        testItems: [systemItem],
      },
    })
    await flushPromises()
    expect(wrapper.find('.delete-btn').exists()).toBe(false)
  })

  it('shows delete button for user items', async () => {
    const wrapper = mount(ItemList, {
      props: {
        fetchUrl: '',
        itemKey: 'items',
        itemFields: ['name'],
        deletable: true,
        testItems: [userItem],
      },
    })
    await flushPromises()
    expect(wrapper.find('.delete-btn').exists()).toBe(true)
  })
})
