live-stream.spec.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. import { test, expect, type Page } from '@playwright/test'
  2. // 测试账号配置
  3. const TEST_USERNAME = process.env.TEST_USERNAME || 'admin'
  4. const TEST_PASSWORD = process.env.TEST_PASSWORD || '123456'
  5. // 登录辅助函数
  6. async function login(page: Page) {
  7. await page.goto('/login')
  8. await page.evaluate(() => {
  9. localStorage.clear()
  10. document.cookie.split(';').forEach((c) => {
  11. document.cookie = c.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date().toUTCString()};path=/`)
  12. })
  13. })
  14. await page.reload()
  15. await page.getByPlaceholder('用户名').fill(TEST_USERNAME)
  16. await page.getByPlaceholder('密码').fill(TEST_PASSWORD)
  17. await page.getByRole('button', { name: '登录' }).click()
  18. await expect(page).not.toHaveURL(/\/login/, { timeout: 15000 })
  19. }
  20. test.describe('LiveStream 管理 - 搜索功能测试', () => {
  21. /**
  22. * 按 Stream SN 搜索
  23. */
  24. test('按 Stream SN 搜索 - 验证参数传递', async ({ page }) => {
  25. await login(page)
  26. await page.goto('/live-stream-manage/list')
  27. // 等待表格加载
  28. await page.waitForSelector('tbody tr', { timeout: 10000 })
  29. // 设置 API 拦截来验证参数
  30. let requestBody: any = null
  31. await page.route('**/admin/live-stream/list', async (route) => {
  32. const request = route.request()
  33. if (request.method() === 'POST') {
  34. requestBody = request.postDataJSON()
  35. }
  36. await route.continue()
  37. })
  38. // 在 stream sn 搜索框输入
  39. await page.getByPlaceholder('stream sn').fill('stream_123')
  40. // 点击查询
  41. await page.getByRole('button', { name: '查询' }).click()
  42. await page.waitForTimeout(1000)
  43. // 验证请求参数中包含 streamSn
  44. expect(requestBody).not.toBeNull()
  45. expect(requestBody.streamSn).toBe('stream_123')
  46. })
  47. /**
  48. * 按 Name 搜索
  49. */
  50. test('按 Name 搜索 - 验证参数传递', async ({ page }) => {
  51. await login(page)
  52. await page.goto('/live-stream-manage/list')
  53. // 等待表格加载
  54. await page.waitForSelector('tbody tr', { timeout: 10000 })
  55. // 设置 API 拦截
  56. let requestBody: any = null
  57. await page.route('**/admin/live-stream/list', async (route) => {
  58. const request = route.request()
  59. if (request.method() === 'POST') {
  60. requestBody = request.postDataJSON()
  61. }
  62. await route.continue()
  63. })
  64. // 在 name 搜索框输入
  65. await page.getByPlaceholder('名称').fill('测试流')
  66. // 点击查询
  67. await page.getByRole('button', { name: '查询' }).click()
  68. await page.waitForTimeout(1000)
  69. // 验证请求参数中包含 name
  70. expect(requestBody).not.toBeNull()
  71. expect(requestBody.name).toBe('测试流')
  72. })
  73. /**
  74. * 按 LSS 搜索
  75. */
  76. test('按 LSS 搜索 - 验证参数传递', async ({ page }) => {
  77. await login(page)
  78. await page.goto('/live-stream-manage/list')
  79. // 等待表格加载
  80. await page.waitForSelector('tbody tr', { timeout: 10000 })
  81. // 设置 API 拦截
  82. let requestBody: any = null
  83. await page.route('**/admin/live-stream/list', async (route) => {
  84. const request = route.request()
  85. if (request.method() === 'POST') {
  86. requestBody = request.postDataJSON()
  87. }
  88. await route.continue()
  89. })
  90. // 点击 LSS 下拉框
  91. await page.locator('.el-select').filter({ hasText: 'LSS' }).click()
  92. await page.waitForTimeout(300)
  93. // 选择第一个 LSS 选项(如果有)
  94. const firstOption = page.locator('.el-select-dropdown__item').first()
  95. if (await firstOption.isVisible()) {
  96. const lssValue = await firstOption.textContent()
  97. await firstOption.click()
  98. // 点击查询
  99. await page.getByRole('button', { name: '查询' }).click()
  100. await page.waitForTimeout(1000)
  101. // 验证请求参数中包含 lssId
  102. expect(requestBody).not.toBeNull()
  103. expect(requestBody.lssId).toBe(lssValue?.trim())
  104. }
  105. })
  106. /**
  107. * 按设备ID搜索
  108. */
  109. test('按设备ID搜索 - 验证参数传递', async ({ page }) => {
  110. await login(page)
  111. await page.goto('/live-stream-manage/list')
  112. // 等待表格加载
  113. await page.waitForSelector('tbody tr', { timeout: 10000 })
  114. // 设置 API 拦截
  115. let requestBody: any = null
  116. await page.route('**/admin/live-stream/list', async (route) => {
  117. const request = route.request()
  118. if (request.method() === 'POST') {
  119. requestBody = request.postDataJSON()
  120. }
  121. await route.continue()
  122. })
  123. // 在设备ID搜索框输入
  124. await page.getByPlaceholder('设备ID').fill('EEE1')
  125. // 点击查询
  126. await page.getByRole('button', { name: '查询' }).click()
  127. await page.waitForTimeout(1000)
  128. // 验证请求参数中包含 cameraId
  129. expect(requestBody).not.toBeNull()
  130. expect(requestBody.cameraId).toBe('EEE1')
  131. })
  132. /**
  133. * 组合搜索 - 所有字段
  134. */
  135. test('组合搜索 - 多字段同时搜索', async ({ page }) => {
  136. await login(page)
  137. await page.goto('/live-stream-manage/list')
  138. // 等待表格加载
  139. await page.waitForSelector('tbody tr', { timeout: 10000 })
  140. // 设置 API 拦截
  141. let requestBody: any = null
  142. await page.route('**/admin/live-stream/list', async (route) => {
  143. const request = route.request()
  144. if (request.method() === 'POST') {
  145. requestBody = request.postDataJSON()
  146. }
  147. await route.continue()
  148. })
  149. // 填入所有搜索条件
  150. await page.getByPlaceholder('stream sn').fill('stream_001')
  151. await page.getByPlaceholder('名称').fill('测试')
  152. await page.getByPlaceholder('设备ID').fill('EEE1')
  153. // 点击查询
  154. await page.getByRole('button', { name: '查询' }).click()
  155. await page.waitForTimeout(1000)
  156. // 验证请求参数包含所有字段
  157. expect(requestBody).not.toBeNull()
  158. expect(requestBody.streamSn).toBe('stream_001')
  159. expect(requestBody.name).toBe('测试')
  160. expect(requestBody.cameraId).toBe('EEE1')
  161. })
  162. /**
  163. * 重置搜索条件
  164. */
  165. test('重置搜索条件 - 清空所有输入', async ({ page }) => {
  166. await login(page)
  167. await page.goto('/live-stream-manage/list')
  168. // 填入搜索条件
  169. await page.getByPlaceholder('stream sn').fill('test-sn')
  170. await page.getByPlaceholder('名称').fill('test-name')
  171. await page.getByPlaceholder('设备ID').fill('test-device')
  172. // 点击重置
  173. await page.getByRole('button', { name: '重置' }).click()
  174. await page.waitForTimeout(300)
  175. // 验证搜索条件已清空
  176. await expect(page.getByPlaceholder('stream sn')).toHaveValue('')
  177. await expect(page.getByPlaceholder('name')).toHaveValue('')
  178. await expect(page.getByPlaceholder('设备ID')).toHaveValue('')
  179. })
  180. })
  181. test.describe('LiveStream 管理 - BUG 回归测试', () => {
  182. /**
  183. * BUG 回归测试:按设备ID搜索应该只返回匹配的记录
  184. *
  185. * 问题描述:
  186. * - 前端已修复:searchForm.cameraId 参数现在会正确传递给 API
  187. * - 后端待修复:API 目前未实现 cameraId 过滤,返回所有数据
  188. *
  189. * 预期行为:
  190. * - 搜索设备ID "EEE1" 应该只返回 1 条记录
  191. * - 该记录的设备ID列应该显示 "EEE1"
  192. *
  193. * 当前状态:测试会失败,等待后端实现过滤
  194. */
  195. test('BUG: 按设备ID搜索 EEE1 应该只返回 1 条匹配记录', async ({ page }) => {
  196. await login(page)
  197. await page.goto('/live-stream-manage/list')
  198. // 等待表格加载
  199. await page.waitForSelector('tbody tr', { timeout: 10000 })
  200. await page.waitForTimeout(500)
  201. // 在设备ID搜索框输入 "EEE1"
  202. await page.getByPlaceholder('设备ID').fill('EEE1')
  203. // 点击查询按钮
  204. await page.getByRole('button', { name: '查询' }).click()
  205. // 等待搜索结果加载
  206. await page.waitForTimeout(1000)
  207. // 验证:应该只有 1 条记录
  208. const tableRows = page.locator('tbody tr')
  209. const rowCount = await tableRows.count()
  210. expect(rowCount).toBe(1)
  211. // 验证:该记录的设备ID应该是 "EEE1"
  212. const firstRowDeviceId = await tableRows.first().locator('td').nth(3).textContent()
  213. expect(firstRowDeviceId?.trim()).toBe('EEE1')
  214. // 验证:分页显示 Total 1
  215. await expect(page.locator('.el-pagination')).toContainText('Total 1')
  216. })
  217. })
  218. test.describe('LiveStream 管理 - 页面功能测试', () => {
  219. test('LiveStream 管理页面正确显示', async ({ page }) => {
  220. await login(page)
  221. await page.goto('/live-stream-manage/list')
  222. // 验证页面标题
  223. await expect(page.locator('text=LiveStream 管理')).toBeVisible()
  224. // 验证搜索表单元素
  225. await expect(page.getByPlaceholder('stream sn')).toBeVisible()
  226. await expect(page.getByPlaceholder('name')).toBeVisible()
  227. await expect(page.getByPlaceholder('设备ID')).toBeVisible()
  228. await expect(page.getByRole('button', { name: '查询' })).toBeVisible()
  229. await expect(page.getByRole('button', { name: '重置' })).toBeVisible()
  230. await expect(page.getByRole('button', { name: '新增' })).toBeVisible()
  231. // 验证表头
  232. await expect(page.locator('th:has-text("Stream SN"), th:has-text("stream sn")')).toBeVisible()
  233. await expect(page.locator('th:has-text("Name"), th:has-text("名称")')).toBeVisible()
  234. await expect(page.locator('th:has-text("LSS")')).toBeVisible()
  235. await expect(page.locator('th:has-text("Device ID"), th:has-text("设备ID")')).toBeVisible()
  236. })
  237. test('打开新增 LiveStream 抽屉', async ({ page }) => {
  238. await login(page)
  239. await page.goto('/live-stream-manage/list')
  240. // 点击新增按钮
  241. await page.getByRole('button', { name: '新增' }).click()
  242. // 验证抽屉打开
  243. const drawer = page.locator('.el-drawer').filter({ hasText: '新增 Live Stream' })
  244. await expect(drawer).toBeVisible({ timeout: 5000 })
  245. // 验证表单元素
  246. await expect(drawer.locator('label:has-text("名称")')).toBeVisible()
  247. await expect(drawer.locator('label:has-text("LSS 节点")')).toBeVisible()
  248. await expect(drawer.locator('label:has-text("摄像头")')).toBeVisible()
  249. // 关闭抽屉
  250. await drawer.getByRole('button', { name: '取消' }).click()
  251. await expect(drawer).not.toBeVisible({ timeout: 5000 })
  252. })
  253. test('分页功能正常', async ({ page }) => {
  254. await login(page)
  255. await page.goto('/live-stream-manage/list')
  256. // 等待表格加载
  257. await page.waitForTimeout(1000)
  258. // 验证分页组件存在
  259. const pagination = page.locator('.el-pagination')
  260. await expect(pagination).toBeVisible()
  261. // 验证 Total 显示
  262. await expect(pagination.locator('text=/Total \\d+/')).toBeVisible()
  263. })
  264. test('从侧边栏导航到 LiveStream 管理', async ({ page }) => {
  265. await login(page)
  266. // 点击侧边栏 LiveStream 管理菜单项
  267. await page.getByText('LiveStream 管理').first().click()
  268. // 验证跳转到 LiveStream 管理页面
  269. await expect(page).toHaveURL(/\/live-stream-manage\/list/)
  270. await expect(page.locator('text=LiveStream 管理')).toBeVisible()
  271. })
  272. })
  273. test.describe('LiveStream 管理 - CodeEditor 组件测试 (Bash模式)', () => {
  274. /**
  275. * 测试 CodeEditor Bash 模式 - 头部显示
  276. */
  277. test('CodeEditor Bash模式 - 验证头部显示Bash Script标签和复制按钮', async ({ page }) => {
  278. await login(page)
  279. await page.goto('/live-stream-manage/list')
  280. // 等待表格加载
  281. await page.waitForSelector('tbody tr', { timeout: 10000 })
  282. // 点击命令模板列的"查看"链接
  283. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  284. await expect(viewLink).toBeVisible({ timeout: 5000 })
  285. await viewLink.click()
  286. // 等待命令模板弹窗打开
  287. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  288. await expect(dialog).toBeVisible({ timeout: 5000 })
  289. // 验证 CodeEditor 头部显示 Bash Script 标签
  290. const codeEditor = dialog.locator('.code-editor')
  291. await expect(codeEditor).toBeVisible()
  292. await expect(codeEditor.locator('.editor-header')).toBeVisible()
  293. await expect(codeEditor.locator('.file-type')).toContainText('Bash Script')
  294. // 验证 Copy 按钮存在
  295. await expect(codeEditor.locator('button:has-text("复制"), button:has-text("Copy")')).toBeVisible()
  296. // 验证 Bash 模式没有格式化按钮
  297. await expect(codeEditor.locator('button:has-text("格式化")')).not.toBeVisible()
  298. })
  299. /**
  300. * 测试 CodeEditor Bash 模式 - 复制功能
  301. */
  302. test('CodeEditor Bash模式 - 复制按钮功能', async ({ page }) => {
  303. await login(page)
  304. await page.goto('/live-stream-manage/list')
  305. // 等待表格加载
  306. await page.waitForSelector('tbody tr', { timeout: 10000 })
  307. // 点击命令模板列的"查看"链接
  308. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  309. await viewLink.click()
  310. // 等待命令模板弹窗打开
  311. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  312. await expect(dialog).toBeVisible({ timeout: 5000 })
  313. // 点击复制按钮
  314. const copyButton = dialog.locator('.code-editor button:has-text("复制"), .code-editor button:has-text("Copy")')
  315. await copyButton.click()
  316. // 验证复制成功提示
  317. await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 3000 })
  318. })
  319. /**
  320. * 测试 CodeEditor Bash 模式 - 编辑器可编辑
  321. */
  322. test('CodeEditor Bash模式 - 编辑器可编辑', async ({ page }) => {
  323. await login(page)
  324. await page.goto('/live-stream-manage/list')
  325. // 等待表格加载
  326. await page.waitForSelector('tbody tr', { timeout: 10000 })
  327. // 点击命令模板列的"查看"链接
  328. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  329. await viewLink.click()
  330. // 等待命令模板弹窗打开
  331. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  332. await expect(dialog).toBeVisible({ timeout: 5000 })
  333. // 验证编辑器存在并可以编辑
  334. const codeEditor = dialog.locator('.code-editor')
  335. const editorContent = codeEditor.locator('.cm-content')
  336. await expect(editorContent).toBeVisible()
  337. // 尝试在编辑器中输入内容
  338. await editorContent.click()
  339. await page.keyboard.press('End')
  340. await page.keyboard.type('\n# Test comment')
  341. // 验证内容已添加
  342. await expect(editorContent).toContainText('# Test comment')
  343. })
  344. /**
  345. * 测试 CodeEditor Bash 模式 - 更新按钮存在 (Bug #4628: "关闭" changed to "取消", Bug #4629: dialog changed to drawer)
  346. */
  347. test('CodeEditor Bash模式 - 抽屉包含取消和更新按钮', async ({ page }) => {
  348. await login(page)
  349. await page.goto('/live-stream-manage/list')
  350. // 等待表格加载
  351. await page.waitForSelector('tbody tr', { timeout: 10000 })
  352. // 点击命令模板列的"查看"链接
  353. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  354. await viewLink.click()
  355. // 等待命令模板弹窗打开
  356. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  357. await expect(dialog).toBeVisible({ timeout: 5000 })
  358. // 验证关闭和更新按钮存在
  359. await expect(dialog.locator('button:has-text("取消"), button:has-text("Cancel")')).toBeVisible()
  360. await expect(dialog.locator('button:has-text("更新"), button:has-text("Update")')).toBeVisible()
  361. // 点击关闭按钮
  362. await dialog.locator('button:has-text("取消"), button:has-text("Cancel")').click()
  363. await expect(dialog).not.toBeVisible({ timeout: 5000 })
  364. })
  365. /**
  366. * 测试 CodeEditor Bash 模式 - 图标颜色正确(绿色)
  367. */
  368. test('CodeEditor Bash模式 - 图标显示为绿色', async ({ page }) => {
  369. await login(page)
  370. await page.goto('/live-stream-manage/list')
  371. // 等待表格加载
  372. await page.waitForSelector('tbody tr', { timeout: 10000 })
  373. // 点击命令模板列的"查看"链接
  374. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  375. await viewLink.click()
  376. // 等待命令模板弹窗打开
  377. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  378. await expect(dialog).toBeVisible({ timeout: 5000 })
  379. // 验证图标有 icon-bash 类(对应绿色)
  380. const codeEditor = dialog.locator('.code-editor')
  381. await expect(codeEditor.locator('.icon-bash')).toBeVisible()
  382. })
  383. /**
  384. * 测试 CodeEditor Bash 模式 - 更新命令模板并验证保存成功
  385. */
  386. test('CodeEditor Bash模式 - 更新命令模板并验证保存成功', async ({ page }) => {
  387. await login(page)
  388. await page.goto('/live-stream-manage/list')
  389. // 等待表格加载
  390. await page.waitForSelector('tbody tr', { timeout: 10000 })
  391. // 点击命令模板列的"查看"链接
  392. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  393. await viewLink.click()
  394. // 等待命令模板弹窗打开
  395. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  396. await expect(dialog).toBeVisible({ timeout: 5000 })
  397. // 获取编辑器
  398. const codeEditor = dialog.locator('.code-editor')
  399. const editorContent = codeEditor.locator('.cm-content')
  400. // 生成唯一标识用于验证更新
  401. const timestamp = Date.now()
  402. const testComment = `# Test update at ${timestamp}`
  403. // 在编辑器末尾添加测试注释
  404. await editorContent.click()
  405. await page.keyboard.press('Meta+End')
  406. await page.keyboard.type(`\n${testComment}`)
  407. // 点击更新按钮
  408. const updateButton = dialog.locator('button:has-text("更新"), button:has-text("Update")')
  409. await updateButton.click()
  410. // 等待更新成功提示
  411. await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 })
  412. // 等待弹窗关闭
  413. await expect(dialog).not.toBeVisible({ timeout: 5000 })
  414. // 重新打开命令模板弹窗验证内容已保存
  415. await page.waitForTimeout(500)
  416. await viewLink.click()
  417. // 等待弹窗重新打开
  418. const dialogReopened = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  419. await expect(dialogReopened).toBeVisible({ timeout: 5000 })
  420. // 验证内容包含我们添加的测试注释
  421. const editorContentReopened = dialogReopened.locator('.cm-content')
  422. await expect(editorContentReopened).toContainText(timestamp.toString())
  423. })
  424. /**
  425. * 测试 CodeEditor Bash 模式 - 修改全部内容并验证保存
  426. */
  427. test('CodeEditor Bash模式 - 替换全部命令模板并验证保存', async ({ page }) => {
  428. await login(page)
  429. await page.goto('/live-stream-manage/list')
  430. // 等待表格加载
  431. await page.waitForSelector('tbody tr', { timeout: 10000 })
  432. // 点击命令模板列的"查看"链接
  433. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  434. await viewLink.click()
  435. // 等待命令模板弹窗打开
  436. const dialog = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  437. await expect(dialog).toBeVisible({ timeout: 5000 })
  438. // 获取编辑器
  439. const codeEditor = dialog.locator('.code-editor')
  440. const editorContent = codeEditor.locator('.cm-content')
  441. // 保存原始内容以便恢复
  442. const originalContent = await editorContent.textContent()
  443. // 生成唯一标识用于验证更新
  444. const timestamp = Date.now()
  445. const newScript = `#!/bin/bash
  446. # Updated script at ${timestamp}
  447. echo "Test script"
  448. ffmpeg -i {RTSP_URL} -c copy output.mp4`
  449. // 全选并替换内容
  450. await editorContent.click()
  451. await page.keyboard.press('Meta+a')
  452. await page.keyboard.type(newScript)
  453. // 点击更新按钮
  454. const updateButton = dialog.locator('button:has-text("更新"), button:has-text("Update")')
  455. await updateButton.click()
  456. // 等待更新成功提示
  457. await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 })
  458. // 等待弹窗关闭
  459. await expect(dialog).not.toBeVisible({ timeout: 5000 })
  460. // 重新打开验证内容
  461. await page.waitForTimeout(500)
  462. await viewLink.click()
  463. const dialogReopened = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  464. await expect(dialogReopened).toBeVisible({ timeout: 5000 })
  465. const editorContentReopened = dialogReopened.locator('.cm-content')
  466. await expect(editorContentReopened).toContainText(`Updated script at ${timestamp}`)
  467. await expect(editorContentReopened).toContainText('echo "Test script"')
  468. // 恢复原始内容
  469. if (originalContent) {
  470. await editorContentReopened.click()
  471. await page.keyboard.press('Meta+a')
  472. await page.keyboard.type(originalContent)
  473. await dialogReopened.locator('button:has-text("更新"), button:has-text("Update")').click()
  474. await page.waitForTimeout(1000)
  475. }
  476. })
  477. })
  478. test.describe('LiveStream 管理 - 从 LSS 页面创建流程', () => {
  479. /**
  480. * 测试带 action=create 参数时自动打开新增抽屉
  481. */
  482. test('带 action=create 参数访问时自动打开新增抽屉', async ({ page }) => {
  483. await login(page)
  484. // 直接导航到带有 action=create 参数的页面
  485. await page.goto('/live-stream?action=create')
  486. // 等待页面加载
  487. await page.waitForTimeout(1000)
  488. // 验证新增抽屉已打开
  489. const drawer = page.locator('.el-drawer').filter({ hasText: '新增 Live Stream' })
  490. await expect(drawer).toBeVisible({ timeout: 5000 })
  491. // 验证抽屉标题
  492. await expect(drawer.locator('.drawer-header')).toContainText('新增 Live Stream')
  493. // 验证表单字段存在
  494. await expect(drawer.locator('label:has-text("名称")')).toBeVisible()
  495. await expect(drawer.locator('label:has-text("LSS 节点")')).toBeVisible()
  496. await expect(drawer.locator('label:has-text("摄像头")')).toBeVisible()
  497. })
  498. /**
  499. * 测试带 cameraId 和 action=create 参数时自动填充摄像头信息
  500. */
  501. test('带 cameraId 和 action=create 参数访问时尝试填充摄像头信息', async ({ page }) => {
  502. await login(page)
  503. // 模拟 API 响应,返回带有 lssId 的摄像头数据
  504. await page.route('**/admin/camera/list*', async (route) => {
  505. const request = route.request()
  506. const url = request.url()
  507. // 检查是否是查询特定 cameraId 的请求
  508. if (url.includes('cameraId=TEST_CAM_001')) {
  509. await route.fulfill({
  510. status: 200,
  511. contentType: 'application/json',
  512. body: JSON.stringify({
  513. success: true,
  514. errCode: 0,
  515. data: {
  516. list: [
  517. {
  518. id: 1,
  519. cameraId: 'TEST_CAM_001',
  520. cameraName: '测试摄像头',
  521. lssId: 'LSS_001',
  522. status: 'active'
  523. }
  524. ],
  525. total: 1
  526. }
  527. })
  528. })
  529. } else {
  530. await route.continue()
  531. }
  532. })
  533. // 导航到带有 cameraId 和 action=create 参数的页面
  534. await page.goto('/live-stream?cameraId=TEST_CAM_001&action=create')
  535. // 等待页面和抽屉加载
  536. await page.waitForTimeout(1500)
  537. // 验证新增抽屉已打开
  538. const drawer = page.locator('.el-drawer').filter({ hasText: '新增 Live Stream' })
  539. await expect(drawer).toBeVisible({ timeout: 5000 })
  540. // 等待表单自动填充
  541. await page.waitForTimeout(1000)
  542. // 验证抽屉中的表单元素可见(LSS 节点选择器)
  543. // 由于是 mock 数据,这里主要验证流程不会出错,抽屉能正常打开
  544. await expect(drawer.locator('label:has-text("LSS")')).toBeVisible()
  545. })
  546. /**
  547. * 测试从 LSS 页面点击未创建 Stream 的摄像头时显示提示对话框
  548. * 注:这个测试需要在 LSS 页面进行,但这里测试的是对话框确认后的跳转结果
  549. */
  550. test('取消新增抽屉后返回列表页面', async ({ page }) => {
  551. await login(page)
  552. // 导航到创建页面
  553. await page.goto('/live-stream?action=create')
  554. // 等待抽屉打开
  555. const drawer = page.locator('.el-drawer').filter({ hasText: '新增 Live Stream' })
  556. await expect(drawer).toBeVisible({ timeout: 5000 })
  557. // 点击取消按钮
  558. await drawer.locator('button:has-text("取消"), button:has-text("Cancel")').click()
  559. // 验证抽屉关闭
  560. await expect(drawer).not.toBeVisible({ timeout: 3000 })
  561. // 验证仍在 live-stream 页面
  562. await expect(page).toHaveURL(/\/live-stream-manage\/list/)
  563. })
  564. /**
  565. * 测试 URL 参数中的 cameraId 同时作为搜索条件
  566. */
  567. test('cameraId 参数同时作为搜索条件', async ({ page }) => {
  568. await login(page)
  569. // 设置 API 拦截来验证参数
  570. let listRequestBody: any = null
  571. await page.route('**/admin/live-stream/list', async (route) => {
  572. const request = route.request()
  573. if (request.method() === 'POST') {
  574. listRequestBody = request.postDataJSON()
  575. }
  576. await route.continue()
  577. })
  578. // 导航到带有 cameraId 参数的页面(不带 action=create)
  579. await page.goto('/live-stream?cameraId=CAM_SEARCH_TEST')
  580. // 等待列表请求完成
  581. await page.waitForTimeout(1500)
  582. // 验证搜索框中已填入 cameraId
  583. const cameraIdInput = page.getByPlaceholder('设备ID')
  584. await expect(cameraIdInput).toHaveValue('CAM_SEARCH_TEST')
  585. // 验证 API 请求中包含 cameraId
  586. expect(listRequestBody).not.toBeNull()
  587. expect(listRequestBody.cameraId).toBe('CAM_SEARCH_TEST')
  588. })
  589. })
  590. test.describe('LiveStream 管理 - Bug修复验证测试', () => {
  591. // 登录辅助函数
  592. async function loginHelper(page: Page) {
  593. await page.goto('/login')
  594. await page.evaluate(() => {
  595. localStorage.clear()
  596. document.cookie.split(';').forEach((c) => {
  597. document.cookie = c.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date().toUTCString()};path=/`)
  598. })
  599. })
  600. await page.reload()
  601. await page.getByPlaceholder('用户名').fill(TEST_USERNAME)
  602. await page.getByPlaceholder('密码').fill(TEST_PASSWORD)
  603. await page.getByRole('button', { name: '登录' }).click()
  604. await expect(page).not.toHaveURL(/\/login/, { timeout: 15000 })
  605. }
  606. /**
  607. * Bug #4627: 启动时间和关闭时间显示用户当前时区
  608. */
  609. test('Bug #4627 - 时间列正确格式化显示', async ({ page }) => {
  610. await loginHelper(page)
  611. await page.goto('/live-stream-manage/list')
  612. // 等待表格加载
  613. await page.waitForSelector('tbody tr', { timeout: 10000 })
  614. // 验证启动时间列存在
  615. await expect(page.locator('th:has-text("启动时间")')).toBeVisible()
  616. await expect(page.locator('th:has-text("关闭时间")')).toBeVisible()
  617. // 验证时间格式正确 (YYYY-MM-DD HH:mm:ss)
  618. const startedAtCell = page.locator('tbody tr').first().locator('td').nth(7)
  619. const startedAtText = await startedAtCell.textContent()
  620. // 时间格式应该是 YYYY-MM-DD HH:mm:ss 或 "-"
  621. if (startedAtText && startedAtText.trim() !== '-') {
  622. expect(startedAtText).toMatch(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)
  623. }
  624. })
  625. /**
  626. * Bug #4628: 命令模板按钮文字从"关闭"改为"取消"
  627. */
  628. test('Bug #4628 - 命令模板抽屉按钮显示"取消"而非"关闭"', async ({ page }) => {
  629. await loginHelper(page)
  630. await page.goto('/live-stream-manage/list')
  631. // 等待表格加载
  632. await page.waitForSelector('tbody tr', { timeout: 10000 })
  633. // 点击命令模板列的"查看"链接
  634. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  635. await expect(viewLink).toBeVisible({ timeout: 5000 })
  636. await viewLink.click()
  637. // 等待命令模板抽屉打开
  638. const drawer = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  639. await expect(drawer).toBeVisible({ timeout: 5000 })
  640. // 验证有"取消"按钮而非"关闭"按钮
  641. await expect(drawer.locator('button:has-text("取消")')).toBeVisible()
  642. await expect(drawer.locator('button:has-text("关闭")')).not.toBeVisible()
  643. })
  644. /**
  645. * Bug #4629: 命令模板使用右到左抽屉显示
  646. */
  647. test('Bug #4629 - 命令模板使用抽屉而非对话框', async ({ page }) => {
  648. await loginHelper(page)
  649. await page.goto('/live-stream-manage/list')
  650. // 等待表格加载
  651. await page.waitForSelector('tbody tr', { timeout: 10000 })
  652. // 点击命令模板列的"查看"链接
  653. const viewLink = page.locator('tbody tr').first().locator('a:has-text("查看"), a:has-text("View")')
  654. await expect(viewLink).toBeVisible({ timeout: 5000 })
  655. await viewLink.click()
  656. // 等待命令模板抽屉打开
  657. const drawer = page.locator('.el-drawer').filter({ hasText: '命令模板' })
  658. await expect(drawer).toBeVisible({ timeout: 5000 })
  659. // 验证是抽屉(el-drawer)而非对话框(el-dialog)
  660. const dialog = page.locator('.el-dialog').filter({ hasText: '命令模板' })
  661. await expect(dialog).not.toBeVisible()
  662. })
  663. /**
  664. * Bug #4630: 搜索框placeholder从"name"改为"名称"
  665. */
  666. test('Bug #4630 - 搜索框placeholder显示"名称"而非"name"', async ({ page }) => {
  667. await loginHelper(page)
  668. await page.goto('/live-stream-manage/list')
  669. // 验证名称搜索框的placeholder是"名称"
  670. const nameInput = page.getByPlaceholder('名称')
  671. await expect(nameInput).toBeVisible()
  672. // 验证没有placeholder为"name"的输入框
  673. const nameInputEnglish = page.getByPlaceholder('name')
  674. await expect(nameInputEnglish).not.toBeVisible()
  675. })
  676. /**
  677. * Bug #4541 (通用): 重置按钮使用灰底白字
  678. */
  679. test('Bug #4541 - 重置按钮使用灰底白字', async ({ page }) => {
  680. await loginHelper(page)
  681. await page.goto('/live-stream-manage/list')
  682. // 获取重置按钮
  683. const resetButton = page.getByRole('button', { name: '重置' })
  684. await expect(resetButton).toBeVisible()
  685. // 验证按钮有 el-button--info 类(灰色按钮)
  686. await expect(resetButton).toHaveClass(/el-button--info/)
  687. })
  688. })