Parcourir la source

test: 修改多tab下的测试逻辑

xyh il y a 2 ans
Parent
commit
de167bffeb
3 fichiers modifiés avec 20 ajouts et 13 suppressions
  1. 5 10
      cypress/e2e/utils/utils.ts
  2. 2 0
      cypress/tsconfig.json
  3. 13 3
      packages/app/src/pages/home/main/hooks.tsx

+ 5 - 10
cypress/e2e/utils/utils.ts

@@ -1,4 +1,5 @@
 import {StaticResponse} from 'cypress/types/net-stubbing';
+import menuJson from '../../fixtures/menu/basic.json';
 
 /** 点击select具体项 */
 export function selectClick(testid: string, eq = 0) {
@@ -12,16 +13,10 @@ export function selectClick(testid: string, eq = 0) {
 
 /** 进入具体菜单 */
 export function intoMenu(parent: string, child: string) {
-  cy.getTestId('menu')
-    .children()
-    .each(function (el) {
-      const titleElement = el.find('.ant-menu-submenu-title');
-
-      if (titleElement.text() === parent) {
-        titleElement.trigger('click');
-        el.find(`ul>li[title="${child}"]`).trigger('click');
-      }
-    });
+  cy.wait('@loginIntercept');
+  const list = menuJson.data;
+  const menu = list.find(val => val.name === child);
+  menu && cy.visit(menu);
 }
 
 /** 校验select */

+ 2 - 0
cypress/tsconfig.json

@@ -3,6 +3,8 @@
     "baseUrl": ".",
     "target": "ES5",
     "downlevelIteration": true,
+    "resolveJsonModule": true,
+    "esModuleInterop": true,
     "lib": [
       "ES5",
       "DOM"

+ 13 - 3
packages/app/src/pages/home/main/hooks.tsx

@@ -1,6 +1,6 @@
 import {useContextSection} from '@hooks';
 import {context} from '../context';
-import {TabPaneProps, TabsProps} from 'antd';
+import {Modal, TabPaneProps, TabsProps} from 'antd';
 import {ReactNode} from 'react';
 import css from './index.module.css';
 import {useStore} from 'zustand';
@@ -22,7 +22,11 @@ export function useTabItems() {
         closable: tab.key !== '-1',
         animated: true,
         children: (
-          <iframe src={`http://${host}${tab.url}`} className={css.iframe} />
+          <iframe
+            src={`http://${host}${tab.url}`}
+            className={css.iframe}
+            data-url={tab.url}
+          />
         ),
       };
     });
@@ -34,7 +38,13 @@ export function useTabActive() {
   const {key: activeKey, dispatch: setActiveKey} = useStore(tabStore);
 
   function onClear() {
-    dispatch({type: 'CLEAR'});
+    Modal.confirm({
+      title: '清除标签页',
+      content: '你确定要关闭所有标签页吗?',
+      onOk() {
+        dispatch({type: 'CLEAR'});
+      },
+    });
   }
 
   const onEdit: TabsProps['onEdit'] = function (target, action) {