|
|
@@ -1,6 +1,7 @@
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
import { mount, flushPromises } from '@vue/test-utils'
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
+import { createI18n } from 'vue-i18n'
|
|
|
import CameraView from '@/views/camera/index.vue'
|
|
|
import { wrapResponse, wrapPageResponse, wrapArrayResponse, mockCameras, mockMachines } from '../../../fixtures'
|
|
|
|
|
|
@@ -45,6 +46,39 @@ vi.mock('@/api/machine', () => ({
|
|
|
listAllMachines: () => mockListAllMachines()
|
|
|
}))
|
|
|
|
|
|
+// Create i18n instance
|
|
|
+const i18n = createI18n({
|
|
|
+ legacy: false,
|
|
|
+ locale: 'zh-CN',
|
|
|
+ messages: {
|
|
|
+ 'zh-CN': {
|
|
|
+ 摄像头管理: '摄像头管理',
|
|
|
+ 新增摄像头: '新增摄像头',
|
|
|
+ 刷新列表: '刷新列表',
|
|
|
+ 搜索: '搜索',
|
|
|
+ 重置: '重置',
|
|
|
+ 编辑: '编辑',
|
|
|
+ 删除: '删除',
|
|
|
+ 检测: '检测',
|
|
|
+ 查看通道: '查看通道',
|
|
|
+ 确认删除: '确认删除',
|
|
|
+ 在线: '在线',
|
|
|
+ 离线: '离线',
|
|
|
+ 全部: '全部',
|
|
|
+ 状态: '状态',
|
|
|
+ 机器: '机器',
|
|
|
+ 摄像头ID: '摄像头ID',
|
|
|
+ 名称: '名称',
|
|
|
+ 品牌: '品牌',
|
|
|
+ IP地址: 'IP地址',
|
|
|
+ 端口: '端口',
|
|
|
+ 操作: '操作',
|
|
|
+ 取消: '取消',
|
|
|
+ 确定: '确定'
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
describe('Camera View', () => {
|
|
|
beforeEach(() => {
|
|
|
setActivePinia(createPinia())
|
|
|
@@ -56,7 +90,7 @@ describe('Camera View', () => {
|
|
|
const mountCamera = () => {
|
|
|
return mount(CameraView, {
|
|
|
global: {
|
|
|
- plugins: [createPinia()],
|
|
|
+ plugins: [createPinia(), i18n],
|
|
|
stubs: {
|
|
|
'el-form': { template: '<form><slot /></form>' },
|
|
|
'el-form-item': { template: '<div class="el-form-item"><slot /></div>' },
|
|
|
@@ -122,25 +156,27 @@ describe('Camera View', () => {
|
|
|
|
|
|
expect(wrapper.find('.page-container').exists()).toBe(true)
|
|
|
expect(wrapper.find('.search-form').exists()).toBe(true)
|
|
|
- expect(wrapper.find('.table-actions').exists()).toBe(true)
|
|
|
+ expect(wrapper.find('.table-wrapper').exists()).toBe(true)
|
|
|
})
|
|
|
|
|
|
it('应该显示新增摄像头按钮', async () => {
|
|
|
const wrapper = mountCamera()
|
|
|
await flushPromises()
|
|
|
|
|
|
- const addButton = wrapper.find('.table-actions button')
|
|
|
- expect(addButton.exists()).toBe(true)
|
|
|
- expect(addButton.text()).toContain('新增摄像头')
|
|
|
+ const buttons = wrapper.findAll('.search-form button')
|
|
|
+ const addButton = buttons.find((b) => b.text().includes('新增'))
|
|
|
+ expect(addButton).toBeDefined()
|
|
|
})
|
|
|
|
|
|
- it('应该显示刷新列表按钮', async () => {
|
|
|
+ it('应该显示查询和重置按钮', async () => {
|
|
|
const wrapper = mountCamera()
|
|
|
await flushPromises()
|
|
|
|
|
|
- const buttons = wrapper.findAll('.table-actions button')
|
|
|
- const refreshBtn = buttons.find((b) => b.text().includes('刷新列表'))
|
|
|
- expect(refreshBtn).toBeDefined()
|
|
|
+ const buttons = wrapper.findAll('.search-form button')
|
|
|
+ const searchBtn = buttons.find((b) => b.text().includes('查询'))
|
|
|
+ const resetBtn = buttons.find((b) => b.text().includes('重置'))
|
|
|
+ expect(searchBtn).toBeDefined()
|
|
|
+ expect(resetBtn).toBeDefined()
|
|
|
})
|
|
|
})
|
|
|
|