import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import ScheduleView from '../ScheduleView.vue'

// Mock the API module
vi.mock('@/api/schedule', () => ({
  getScheduleList: vi.fn().mockResolvedValue({ rows: [] })
}))

describe('ScheduleView.vue - TDD Task 7', () => {
  it('should have TopBar right slot with today and add-schedule buttons', () => {
    const wrapper = mount(ScheduleView)
    const topBar = wrapper.findComponent({ name: 'TopBar' })
    expect(topBar.exists()).toBe(true)

    // Check that TopBar has right slot content
    const rightSlot = topBar.find('[class*="flex items-center gap-2"]')
    expect(rightSlot.exists()).toBe(true)

    // Verify "今天" button exists in right slot
    const todayButton = rightSlot.findAll('[class*="text-blue-500"]').find(el => el.text().includes('今天'))
    expect(todayButton).toBeDefined()
    expect(todayButton!.exists()).toBe(true)

    // Verify "新增排班" button exists in right slot
    const addScheduleButton = rightSlot.findAll('[class*="text-blue-500"]').find(el => el.text().includes('新增排班'))
    expect(addScheduleButton).toBeDefined()
    expect(addScheduleButton!.exists()).toBe(true)
  })

  it('should have empty month navigation row right side (no today button)', () => {
    const wrapper = mount(ScheduleView)

    // Find the month navigation area
    const monthNav = wrapper.findAll('[class*="bg-white px-4 py-3 flex items-center justify-between"]').at(0)
    expect(monthNav).toBeDefined()
    expect(monthNav!.exists()).toBe(true)

    // The right side should only contain the left arrow, month text, and right arrow
    // It should NOT contain "今天" button anymore
    const todayButtonInMonthNav = monthNav!.findAll('[class*="text-blue-500"]').find(el => el.text().includes('今天'))
    expect(todayButtonInMonthNav).toBeUndefined()
  })

  it('should have empty schedule list title right side (no add-schedule button)', () => {
    const wrapper = mount(ScheduleView)

    // Find the schedule list title area
    const scheduleListTitle = wrapper.findAll('[class*="flex justify-between items-center mb-3"]').at(0)
    expect(scheduleListTitle).toBeDefined()
    expect(scheduleListTitle!.exists()).toBe(true)

    // The right side should NOT contain "新增排班" button anymore
    const addScheduleButtonInTitle = scheduleListTitle!.findAll('[class*="text-blue-500"]').find(el => el.text().includes('新增排班'))
    expect(addScheduleButtonInTitle).toBeUndefined()
  })
})
