Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test]:(Account) Supplementary testing coverage #233

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/base/src/page/Account/components/UserEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const UserEmail: React.FC<UpdateComponentCommonProps> = ({
});
};
const emailValidator = (value: string): boolean => {
if (!value) return false;

if (!emailValidate(value)) {
if (value && !emailValidate(value)) {
messageApi.error(t('dmsAccount.emailErrorMessage.type'));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import account from '../../../../testUtils/mockApi/account';
describe('test base/page/Account/UserEmail', () => {
const updateUserInfoSpy = jest.fn();
const messageSuccessSpy = jest.fn();
const messageErrorSpy = jest.fn();

const customRender = (email?: string) => {
return renderWithTheme(
<UserEmail
messageApi={{ success: messageSuccessSpy } as any}
messageApi={{
success: messageSuccessSpy,
error: messageErrorSpy,
info: jest.fn(),
warning: jest.fn(),
loading: jest.fn(),
open: jest.fn(),
destroy: jest.fn()
}}
updateUserInfo={updateUserInfoSpy}
userBaseInfo={{ email }}
/>
Expand All @@ -34,7 +43,7 @@ describe('test base/page/Account/UserEmail', () => {
});

it('execute the onSubmit after triggering the enter event', async () => {
const { container } = customRender();
const { container } = customRender('[email protected]');

fireEvent.mouseEnter(
getBySelector('.ant-row,.ant-row-space-between.ant-row-middle', container)
Expand All @@ -46,10 +55,36 @@ describe('test base/page/Account/UserEmail', () => {

fireEvent.change(inputEle, {
target: {
value: '[email protected]'
value: 'submit.com'
}
});
fireEvent.keyDown(inputEle, {
key: 'Enter',
code: 'Enter',
keyCode: 13
});
expect(messageErrorSpy).toBeCalledTimes(1);
expect(messageErrorSpy).toBeCalledWith('请输入正确格式的邮箱地址');

fireEvent.change(inputEle, {
target: {
value: '[email protected]'
}
});
fireEvent.keyDown(inputEle, {
key: 'Enter',
code: 'Enter',
keyCode: 13
});
expect(messageErrorSpy).toBeCalledTimes(2);
expect(messageErrorSpy).toBeCalledWith('新邮箱地址不能与旧地址一致');
expect(updateCurrentUserSpy).toBeCalledTimes(0);

fireEvent.change(inputEle, {
target: {
value: '[email protected]'
}
});
fireEvent.keyDown(inputEle, {
key: 'Enter',
code: 'Enter',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import account from '../../../../testUtils/mockApi/account';
describe('test base/page/Account/UserPhone', () => {
const updateUserInfoSpy = jest.fn();
const messageSuccessSpy = jest.fn();
const messageErrorSpy = jest.fn();

const customRender = (phone?: string) => {
return renderWithTheme(
<UserPhone
messageApi={{ success: messageSuccessSpy } as any}
messageApi={{
success: messageSuccessSpy,
error: messageErrorSpy,
info: jest.fn(),
warning: jest.fn(),
loading: jest.fn(),
open: jest.fn(),
destroy: jest.fn()
}}
updateUserInfo={updateUserInfoSpy}
userBaseInfo={{ phone }}
/>
Expand All @@ -34,7 +43,7 @@ describe('test base/page/Account/UserPhone', () => {
});

it('execute the onSubmit after triggering the enter event', async () => {
const { container } = customRender();
const { container } = customRender('13112134353');

fireEvent.mouseEnter(
getBySelector('.ant-row,.ant-row-space-between.ant-row-middle', container)
Expand All @@ -44,6 +53,33 @@ describe('test base/page/Account/UserPhone', () => {

const inputEle = getBySelector('input.ant-input#editInput', container);

fireEvent.change(inputEle, {
target: {
value: 'submit.com'
}
});
fireEvent.keyDown(inputEle, {
key: 'Enter',
code: 'Enter',
keyCode: 13
});
expect(messageErrorSpy).toBeCalledTimes(1);
expect(messageErrorSpy).toBeCalledWith('请输入正确格式的手机号码');

fireEvent.change(inputEle, {
target: {
value: '13112134353'
}
});
fireEvent.keyDown(inputEle, {
key: 'Enter',
code: 'Enter',
keyCode: 13
});
expect(messageErrorSpy).toBeCalledTimes(2);
expect(messageErrorSpy).toBeCalledWith('新手机号码不能与旧号码一致');
expect(updateCurrentUserSpy).toBeCalledTimes(0);

fireEvent.change(inputEle, {
target: {
value: '13214334343'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`test base/page/Account/UserEmail execute the onSubmit after triggering
class="ant-space-item"
style="margin-right: 8px;"
>
-
[email protected]
</div>
<div
class="ant-space-item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`test base/page/Account/UserPhone execute the onSubmit after triggering
class="ant-space-item"
style="margin-right: 8px;"
>
-
13112134353
</div>
<div
class="ant-space-item"
Expand Down
Loading