From de5150b3850795f0f403223be48939104b0bd4fa Mon Sep 17 00:00:00 2001 From: Dawn1Ocean <1785590531@qq.com> Date: Wed, 17 Apr 2024 19:43:45 +0800 Subject: [PATCH] refactor: remove redundant files --- mock/requestRecord.mock.js | 22 +- mock/route.ts | 5 - mock/user.ts | 65 - models/user.ts | 24 + src/access.ts | 2 + .../Login/__snapshots__/login.test.tsx.snap | 1108 ----------------- src/pages/User/Login/login.test.tsx | 96 -- src/services/api.ts | 2 +- src/services/typings.d.ts | 13 - 9 files changed, 29 insertions(+), 1308 deletions(-) delete mode 100644 mock/route.ts create mode 100644 models/user.ts delete mode 100644 src/pages/User/Login/__snapshots__/login.test.tsx.snap delete mode 100644 src/pages/User/Login/login.test.tsx diff --git a/mock/requestRecord.mock.js b/mock/requestRecord.mock.js index c7f42cd..f34b355 100644 --- a/mock/requestRecord.mock.js +++ b/mock/requestRecord.mock.js @@ -67,31 +67,13 @@ module.exports = { data: conclusionlist, }, 'GET /api/currentUser': { + success: true, data: { name: 'Serati Ma', avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png', userid: '00000001', - email: 'antdesign@alipay.com', - signature: '海纳百川,有容乃大', - title: '交互专家', group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED', - tags: [ - { key: '0', label: '很有想法的' }, - { key: '1', label: '专注设计' }, - { key: '2', label: '辣~' }, - { key: '3', label: '大长腿' }, - { key: '4', label: '川妹子' }, - { key: '5', label: '海纳百川' }, - ], - notifyCount: 12, - unreadCount: 11, - country: 'China', - geographic: { - province: { label: '浙江省', key: '330000' }, - city: { label: '杭州市', key: '330100' }, - }, - address: '西湖区工专路 77 号', - phone: '0752-268888888', + access: 'admin', }, }, 'POST /api/login/outLogin': { data: {}, success: true }, diff --git a/mock/route.ts b/mock/route.ts deleted file mode 100644 index 418d10f..0000000 --- a/mock/route.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default { - '/api/auth_routes': { - '/form/advanced-form': { authority: ['admin', 'user'] }, - }, -}; diff --git a/mock/user.ts b/mock/user.ts index 0c9763d..b4eb580 100644 --- a/mock/user.ts +++ b/mock/user.ts @@ -42,76 +42,11 @@ export default { name: 'Serati Ma', avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png', userid: '00000001', - email: 'antdesign@alipay.com', - signature: '海纳百川,有容乃大', - title: '交互专家', group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED', - tags: [ - { - key: '0', - label: '很有想法的', - }, - { - key: '1', - label: '专注设计', - }, - { - key: '2', - label: '辣~', - }, - { - key: '3', - label: '大长腿', - }, - { - key: '4', - label: '川妹子', - }, - { - key: '5', - label: '海纳百川', - }, - ], - notifyCount: 12, - unreadCount: 11, - country: 'China', access: getAccess(), - geographic: { - province: { - label: '浙江省', - key: '330000', - }, - city: { - label: '杭州市', - key: '330100', - }, - }, - address: '西湖区工专路 77 号', - phone: '0752-268888888', }, }); }, - // GET POST 可省略 - 'GET /api/users': [ - { - key: '1', - name: 'John Brown', - age: 32, - address: 'New York No. 1 Lake Park', - }, - { - key: '2', - name: 'Jim Green', - age: 42, - address: 'London No. 1 Lake Park', - }, - { - key: '3', - name: 'Joe Black', - age: 32, - address: 'Sidney No. 1 Lake Park', - }, - ], 'POST /api/login/account': async (req: Request, res: Response) => { const { password, username, type } = req.body; await waitTime(2000); diff --git a/models/user.ts b/models/user.ts new file mode 100644 index 0000000..762bc9e --- /dev/null +++ b/models/user.ts @@ -0,0 +1,24 @@ +import { useCallback, useState } from 'react'; +export default () => { + const [user, setUser] = useState({}); + const [token, setToken] = useState(''); + + const setUserData = useCallback( + (name: string, avatar: string, group: number, title: number, access: string) => { + setUser({ + name: name, + avatar: avatar, + group: group, + title: title, + access: access, + }); + }, + [], + ); + + const setTokenStr = useCallback((token: string) => { + setToken(token); + }, []); + + return { user, setUserData, token, setTokenStr }; +}; diff --git a/src/access.ts b/src/access.ts index d527afb..3147209 100644 --- a/src/access.ts +++ b/src/access.ts @@ -1,3 +1,5 @@ +import { API } from './services/typings'; + /** * @see https://umijs.org/docs/max/access#access * */ diff --git a/src/pages/User/Login/__snapshots__/login.test.tsx.snap b/src/pages/User/Login/__snapshots__/login.test.tsx.snap deleted file mode 100644 index e6fd702..0000000 --- a/src/pages/User/Login/__snapshots__/login.test.tsx.snap +++ /dev/null @@ -1,1108 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Login Page should login success 1`] = ` - -
-
- - - -
-
-
- -
-
-
-
- -
-
-
-
-
-
-
- - - -
-
-
- - - - - -
- -
- - - - - - Serati Ma - - -
-
-
-
-
-
-
-
-
-
-
-
-
- - Welcome - -
-
-
-
-
-
-
-
-
-
-
- 欢迎使用 Ant Design Pro -
-

- Ant Design Pro 是一个整合了 umi,Ant Design 和 ProComponents 的脚手架方案。致力于在设计规范和基础组件的基础上,继续向上构建,提炼出典型模板/业务组件/配套设计资源,进一步提升企业级中后台产品设计研发过程中的『用户』和『设计者』的体验。 -

-
-
-
-
- 1 -
-
- 了解 umi -
-
-
- umi 是一个可扩展的企业级前端应用框架,umi 以路由为基础的,同时支持配置式路由和约定式路由,保证路由的功能完备,并以此进行功能扩展。 -
- - 了解更多 > - -
-
-
-
- 2 -
-
- 了解 ant design -
-
-
- antd 是基于 Ant Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。 -
- - 了解更多 > - -
-
-
-
- 3 -
-
- 了解 Pro Components -
-
-
- ProComponents 是一个基于 Ant Design 做了更高抽象的模板组件,以 一个组件就是一个页面为开发理念,为中后台开发带来更好的体验。 -
- - 了解更多 > - -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
- -`; - -exports[`Login Page should show login form 1`] = ` - -
-
- - - - - -
-
- - -`; diff --git a/src/pages/User/Login/login.test.tsx b/src/pages/User/Login/login.test.tsx deleted file mode 100644 index 4ee313c..0000000 --- a/src/pages/User/Login/login.test.tsx +++ /dev/null @@ -1,96 +0,0 @@ -import { TestBrowser } from '@@/testBrowser'; -import { act, fireEvent, render } from '@testing-library/react'; -import React from 'react'; - -// @ts-ignore -import { startMock } from '@@/requestRecordMock'; - -const waitTime = (time: number = 100) => { - return new Promise((resolve) => { - setTimeout(() => { - resolve(true); - }, time); - }); -}; - -let server: { - close: () => void; -}; - -describe('Login Page', () => { - beforeAll(async () => { - server = await startMock({ - port: 8000, - scene: 'login', - }); - }); - - afterAll(() => { - server?.close(); - }); - - it('should show login form', async () => { - const historyRef = React.createRef(); - const rootContainer = render( - , - ); - - await rootContainer.findAllByText('Ant Design'); - - act(() => { - historyRef.current?.push('/user/login'); - }); - - expect(rootContainer.baseElement?.querySelector('.ant-pro-form-login-desc')?.textContent).toBe( - 'Ant Design is the most influential web design specification in Xihu district', - ); - - expect(rootContainer.asFragment()).toMatchSnapshot(); - - rootContainer.unmount(); - }); - - it('should login success', async () => { - const historyRef = React.createRef(); - const rootContainer = render( - , - ); - - await rootContainer.findAllByText('Ant Design'); - - const userNameInput = await rootContainer.findByPlaceholderText('Username: admin or user'); - - act(() => { - fireEvent.change(userNameInput, { target: { value: 'admin' } }); - }); - - const passwordInput = await rootContainer.findByPlaceholderText('Password: ant.design'); - - act(() => { - fireEvent.change(passwordInput, { target: { value: 'ant.design' } }); - }); - - await (await rootContainer.findByText('Login')).click(); - - // 等待接口返回结果 - await waitTime(5000); - - await rootContainer.findAllByText('Ant Design Pro'); - - expect(rootContainer.asFragment()).toMatchSnapshot(); - - await waitTime(2000); - - rootContainer.unmount(); - }); -}); diff --git a/src/services/api.ts b/src/services/api.ts index 123d5c6..2a54275 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -33,7 +33,7 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an }); } -/** 获取首页信息 GET /admin/stat */ +/** 获取首页信息 GET /admin/stats */ export async function getStat(options?: { [key: string]: any }) { return request<{ data: API.Stat; diff --git a/src/services/typings.d.ts b/src/services/typings.d.ts index 2c5c6c5..acbcde8 100644 --- a/src/services/typings.d.ts +++ b/src/services/typings.d.ts @@ -5,21 +5,8 @@ declare namespace API { name?: string; avatar?: string; userid?: string; - email?: string; - signature?: string; - title?: string; group?: string; - tags?: { key?: string; label?: string }[]; - notifyCount?: number; - unreadCount?: number; - country?: string; access?: string; - geographic?: { - province?: { label?: string; key?: string }; - city?: { label?: string; key?: string }; - }; - address?: string; - phone?: string; }; type LoginResult = {