浏览代码

test: 增加容器管理测试

xyh 2 年之前
父节点
当前提交
1b10b70665

+ 145 - 0
cypress/e2e/container.cy.ts

@@ -0,0 +1,145 @@
+import {
+  beforeSetup,
+  exportIntercept,
+  generateNetworkResult,
+  intercept,
+  intoMenu,
+  successIntercept,
+  tableBtnClick,
+  validateDelete,
+  validateModalOperation,
+  validatePut,
+  validateTableList,
+  validateTableSearch,
+} from './utils';
+
+const basicData = {
+  id: '5',
+  department: '涂装班组',
+  departmentId: '000300010012',
+  type: '充电桩底座+1',
+  containerName: '特来电002',
+  code: '00002',
+  num: '9',
+  createTime: '2023-03-31 10:11:27',
+  modifyUser: 'admin',
+  modifyTime: '2023-03-31 10:46:30',
+  page: 0,
+  limit: 0,
+};
+
+const scrapBasicData = {
+  id: '6',
+  operationName: 'admin',
+  name: null,
+  scrapCause: '1',
+  scrapTime: '2023-03-31 10:46:30',
+  scrapNum: '1',
+  startTime: null,
+  endTime: null,
+  containerName: '特来电002',
+  page: 0,
+  limit: 0,
+};
+
+describe('容器管理', function () {
+  beforeEach(function () {
+    beforeSetup(true);
+    intoMenu('基础资料', '容器管理');
+  });
+
+  beforeEach(function () {
+    intercept('/container/getContainer', function ({reply, search}) {
+      generateNetworkResult({reply, search, basicData, title: 'code'});
+    });
+
+    intercept('/container/getScrap', function ({reply, search}) {
+      generateNetworkResult({
+        reply,
+        search,
+        basicData: scrapBasicData,
+        title: 'operationName',
+        skipCondition: name => name === 'containerName',
+      });
+    });
+
+    successIntercept([
+      '/container/addContainer',
+      '/container/updateContainer',
+      '/container/delCon',
+      '/container/delContainer',
+    ]);
+
+    exportIntercept('/container/exportScrap');
+    exportIntercept('/container/export');
+  });
+
+  it('table', function () {
+    validateTableList('container_table');
+    validateTableSearch(
+      'container_table',
+      [
+        'containerCode',
+        'containerName',
+        'containerType',
+        {id: 'department', type: 'select', value: '00029999'},
+        'modifyUser',
+      ],
+      {toolId: 'container_filter', url: '/container/getContainer'},
+    );
+  });
+
+  it('operation', function () {
+    const {validateAdd, validateEdit} = validatePut(
+      'container_modal',
+      'container_table',
+      {
+        label: '容器',
+      },
+    );
+
+    validateAdd([
+      'containerName',
+      'containerCode',
+      'containerType',
+      {id: 'containerNum', type: 'field', value: '10'},
+      {id: 'containerDepartment', type: 'select'},
+    ]);
+
+    validateEdit([
+      {id: 'containerName', type: 'field', value: basicData.containerName},
+      {id: 'containerCode', type: 'field', value: basicData.code},
+      {id: 'containerType', type: 'field', value: basicData.type},
+      {id: 'containerNum', type: 'field', value: basicData.num},
+      {id: 'containerDepartment', type: 'select', value: basicData.department},
+    ]);
+
+    validateDelete('container_table', '容器', {
+      eq: 3,
+      title: basicData.containerName,
+    });
+
+    //报废
+    tableBtnClick('container_table', 1);
+    cy.getTestId('container_scrap_modal')
+      .find('h3')
+      .should('have.text', '容器报废');
+
+    cy.getTestId('field_scrapNum').clear().type('2');
+    cy.getTestId('field_scrapNote').type('报废理由');
+
+    validateModalOperation('container_scrap_modal', '报废成功');
+  });
+
+  it('报废列表', function () {
+    tableBtnClick('container_table', 2);
+
+    validateTableList('container_scrap_table');
+
+    validateTableSearch(
+      'container_scrap_table',
+      ['operationName', {id: 'containerDate', type: 'date'}],
+      {toolId: 'container_scrap_filter', url: '/container/getScrap'},
+    );
+  });
+});

+ 46 - 38
cypress/e2e/utils/utils.ts

@@ -58,11 +58,35 @@ export function validateTableList(tableName: string) {
     .should('include.text', 'page-2');
     .should('include.text', 'page-2');
 }
 }
 
 
+/** 选择时间组件 */
+export function clickDatePicker(id: string) {
+  cy.getTestId(id).click();
+
+  cy.get('.ant-picker-panels')
+    .children()
+    .eq(0)
+    .find('.ant-picker-content')
+    .find('tbody')
+    .find('td')
+    .eq(0)
+    .click();
+
+  cy.get('.ant-picker-panels')
+    .children()
+    .eq(1)
+    .find('.ant-picker-content')
+    .find('tbody')
+    .find('td')
+    .eq(0)
+    .click();
+}
+
 /** 校验table search */
 /** 校验table search */
 export function validateTableSearch(
 export function validateTableSearch(
   tableName: string,
   tableName: string,
   keys: (
   keys: (
-    | {id: string; type: 'select' | 'date'; value: string; eq?: number}
+    | {id: string; type: 'select'; value: string; eq?: number}
+    | {id: string; type: 'date'}
     | string
     | string
   )[],
   )[],
   options: {
   options: {
@@ -82,15 +106,13 @@ export function validateTableSearch(
       if (typeof key === 'string') {
       if (typeof key === 'string') {
         cy.getTestId(toolId).find(`[data-testid="filter_${key}"]`).clear();
         cy.getTestId(toolId).find(`[data-testid="filter_${key}"]`).clear();
       } else {
       } else {
-        const {id, type} = key;
-
-        if (type === 'select') {
-          cy.getTestId(toolId)
-            .find(`[data-testid="filter_${id}"]`)
-            .trigger('mouseover')
-            .find('.ant-select-clear')
-            .click();
-        }
+        const {id} = key;
+
+        cy.getTestId(toolId)
+          .find(`[data-testid="filter_${id}"]`)
+          .trigger('mouseover')
+          .find('.ant-select-clear')
+          .click();
       }
       }
     }
     }
 
 
@@ -136,11 +158,17 @@ export function validateTableSearch(
       cy.getTestId(toolId).find(`[data-testid="filter_${key}"]`).type(key);
       cy.getTestId(toolId).find(`[data-testid="filter_${key}"]`).type(key);
       validate(key);
       validate(key);
     } else {
     } else {
-      const {id, type, value} = key;
+      const {id, type} = key;
 
 
-      if (type === 'select') {
-        selectClick(`filter_${id}`, key?.eq ?? 0);
-        validate(value);
+      switch (type) {
+        case 'select':
+          selectClick(`filter_${id}`, key?.eq ?? 0);
+          validate(key.value);
+          break;
+        case 'date':
+          clickDatePicker(`filter_${id}`);
+          validate('searchTime');
+          break;
       }
       }
     }
     }
   });
   });
@@ -354,29 +382,6 @@ export function closeModal() {
   cy.get('.ReactModal__Overlay').trigger('click', 'topRight');
   cy.get('.ReactModal__Overlay').trigger('click', 'topRight');
 }
 }
 
 
-/** 选择时间组件 */
-export function clickDatePicker(id: string) {
-  cy.getTestId(id).click();
-
-  cy.get('.ant-picker-panels')
-    .children()
-    .eq(0)
-    .find('.ant-picker-content')
-    .find('tbody')
-    .find('td')
-    .eq(0)
-    .click();
-
-  cy.get('.ant-picker-panels')
-    .children()
-    .eq(1)
-    .find('.ant-picker-content')
-    .find('tbody')
-    .find('td')
-    .eq(0)
-    .click();
-}
-
 /** 选择所有的筛选框 */
 /** 选择所有的筛选框 */
 export function selectAllFilters(toolId: string, count: number) {
 export function selectAllFilters(toolId: string, count: number) {
   indexedDB.deleteDatabase('filterGroup');
   indexedDB.deleteDatabase('filterGroup');
@@ -461,7 +466,10 @@ export function generateNetworkResult<
           limit,
           limit,
           isList: true,
           isList: true,
           title,
           title,
-          value: searchValue,
+          value:
+            name === 'startTime' || name === 'endTime'
+              ? 'searchTime'
+              : searchValue,
         }),
         }),
       });
       });
     }
     }

+ 7 - 2
packages/app/src/pages/container-scrap/filter/index.tsx

@@ -28,12 +28,17 @@ const Filter: FC = function () {
   const [, {onSearch, onReset}] = useTableSearchToolEvents(
   const [, {onSearch, onReset}] = useTableSearchToolEvents(
     context,
     context,
     {...fields, startTime: start, endTime: end, containerName},
     {...fields, startTime: start, endTime: end, containerName},
-    {resetCallback: resetState},
+    {
+      resetCallback() {
+        resetState();
+        setDates([null, null]);
+      },
+    },
   );
   );
 
 
   return (
   return (
     <Card>
     <Card>
-      <FilterFieldWrapper onSearch={onSearch}>
+      <FilterFieldWrapper onSearch={onSearch} testId='container_scrap_filter'>
         <FilterField
         <FilterField
           label='工号'
           label='工号'
           name='operationName'
           name='operationName'

+ 1 - 1
packages/app/src/pages/container/filter/index.tsx

@@ -30,7 +30,7 @@ const Filter: FC = function () {
 
 
   return (
   return (
     <Card>
     <Card>
-      <FilterFieldWrapper onSearch={onSearch}>
+      <FilterFieldWrapper onSearch={onSearch} testId='container_filter'>
         <FilterField
         <FilterField
           name='containerCode'
           name='containerCode'
           label='容器编号'
           label='容器编号'