Skip to content

Commit

Permalink
✅ test: 修正单测
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Mar 20, 2022
1 parent 567bd21 commit cd68ab2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 48 deletions.
28 changes: 6 additions & 22 deletions packages/user-panel/src/components/Footer/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,25 @@ import React from 'react';
import { render } from '@testing-library/react';

import { Footer } from './index';
import { IntlProvider } from '../Intl';
import '../../locales';

describe('Footer 组件', () => {
it('登录页脚', () => {
const { container } = render(
<IntlProvider>
<Footer type={'login'} />
</IntlProvider>,
);
const { container } = render(<Footer type={'login'} />);
expect(container).toMatchSnapshot();
});
it('微信登陆页面', () => {
const { container } = render(
<IntlProvider>
<Footer type={'register'} onWechatLoginClick={() => {}} />
</IntlProvider>,
);
const { container } = render(<Footer type={'register'} onWechatLoginClick={() => {}} />);
expect(container).toMatchSnapshot();
});
it('忘记密码', () => {
const { container } = render(
<IntlProvider>
<Footer type={'forgot'} />
</IntlProvider>,
);
const { container } = render(<Footer type={'forgot'} />);
expect(container).toMatchSnapshot();
});
it('空', () => {
const { container } = render(
<IntlProvider>
<Footer
// @ts-ignore
type={''}
/>
</IntlProvider>,
// @ts-ignore
<Footer type={''} />,
);
expect(container).toMatchSnapshot();
});
Expand Down
8 changes: 2 additions & 6 deletions packages/user-panel/src/components/Header/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import React from 'react';
import { render } from '@testing-library/react';

import { Header } from './index';
import { IntlProvider } from '../Intl';
import '../../locales';

describe('Header 组件', () => {
it('登录头部', () => {
const { container } = render(
<IntlProvider>
<Header type={'login'} />
</IntlProvider>,
);
const { container } = render(<Header type={'login'} />);
expect(container).toMatchSnapshot();
});
});
20 changes: 4 additions & 16 deletions packages/user-panel/src/components/WechatLogin/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@ import { render, fireEvent } from '@testing-library/react';
import { act } from '@testing-library/react-hooks';

import WechatLogin from './index';
import { IntlProvider } from '../Intl';
import '../../locales';

describe('WechatLogin 组件', () => {
it('默认状态', () => {
const { container } = render(
<IntlProvider>
<WechatLogin />
</IntlProvider>,
);
const { container } = render(<WechatLogin />);
expect(container).toMatchSnapshot();
});

it('点击微信登录按钮', async () => {
const fn = jest.fn();
const { findByTestId } = render(
<IntlProvider>
<WechatLogin login={fn} />
</IntlProvider>,
);
const { findByTestId } = render(<WechatLogin login={fn} />);
const btn = await findByTestId('wechat-btn');
fireEvent.click(btn);

expect(fn).toBeCalledTimes(1);
});
it('没有实现方法时报错', async () => {
const { findByTestId } = render(
<IntlProvider>
<WechatLogin />
</IntlProvider>,
);
const { findByTestId } = render(<WechatLogin />);

const btn = await findByTestId('wechat-btn');

Expand Down
7 changes: 3 additions & 4 deletions packages/user-panel/src/locales/en-US/login.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export default {
'login.accountLogin.tab': 'Account Login',
'login.accountLogin.errorMessage':
'Incorrect username/password(admin/ant.design)',
'login.username.placeholder': 'Username: admin or user',
'login.accountLogin.errorMessage': 'Incorrect username/password',
'login.username.placeholder': 'Username',
'login.username.required': 'Please input your username!',
'login.password.placeholder': 'Password: ant.design',
'login.password.placeholder': 'Password',
'login.password.required': 'Please input your password!',
'login.phoneLogin.tab': 'Phone Login',
'login.phoneLogin.errorMessage': 'Verification Code Error',
Expand Down
4 changes: 4 additions & 0 deletions packages/user-panel/src/login/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';

import Login from './index';
import '../locales';
import i18n from '../locales';

i18n.changeLanguage('zh-CN');

describe('Login 组件', () => {
it('默认状态', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/user-panel/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';

import UserPanel from '@arvinxu/user-panel';
import i18n from '../src/locales';

i18n.changeLanguage('zh-CN');

describe('UserPanel', () => {
it('登录面板', async () => {
Expand Down

0 comments on commit cd68ab2

Please sign in to comment.