Browse Source

fix test error and warning

tumao 4 years ago
parent
commit
ea3f15f9bd

+ 9 - 0
client/package.json

@@ -29,10 +29,19 @@
     "typescript": "^4.1.2",
     "typescript": "^4.1.2",
     "web-vitals": "^1.0.1"
     "web-vitals": "^1.0.1"
   },
   },
+  "jest": {
+    "collectCoverage": true,
+    "coverageReporters": [
+      "json"
+    ]
+  },
   "scripts": {
   "scripts": {
     "start": "react-app-rewired start -FAST_REFRESH=true",
     "start": "react-app-rewired start -FAST_REFRESH=true",
     "build": "react-app-rewired build",
     "build": "react-app-rewired build",
     "test": "react-app-rewired test",
     "test": "react-app-rewired test",
+    "test:watch": "react-app-rewired test --watch",
+    "test:cov": "react-app-rewired test --watchAll=false --coverage",
+    "test:report": "react-app-rewired test --watchAll=false --coverageReporters='text-summary'",
     "eject": "react-app-rewired eject"
     "eject": "react-app-rewired eject"
   },
   },
   "eslintConfig": {
   "eslintConfig": {

+ 6 - 0
client/src/components/__test__/copy/Copy.spec.tsx

@@ -3,6 +3,12 @@ import { act } from 'react-dom/test-utils';
 import Copy from '../../copy/Copy';
 import Copy from '../../copy/Copy';
 let container: any = null;
 let container: any = null;
 
 
+jest.mock('react-i18next', () => ({
+  useTranslation: () => ({
+    t: (key: any) => key,
+  }),
+}));
+
 jest.mock('@material-ui/core/Tooltip', () => {
 jest.mock('@material-ui/core/Tooltip', () => {
   return props => {
   return props => {
     return <div id="tooltip">{props.children}</div>;
     return <div id="tooltip">{props.children}</div>;

+ 6 - 0
client/src/components/__test__/customDialog/CustomDialog.spec.tsx

@@ -6,6 +6,12 @@ import CustomDialog from '../../customDialog/CustomDialog';
 
 
 let container: any = null;
 let container: any = null;
 
 
+jest.mock('react-i18next', () => ({
+  useTranslation: () => ({
+    t: (key: any) => key,
+  }),
+}));
+
 jest.mock('@material-ui/core/Dialog', () => {
 jest.mock('@material-ui/core/Dialog', () => {
   return props => {
   return props => {
     return <div id="dialog-wrapper">{props.children}</div>;
     return <div id="dialog-wrapper">{props.children}</div>;

+ 18 - 0
client/src/components/__test__/layout/Layout.spec.tsx

@@ -4,6 +4,24 @@ import Layout from '../../layout/Layout';
 
 
 let container: any = null;
 let container: any = null;
 
 
+jest.mock('react-i18next', () => ({
+  useTranslation: () => ({
+    t: (key: any) => key,
+  }),
+}));
+
+jest.mock('react-router-dom', () => ({
+  useHistory: () => ({
+    push: jest.fn(),
+  }),
+  useLocation: () => ({
+    hash: '',
+    pathname: '/use-location-mock',
+    search: '',
+    state: undefined,
+  }),
+}));
+
 jest.mock('../../layout/GlobalEffect', () => {
 jest.mock('../../layout/GlobalEffect', () => {
   return () => {
   return () => {
     return <div id="global">{}</div>;
     return <div id="global">{}</div>;

+ 4 - 0
client/src/components/__test__/textField/customInput.spec.tsx

@@ -10,6 +10,10 @@ import {
 
 
 let container: any = null;
 let container: any = null;
 
 
+jest.mock('@material-ui/core/styles/makeStyles', () => {
+  return () => () => ({});
+});
+
 jest.mock('@material-ui/core/FormControl', () => {
 jest.mock('@material-ui/core/FormControl', () => {
   return props => {
   return props => {
     const { children } = props;
     const { children } = props;

+ 0 - 10
client/src/components/layout/Layout.tsx

@@ -25,16 +25,6 @@ const useStyles = makeStyles((theme: Theme) =>
       height: '100vh',
       height: '100vh',
       overflowY: 'scroll',
       overflowY: 'scroll',
     },
     },
-    activeConsole: {
-      '& path': {
-        fill: theme.palette.primary.main,
-      },
-    },
-    normalConsole: {
-      '& path': {
-        fill: theme.palette.milvusGrey.dark,
-      },
-    },
   })
   })
 );
 );
 
 

+ 18 - 16
client/src/components/menu/SimpleMenu.tsx

@@ -48,22 +48,24 @@ const SimpleMenu: FC<SimpleMenuType> = props => {
         anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
         anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
         transformOrigin={{ vertical: 'top', horizontal: 'center' }}
         transformOrigin={{ vertical: 'top', horizontal: 'center' }}
       >
       >
-        {menuItems.map((v, i) =>
-          typeof v.label === 'string' ? (
-            <MenuItem
-              classes={{ root: classes.menuItem }}
-              onClick={() => {
-                v.callback && v.callback();
-                handleClose();
-              }}
-              key={v.label + i}
-            >
-              {v.label}
-            </MenuItem>
-          ) : (
-            <span key={i}>{v.label}</span>
-          )
-        )}
+        <div>
+          {menuItems.map((v, i) =>
+            typeof v.label === 'string' ? (
+              <MenuItem
+                classes={{ root: classes.menuItem }}
+                onClick={() => {
+                  v.callback && v.callback();
+                  handleClose();
+                }}
+                key={v.label + i}
+              >
+                {v.label}
+              </MenuItem>
+            ) : (
+              <span key={i}>{v.label}</span>
+            )
+          )}
+        </div>
       </Menu>
       </Menu>
     </div>
     </div>
   );
   );

+ 2 - 2
client/src/http/Axios.ts

@@ -1,8 +1,8 @@
 import axios from 'axios';
 import axios from 'axios';
 // import { SESSION } from '../consts/Localstorage';
 // import { SESSION } from '../consts/Localstorage';
 
 
-console.log(process.env.NODE_ENV, 'api:', process.env.REACT_APP_BASE_URL);
-console.log('docker env', (window as any)._env_);
+// console.log(process.env.NODE_ENV, 'api:', process.env.REACT_APP_BASE_URL);
+// console.log('docker env', (window as any)._env_);
 
 
 export const url =
 export const url =
   ((window as any)._env_ && (window as any)._env_.HOST_URL) ||
   ((window as any)._env_ && (window as any)._env_.HOST_URL) ||