/**
 * 手动验证脚本 - 逐个打开三个页面，每页停留10秒供人眼观察
 * 验证：勾选checkbox后是否出现批量启用/停用/删除按钮
 */
import { test, type Page } from '@playwright/test'

const MOCK_TOKEN = 'mock-test-token'

test.beforeEach(async ({ page }) => {
  await page.addInitScript((token) => {
    localStorage.setItem('token', token)
  }, MOCK_TOKEN)
})

// 重置mock数据
async function resetMock(page: Page, endpoint: string) {
  await page.evaluate(async (url) => {
    await fetch(url, { method: 'POST' })
  }, endpoint)
}

async function openPage(page: Page, path: string, resetEndpoint: string) {
  await page.goto(path, { waitUntil: 'networkidle' })
  await resetMock(page, resetEndpoint)
  await page.reload({ waitUntil: 'networkidle' })
  await page.waitForSelector('.el-table', { timeout: 15000 })
}

test('设备管理 - 打开页面截图（未勾选）', async ({ page }) => {
  await openPage(page, '/mock/machine', '/mock-api/test/reset-machines')
  await page.screenshot({ path: 'test-results/manual-machine-no-select.png', fullPage: true })
  
  // 勾选第1行
  await page.locator('.el-table__body .el-checkbox').first().click()
  await page.waitForTimeout(1000)
  await page.screenshot({ path: 'test-results/manual-machine-selected.png', fullPage: true })
  
  // 等待10秒供人眼观察
  await page.waitForTimeout(10000)
})

test('员工管理 - 打开页面截图（未勾选）', async ({ page }) => {
  await openPage(page, '/mock/worker', '/mock-api/test/reset-workers')
  await page.screenshot({ path: 'test-results/manual-worker-no-select.png', fullPage: true })
  
  await page.locator('.el-table__body .el-checkbox').first().click()
  await page.waitForTimeout(1000)
  await page.screenshot({ path: 'test-results/manual-worker-selected.png', fullPage: true })
  
  await page.waitForTimeout(10000)
})

test('采集地址 - 打开页面截图（未勾选）', async ({ page }) => {
  await openPage(page, '/mock/collect-address', '/mock-api/test/reset-addresses')
  await page.screenshot({ path: 'test-results/manual-address-no-select.png', fullPage: true })
  
  await page.locator('.el-table__body .el-checkbox').first().click()
  await page.waitForTimeout(1000)
  await page.screenshot({ path: 'test-results/manual-address-selected.png', fullPage: true })
  
  await page.waitForTimeout(10000)
})
