-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: (#205) 게시글 작성 페이지에서 카테고리 리스트를 불러와 옵션으로 변환하는 기능 구현
- Loading branch information
1 parent
920d187
commit 4b7f800
Showing
4 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Category } from '@type/category'; | ||
|
||
import { Option } from '@components/common/MultiSelect/types'; | ||
|
||
import { changeCategoryToOption } from '@utils/post/changeCategoryToOption'; | ||
|
||
describe('changeCategoryToOption 함수를 이용해서 카테고리 리스트를 셀렉트 컴포넌트에 사용되는 옵션 리스트로 변환한다.', () => { | ||
test('카테고리 리스트로 옵션 리스트를 만든다.', () => { | ||
const categoryList: Category[] = [ | ||
{ id: 1, isFavorite: false, name: '갤럭시' }, | ||
{ id: 2, isFavorite: true, name: '애플' }, | ||
]; | ||
|
||
const result: Option[] = changeCategoryToOption(categoryList); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
id: 1, | ||
name: '갤럭시', | ||
}, | ||
{ | ||
id: 2, | ||
name: '애플', | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { ReactNode } from 'react'; | ||
|
||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
|
||
import { useCategoryList } from '@hooks/query/category/useCategoryList'; | ||
|
||
import { transformCategoryListResponse } from '@api/categoryList'; | ||
|
||
import { MOCK_CATEGORY_LIST, MOCK_GUEST_CATEGORY_LIST } from '@mocks/mockData/categoryList'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const wrapper = ({ children }: { children: ReactNode }) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe('useCategoryList 훅이 카테고리 목록을 불러오는지 확인한다.', () => { | ||
test('비회원 카테고리 목록을 불러온다.', async () => { | ||
const { result } = renderHook(() => useCategoryList(false), { | ||
wrapper, | ||
}); | ||
|
||
await waitFor(() => | ||
expect(result.current.data).toEqual(transformCategoryListResponse(MOCK_GUEST_CATEGORY_LIST)) | ||
); | ||
}); | ||
|
||
test('회원 카테고리 목록을 불러온다.', async () => { | ||
const { result } = renderHook(() => useCategoryList(true), { | ||
wrapper, | ||
}); | ||
|
||
await waitFor(() => | ||
expect(result.current.data).toEqual(transformCategoryListResponse(MOCK_CATEGORY_LIST)) | ||
); | ||
}); | ||
|
||
test('회원 카테고리 목록을 불러온다.', async () => { | ||
const { result } = renderHook(() => useCategoryList(true), { | ||
wrapper, | ||
}); | ||
|
||
await waitFor(() => | ||
expect(result.current.data).toEqual(transformCategoryListResponse(MOCK_CATEGORY_LIST)) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Category } from '@type/category'; | ||
|
||
import { Option } from '@components/common/MultiSelect/types'; | ||
|
||
export const changeCategoryToOption = (categoryList: Category[]): Option[] => { | ||
return categoryList.map(category => ({ id: category.id, name: category.name })); | ||
}; |