Ver Fonte

test(machine): update tests to match new page structure

- Add missing component stubs (el-select, el-option, el-date-picker)
- Update test assertions for new search form layout
- Replace deprecated button text references

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
yb há 2 semanas atrás
pai
commit
8d89463909
1 ficheiros alterados com 51 adições e 29 exclusões
  1. 51 29
      tests/unit/views/machine/index.spec.ts

+ 51 - 29
tests/unit/views/machine/index.spec.ts

@@ -48,11 +48,14 @@ describe('Machine View', () => {
           },
           'el-table': {
             template: '<table class="el-table" data-id="machine-table"><slot /></table>',
-            props: ['data', 'loading', 'border']
+            props: ['data', 'loading', 'border', 'height'],
+            methods: {
+              clearSelection() {}
+            }
           },
           'el-table-column': {
             template: '<td class="el-table-column"></td>',
-            props: ['prop', 'label', 'width', 'align', 'type', 'fixed', 'minWidth', 'showOverflowTooltip']
+            props: ['prop', 'label', 'width', 'align', 'type', 'fixed', 'minWidth', 'showOverflowTooltip', 'sortable']
           },
           'el-tag': { template: '<span class="el-tag"><slot /></span>', props: ['type'] },
           'el-link': {
@@ -70,7 +73,7 @@ describe('Machine View', () => {
           },
           'el-form': {
             template: '<form class="el-form" data-id="form-machine"><slot /></form>',
-            props: ['model', 'rules', 'labelWidth'],
+            props: ['model', 'rules', 'labelWidth', 'inline'],
             methods: {
               validate(callback: Function) {
                 callback(false)
@@ -83,7 +86,29 @@ describe('Machine View', () => {
           'el-input': {
             template:
               '<input :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" :disabled="disabled" :placeholder="placeholder" />',
-            props: ['modelValue', 'placeholder', 'disabled', 'type', 'rows']
+            props: ['modelValue', 'placeholder', 'disabled', 'type', 'rows', 'clearable']
+          },
+          'el-select': {
+            template:
+              '<select :value="modelValue" @change="$emit(\'update:modelValue\', $event.target.value)"><slot /></select>',
+            props: ['modelValue', 'placeholder', 'clearable']
+          },
+          'el-option': {
+            template: '<option :value="value">{{ label }}</option>',
+            props: ['label', 'value']
+          },
+          'el-date-picker': {
+            template:
+              '<input type="text" :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />',
+            props: [
+              'modelValue',
+              'type',
+              'rangeSeparator',
+              'startPlaceholder',
+              'endPlaceholder',
+              'valueFormat',
+              'clearable'
+            ]
           },
           'el-switch': {
             template:
@@ -92,6 +117,7 @@ describe('Machine View', () => {
           },
           Plus: { template: '<span>Plus</span>' },
           Refresh: { template: '<span>Refresh</span>' },
+          Search: { template: '<span>Search</span>' },
           Edit: { template: '<span>Edit</span>' },
           Delete: { template: '<span>Delete</span>' }
         }
@@ -105,23 +131,23 @@ describe('Machine View', () => {
       await flushPromises()
 
       expect(wrapper.find('.page-container').exists()).toBe(true)
-      expect(wrapper.find('.table-actions').exists()).toBe(true)
+      expect(wrapper.find('.search-form').exists()).toBe(true)
     })
 
-    it('应该显示新增机器按钮', async () => {
+    it('应该显示新增按钮', async () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增机器'))
+      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增'))
       expect(addBtn).toBeDefined()
     })
 
-    it('应该显示刷新列表按钮', async () => {
+    it('应该显示查询按钮', async () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const refreshBtn = wrapper.findAll('button').find((btn) => btn.text().includes('刷新列表'))
-      expect(refreshBtn).toBeDefined()
+      const searchBtn = wrapper.findAll('button').find((btn) => btn.text().includes('查询'))
+      expect(searchBtn).toBeDefined()
     })
 
     it('应该显示数据表格', async () => {
@@ -147,27 +173,23 @@ describe('Machine View', () => {
       expect(mockListMachines).toHaveBeenCalled()
     })
 
-    it('点击刷新按钮应该重新加载数据', async () => {
+    it('应该显示查询和重置按钮', async () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      mockListMachines.mockClear()
-
-      const refreshBtn = wrapper.findAll('button').find((btn) => btn.text().includes('刷新列表'))
-      if (refreshBtn) {
-        await refreshBtn.trigger('click')
-        await flushPromises()
-        expect(mockListMachines).toHaveBeenCalled()
-      }
+      const searchBtn = wrapper.findAll('button').find((btn) => btn.text().includes('查询'))
+      const resetBtn = wrapper.findAll('button').find((btn) => btn.text().includes('重置'))
+      expect(searchBtn).toBeDefined()
+      expect(resetBtn).toBeDefined()
     })
   })
 
-  describe('新增机器', () => {
+  describe('新增', () => {
     it('点击新增按钮应该打开弹窗', async () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增机器'))
+      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增'))
       if (addBtn) {
         await addBtn.trigger('click')
         await flushPromises()
@@ -175,7 +197,7 @@ describe('Machine View', () => {
       }
     })
 
-    it('新增机器成功应该刷新列表并关闭弹窗', async () => {
+    it('新增成功应该重置并关闭弹窗', async () => {
       mockAddMachine.mockResolvedValue(wrapResponse({ id: 4, machineId: 'machine-004' }))
 
       const wrapper = mountMachine()
@@ -184,11 +206,11 @@ describe('Machine View', () => {
       expect(mockListMachines).toHaveBeenCalled()
     })
 
-    it('新增机器时应该显示正确的弹窗标题', async () => {
+    it('新增时应该显示正确的弹窗标题', async () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增机器'))
+      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增'))
       if (addBtn) {
         await addBtn.trigger('click')
         await flushPromises()
@@ -199,7 +221,7 @@ describe('Machine View', () => {
   })
 
   describe('编辑机器', () => {
-    it('编辑机器成功应该刷新列表', async () => {
+    it('编辑机器成功应该重置', async () => {
       mockUpdateMachine.mockResolvedValue(wrapResponse(mockMachines[0]))
 
       const wrapper = mountMachine()
@@ -224,7 +246,7 @@ describe('Machine View', () => {
   })
 
   describe('删除机器', () => {
-    it('删除机器成功应该刷新列表', async () => {
+    it('删除机器成功应该重置', async () => {
       const { ElMessage } = await import('element-plus')
       mockDeleteMachine.mockResolvedValue(wrapResponse(null))
 
@@ -278,7 +300,7 @@ describe('Machine View', () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增机器'))
+      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增'))
       if (addBtn) {
         await addBtn.trigger('click')
         await flushPromises()
@@ -301,7 +323,7 @@ describe('Machine View', () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增机器'))
+      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增'))
       if (addBtn) {
         await addBtn.trigger('click')
         await flushPromises()
@@ -357,7 +379,7 @@ describe('Machine View', () => {
       const wrapper = mountMachine()
       await flushPromises()
 
-      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增机器'))
+      const addBtn = wrapper.findAll('button').find((btn) => btn.text().includes('新增'))
       if (addBtn) {
         await addBtn.trigger('click')
         await flushPromises()