import { test, expect } from '@playwright/test'

test.describe('侧边栏', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/providers')
    await expect(page.getByRole('heading', { name: '供应商管理' })).toBeVisible()
  })

  test('应显示侧边栏', async ({ page }) => {
    const aside = page.locator('aside')
    await expect(aside).toBeVisible()
  })

  test('应显示应用名称', async ({ page }) => {
    await expect(page.locator('aside').getByText('AI Gateway')).toBeVisible()
  })

  test('应显示导航菜单项', async ({ page }) => {
    const aside = page.locator('aside')
    await expect(aside.getByText('供应商管理')).toBeVisible()
    await expect(aside.getByText('用量统计')).toBeVisible()
  })
})

test.describe('页面导航', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/providers')
    await expect(page.getByRole('heading', { name: '供应商管理' })).toBeVisible()
  })

  test('应能切换到用量统计', async ({ page }) => {
    await page.locator('aside').getByText('用量统计').click()
    await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible()
  })

  test('应能切换回供应商管理', async ({ page }) => {
    await page.locator('aside').getByText('用量统计').click()
    await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible()

    await page.locator('aside').getByText('供应商管理').click()
    await expect(page.getByRole('heading', { name: '供应商管理' })).toBeVisible()
  })

  test('应在刷新后保持当前页面', async ({ page }) => {
    await page.locator('aside').getByText('用量统计').click()
    await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible()

    await page.reload()
    await expect(page.getByRole('heading', { name: '用量统计' })).toBeVisible()
  })
})
