Skip to content

Commit d11de11

Browse files
committed
Merge branch 'master' of github.com:velopert/velog-client
2 parents 697a79b + 5d85301 commit d11de11

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/components/write/PublishSeriesCreate.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import OutsideClickHandler from 'react-outside-click-handler';
55
import Button from '../common/Button';
66
import useInputs from '../../lib/hooks/useInputs';
77
import { escapeForUrl } from '../../lib/utils';
8+
import { toast } from 'react-toastify';
89

910
const fadeIn = keyframes`
1011
from {
@@ -147,6 +148,10 @@ const PublishSeriesCreate: React.FC<PublishSeriesCreateProps> = ({
147148

148149
const submit = (e: FormEvent) => {
149150
e.preventDefault();
151+
if (form.name.trim() === '') {
152+
toast.error('시리즈 제목이 비어있습니다.');
153+
return;
154+
}
150155
onSubmit({
151156
name: form.name,
152157
urlSlug: form.urlSlug || defaultUrlSlug,

src/components/write/__tests__/PublishSeriesCreate.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import PublishSeriesCreate, {
99
PublishSeriesCreateProps,
1010
} from '../PublishSeriesCreate';
11+
import { toast } from 'react-toastify';
1112

1213
describe('PublishSeriesCreate', () => {
1314
const setup = (props: Partial<PublishSeriesCreateProps> = {}) => {
@@ -80,6 +81,20 @@ describe('PublishSeriesCreate', () => {
8081
});
8182
});
8283

84+
it('show error toast when called onSubmit with no name', async () => {
85+
const onSubmit = jest.fn();
86+
toast.error = jest.fn();
87+
const { getByText } = setup({ onSubmit });
88+
const createSeriesButton = await waitForElement(() =>
89+
getByText('시리즈 추가'),
90+
);
91+
fireEvent.click(createSeriesButton);
92+
expect(onSubmit).toHaveBeenCalledWith({
93+
name: '',
94+
});
95+
expect(toast.error).toHaveBeenCalledWith('시리즈 제목이 비어있습니다.');
96+
});
97+
8398
it('shows username recevied via props', async () => {
8499
const { getByPlaceholderText, getByText } = setup({
85100
username: 'helloworld',

0 commit comments

Comments
 (0)