|
|
@@ -811,3 +811,215 @@ test.describe('LSS管理 - 摄像头列表搜索测试', () => {
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+test.describe('LSS管理 - 摄像头未创建 Live Stream 对话框测试', () => {
|
|
|
+ // 登录辅助函数
|
|
|
+ async function login(page: Page) {
|
|
|
+ await page.goto('/login')
|
|
|
+ await page.evaluate(() => {
|
|
|
+ localStorage.clear()
|
|
|
+ document.cookie.split(';').forEach((c) => {
|
|
|
+ document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
|
|
|
+ })
|
|
|
+ })
|
|
|
+ await page.reload()
|
|
|
+
|
|
|
+ await page.getByPlaceholder('用户名').fill(TEST_USERNAME)
|
|
|
+ await page.getByPlaceholder('密码').fill(TEST_PASSWORD)
|
|
|
+ await page.getByRole('button', { name: '登录' }).click()
|
|
|
+ await expect(page).not.toHaveURL(/\/login/, { timeout: 15000 })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打开摄像头列表辅助函数
|
|
|
+ async function openCameraList(page: Page) {
|
|
|
+ await page.goto('/lss')
|
|
|
+ await page.waitForTimeout(1000)
|
|
|
+
|
|
|
+ // 点击编辑按钮进入 LSS 编辑抽屉
|
|
|
+ const editButton = page.locator('tbody tr').first().locator('button').nth(1)
|
|
|
+ await expect(editButton).toBeVisible({ timeout: 10000 })
|
|
|
+ await editButton.click()
|
|
|
+
|
|
|
+ // 等待 LSS 编辑抽屉打开
|
|
|
+ const drawer = page.locator('.el-drawer').filter({ hasText: 'LSS详情' })
|
|
|
+ await expect(drawer).toBeVisible({ timeout: 5000 })
|
|
|
+
|
|
|
+ // 点击"摄像头列表" Tab
|
|
|
+ await drawer.locator('.el-tabs__item').filter({ hasText: '摄像头列表' }).click()
|
|
|
+ await page.waitForTimeout(500)
|
|
|
+
|
|
|
+ return drawer
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试点击无 streamSn 的摄像头时显示对话框
|
|
|
+ */
|
|
|
+ test('点击无 streamSn 的摄像头时显示"尚未建立 Live Stream"对话框', async ({ page }) => {
|
|
|
+ await login(page)
|
|
|
+
|
|
|
+ // Mock 摄像头列表 API 返回无 streamSn 的数据
|
|
|
+ await page.route('**/admin/camera/list*', async (route) => {
|
|
|
+ await route.fulfill({
|
|
|
+ status: 200,
|
|
|
+ contentType: 'application/json',
|
|
|
+ body: JSON.stringify({
|
|
|
+ success: true,
|
|
|
+ errCode: 0,
|
|
|
+ data: {
|
|
|
+ list: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ cameraId: 'CAM_NO_STREAM',
|
|
|
+ cameraName: '无推流摄像头',
|
|
|
+ lssId: 'LSS_001',
|
|
|
+ status: 'active',
|
|
|
+ streamSn: null // 没有 streamSn
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ total: 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ const drawer = await openCameraList(page)
|
|
|
+
|
|
|
+ // 等待表格数据加载
|
|
|
+ await page.waitForTimeout(500)
|
|
|
+
|
|
|
+ // 点击摄像头控制按钮(crosshairs-btn)
|
|
|
+ const crosshairsBtn = drawer.locator('.crosshairs-btn').first()
|
|
|
+ await expect(crosshairsBtn).toBeVisible({ timeout: 5000 })
|
|
|
+ await crosshairsBtn.click()
|
|
|
+
|
|
|
+ // 验证对话框显示
|
|
|
+ const messageBox = page.locator('.el-message-box')
|
|
|
+ await expect(messageBox).toBeVisible({ timeout: 5000 })
|
|
|
+
|
|
|
+ // 验证对话框标题
|
|
|
+ await expect(messageBox.locator('.el-message-box__title')).toContainText('尚未建立 Live Stream')
|
|
|
+
|
|
|
+ // 验证对话框内容
|
|
|
+ await expect(messageBox.locator('.el-message-box__message')).toContainText('请先新增 Live Stream')
|
|
|
+
|
|
|
+ // 验证按钮存在
|
|
|
+ await expect(messageBox.locator('button:has-text("新增 Live Stream")')).toBeVisible()
|
|
|
+ await expect(messageBox.locator('button:has-text("取消")')).toBeVisible()
|
|
|
+ })
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试点击"取消"按钮关闭对话框
|
|
|
+ */
|
|
|
+ test('点击"取消"按钮关闭对话框', async ({ page }) => {
|
|
|
+ await login(page)
|
|
|
+
|
|
|
+ // Mock 摄像头列表 API 返回无 streamSn 的数据
|
|
|
+ await page.route('**/admin/camera/list*', async (route) => {
|
|
|
+ await route.fulfill({
|
|
|
+ status: 200,
|
|
|
+ contentType: 'application/json',
|
|
|
+ body: JSON.stringify({
|
|
|
+ success: true,
|
|
|
+ errCode: 0,
|
|
|
+ data: {
|
|
|
+ list: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ cameraId: 'CAM_NO_STREAM',
|
|
|
+ cameraName: '无推流摄像头',
|
|
|
+ lssId: 'LSS_001',
|
|
|
+ status: 'active',
|
|
|
+ streamSn: null
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ total: 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ const drawer = await openCameraList(page)
|
|
|
+ await page.waitForTimeout(500)
|
|
|
+
|
|
|
+ // 点击摄像头控制按钮
|
|
|
+ const crosshairsBtn = drawer.locator('.crosshairs-btn').first()
|
|
|
+ await crosshairsBtn.click()
|
|
|
+
|
|
|
+ // 等待对话框显示
|
|
|
+ const messageBox = page.locator('.el-message-box')
|
|
|
+ await expect(messageBox).toBeVisible({ timeout: 5000 })
|
|
|
+
|
|
|
+ // 点击取消按钮
|
|
|
+ await messageBox.locator('button:has-text("取消")').click()
|
|
|
+
|
|
|
+ // 验证对话框关闭
|
|
|
+ await expect(messageBox).not.toBeVisible({ timeout: 3000 })
|
|
|
+
|
|
|
+ // 验证仍在 LSS 页面
|
|
|
+ await expect(page).toHaveURL(/\/lss/)
|
|
|
+ })
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试点击"新增 Live Stream"按钮跳转到创建页面
|
|
|
+ */
|
|
|
+ test('点击"新增 Live Stream"按钮跳转到 live-stream 创建页面', async ({ page }) => {
|
|
|
+ await login(page)
|
|
|
+ const drawer = await openCameraList(page)
|
|
|
+ await page.waitForTimeout(500)
|
|
|
+
|
|
|
+ // 找到没有 streamSn 的摄像头(crosshairs-btn 没有 active 类的)
|
|
|
+ const inactiveCrosshairsBtn = drawer.locator('.crosshairs-btn:not(.active)').first()
|
|
|
+
|
|
|
+ // 如果存在无 streamSn 的摄像头
|
|
|
+ if ((await inactiveCrosshairsBtn.count()) > 0) {
|
|
|
+ await inactiveCrosshairsBtn.click()
|
|
|
+
|
|
|
+ // 等待对话框显示
|
|
|
+ const messageBox = page.locator('.el-message-box')
|
|
|
+ await expect(messageBox).toBeVisible({ timeout: 5000 })
|
|
|
+
|
|
|
+ // 点击"新增 Live Stream"按钮
|
|
|
+ await messageBox.locator('button:has-text("新增 Live Stream")').click()
|
|
|
+
|
|
|
+ // 验证跳转到 live-stream 页面并带有 action=create 参数
|
|
|
+ await expect(page).toHaveURL(/\/live-stream\?cameraId=.*&action=create/, { timeout: 5000 })
|
|
|
+
|
|
|
+ // 验证新增抽屉自动打开
|
|
|
+ const liveStreamDrawer = page.locator('.el-drawer').filter({ hasText: '新增 Live Stream' })
|
|
|
+ await expect(liveStreamDrawer).toBeVisible({ timeout: 5000 })
|
|
|
+ } else {
|
|
|
+ // 如果没有无 streamSn 的摄像头,跳过测试
|
|
|
+ test.skip()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试有 streamSn 的摄像头直接跳转(不显示对话框)
|
|
|
+ */
|
|
|
+ test('有 streamSn 的摄像头直接跳转到 live-stream 页面', async ({ page }) => {
|
|
|
+ await login(page)
|
|
|
+ const drawer = await openCameraList(page)
|
|
|
+ await page.waitForTimeout(500)
|
|
|
+
|
|
|
+ // 找到有 streamSn 的摄像头(crosshairs-btn 有 active 类的)
|
|
|
+ const activeCrosshairsBtn = drawer.locator('.crosshairs-btn.active').first()
|
|
|
+
|
|
|
+ // 如果存在有 streamSn 的摄像头
|
|
|
+ if ((await activeCrosshairsBtn.count()) > 0) {
|
|
|
+ await activeCrosshairsBtn.click()
|
|
|
+
|
|
|
+ // 等待一小段时间检查是否有对话框
|
|
|
+ await page.waitForTimeout(500)
|
|
|
+
|
|
|
+ // 验证没有显示对话框,直接跳转
|
|
|
+ const messageBox = page.locator('.el-message-box')
|
|
|
+
|
|
|
+ // 验证跳转到 live-stream 页面(不带 action=create)
|
|
|
+ await expect(page).toHaveURL(/\/live-stream\?cameraId=/, { timeout: 5000 })
|
|
|
+ await expect(page).not.toHaveURL(/action=create/)
|
|
|
+ } else {
|
|
|
+ // 如果没有有 streamSn 的摄像头,跳过测试
|
|
|
+ test.skip()
|
|
|
+ }
|
|
|
+ })
|
|
|
+})
|