Skip to content

Commit

Permalink
Merge pull request #103 from GDSC-PKNU-21-22/fix/#102
Browse files Browse the repository at this point in the history
Fix/#102: 공지사항 선택 시 특정 학과는 공지 안보이는 에러 수정
  • Loading branch information
pp449 authored Jul 25, 2023
2 parents 3426216 + 48bf871 commit 7f63170
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/components/List/DepartmentList/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DepartmentList from '@components/List/DepartmentList';
import useMajor from '@hooks/useMajor';
import { render, act, screen } from '@testing-library/react';
import { render, act, screen, findByText } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter, Route, Routes } from 'react-router-dom';

Expand Down Expand Up @@ -73,4 +73,26 @@ describe('학과선택 테스트', () => {
expect(mockSetMajor).toBeCalledWith('컴퓨터인공지능학부');
expect(routerToMock).toBeCalledWith('/');
});

it('학과 이름에 스페이스가 있는 경우 (학부, 전공이 모두 있는경우) 테스트', async () => {
const collegName = '정보융합대학';
render(
<MemoryRouter initialEntries={[`/major-decision/${collegName}`]}>
<Routes>
<Route path="/major-decision/:college" element={<DepartmentList />} />
</Routes>
</MemoryRouter>,
);

const confirmButton = await screen.findByRole('button', {
name: '선택완료',
});
const college = await screen.findByText('조형학부 건축학전공');
await act(async () => {
await userEvent.click(college);
});
await userEvent.click(confirmButton);

expect(mockSetMajor).toBeCalledWith('건축학전공');
});
});
5 changes: 3 additions & 2 deletions src/components/List/DepartmentList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const DepartmentList = () => {

const buttonClick: React.MouseEventHandler<HTMLElement> = (e) => {
if (e.target !== e.currentTarget) return;
localStorage.setItem('major', selected);
setMajor(selected);
const afterSpace = selected.substring(selected.indexOf(' ') + 1);
localStorage.setItem('major', afterSpace);
setMajor(afterSpace);
alert('전공 선택 완료 !');
routerTo('/');
};
Expand Down
1 change: 1 addition & 0 deletions src/mocks/handlers/majorHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const majorHandlers: RequestHandler[] = [
'데이터정보과학부',
'미디어커뮤니케이션학부',
'컴퓨터인공지능학부',
'조형학부 건축학전공',
];
return res(ctx.status(200), ctx.json(INFORMATIONCONVERGENCE));
}
Expand Down

0 comments on commit 7f63170

Please sign in to comment.