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

[Feature] Membership authentication error handling #41

Merged
merged 3 commits into from
Feb 27, 2021
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
609 changes: 600 additions & 9 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
"@emotion/core": "^11.0.0",
"@emotion/react": "^11.1.4",
"@emotion/styled": "^11.0.0",
"@material-ui/core": "^4.11.3",
"axios": "^0.21.1",
"emotion": "^11.0.0",
"facepaint": "^1.2.1",
"lodash": "^4.17.20",
"notistack": "^1.0.4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-responsive": "^8.2.0",
Expand Down
12 changes: 8 additions & 4 deletions src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { render, fireEvent } from '@testing-library/react';

import { RecoilRoot } from 'recoil';

import { SnackbarProvider } from 'notistack';

import App from './App';
import InjectTestingRecoilState from './components/common/InjectTestingRecoilState';

describe('App', () => {
const renderApp = ({ todos }) => render((
<RecoilRoot>
<InjectTestingRecoilState
todos={todos}
/>
<App />
<SnackbarProvider>
<InjectTestingRecoilState
todos={todos}
/>
<App />
</SnackbarProvider>
</RecoilRoot>
));

Expand Down
17 changes: 15 additions & 2 deletions src/components/auth/AuthModalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { useRecoilValue, useResetRecoilState } from 'recoil';
import styled from '@emotion/styled';
import { css } from '@emotion/react';

import { FORM_TYPE } from '../../utils/constants/constants';
import authFieldsAtom, { authStatusAtom } from '../../recoil/auth';
import { useSnackbar } from 'notistack';

import { isCheckValidate } from '../../utils/utils';
import { FORM_TYPE, EMPTY_AUTH_INPUT } from '../../utils/constants/constants';

import authFieldsAtom, { authStatusAtom, authWithFields } from '../../recoil/auth';

import AuthInput from './AuthInput';

Expand Down Expand Up @@ -61,13 +65,22 @@ const AuthFormWrapper = styled.form`
`;

const AuthModalForm = () => {
const { enqueueSnackbar } = useSnackbar();

const { type, visible } = useRecoilValue(authStatusAtom);
const authFieldsState = useRecoilValue(authWithFields);

const resetAuthStatusState = useResetRecoilState(authStatusAtom);
const resetAuthFieldsState = useResetRecoilState(authFieldsAtom);

const handleSubmit = (e) => {
e.preventDefault();

if (!isCheckValidate(authFieldsState)) {
enqueueSnackbar(EMPTY_AUTH_INPUT, {
variant: 'error',
});
}
Comment on lines 76 to +83
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: api 호출 처리

};

const onCloseAuthModal = () => {
Expand Down
68 changes: 54 additions & 14 deletions src/components/auth/AuthModalForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { RecoilRoot } from 'recoil';

import { render, fireEvent } from '@testing-library/react';

import { SnackbarProvider } from 'notistack';

import InjectTestingRecoilState from '../common/InjectTestingRecoilState';
import AuthModalForm from './AuthModalForm';

Expand All @@ -22,11 +24,13 @@ const authFieldsState = {
describe('AuthModalForm', () => {
const renderAuthForm = ({ auth, fields = authFieldsState }) => render((
<RecoilRoot>
<InjectTestingRecoilState
auth={auth}
authFields={fields}
/>
<AuthModalForm />
<SnackbarProvider>
<InjectTestingRecoilState
auth={auth}
authFields={fields}
/>
<AuthModalForm />
</SnackbarProvider>
</RecoilRoot>
));

Expand Down Expand Up @@ -62,17 +66,53 @@ describe('AuthModalForm', () => {
});
});

it('When click Submit button, listen event', () => {
const props = {
auth: {
type: 'register',
visible: true,
},
};
context('Is Submit error', () => {
describe('When click Submit button, listen event', () => {
it('Renders error message "입력이 안된 사항이 있습니다."', () => {
const props = {
auth: {
type: 'register',
visible: true,
},
};

const { container, getByTestId } = renderAuthForm(props);

fireEvent.submit(getByTestId('auth-submit-button'));

const { getByTestId } = renderAuthForm(props);
expect(container).toHaveTextContent('입력이 안된 사항이 있습니다.');
});
});
});

fireEvent.submit(getByTestId('auth-submit-button'));
context("Isn't Submit error", () => {
describe('When click Submit button, listen event', () => {
it('Success submit', () => {
const props = {
auth: {
type: 'register',
visible: true,
},
fields: {
register: {
userId: 'test',
password: 'test',
passwordConfirm: 'test',
},
login: {
userId: '',
password: '',
},
},
};
Comment on lines +91 to +107
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리팩토링 필요.
중복되는 테스트 케이스 코드가 많다.
fixtures 폴더를 만들어 테스트에 필요한 데이터를 가져다가 써주자.


const { container, getByTestId } = renderAuthForm(props);

fireEvent.submit(getByTestId('auth-submit-button'));

expect(container).not.toHaveTextContent('입력이 안된 사항이 있습니다.');
});
});
});

it('When click Close button, the modal window is closed.', () => {
Expand Down
13 changes: 12 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ import ReactDOM from 'react-dom';

import { RecoilRoot } from 'recoil';

import { SnackbarProvider } from 'notistack';

import App from './App';

import './assets/css/global.css';

ReactDOM.render(
(
<RecoilRoot>
<App />
<SnackbarProvider
maxSnack={3}
preventDuplicate
anchorOrigin={{
vertical: 'top',
horizontal: 'left',
}}
>
<App />
</SnackbarProvider>
</RecoilRoot>
),
document.getElementById('app'),
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export const FORM_TYPE = {
register: 'Sign up',
logout: 'Sign out',
};

export const EMPTY_AUTH_INPUT = '입력이 안된 사항이 있습니다.';
4 changes: 4 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ export const filteredTodos = {
ACTIVE: (state) => (state.filter(isActive)),
COMPLETED: (state) => (state.filter(isCompleted)),
};

export const isCheckValidate = (inputValue) => Object
.entries(inputValue)
.every((value) => _.trim(value[1]));