-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 숨김 및 신고 테스트 추가 및 기존 테스트 리팩토링 (#73)
* feat: 테스트 서버 handler 등록 * feat: React Query 적용 * style: 통합 테스트 파일 명 수정 * feat: 무한 스크롤 단위 테스트 * feat: 신고 완료 시, 응답 포맷 수정 * feat: 북마크 단위 테스트 수정 * test: 북마크 단위 테스트 리팩토링 * feat: mutation 결과 반환 * feat: 북마크 단위 테스트 리팩토링 * feat: 좋아요 기능 단위 테스트 리팩토링 * test: 숨기기 기능 단위 테스트 * style: 주석 추가 * test: 신고 기능 단위 테스트 * feat: 신고하기 통합 테스트 * style: 파일명 컨벤션 유지 Closes #48, #71
- Loading branch information
Showing
18 changed files
with
270 additions
and
113 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
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 was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/features/feed-bookmark/test/useBookmarks.unit.test.tsx
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,44 @@ | ||
import { renderHook, act, waitFor } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { createQueryClientWrapper } from '@/shared/tests'; | ||
|
||
import { useBookmarks } from '../api'; | ||
|
||
describe('북마크 기능 테스트', () => { | ||
it('북마크 상태가 아닐 때, 북마크 버튼을 클릭하면 북마크 된다', async () => { | ||
// given | ||
const { result } = renderHook(() => useBookmarks(1, false), { | ||
wrapper: createQueryClientWrapper(), | ||
}); | ||
|
||
// when | ||
act(() => result.current.handleBookmarkFeed()); | ||
|
||
// then | ||
await waitFor(() => { | ||
const { | ||
data: { isBookmarked }, | ||
} = result.current.data; | ||
expect(isBookmarked).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('북마크 상태일 때, 북마크 버튼을 클릭하면 북마크가 취소된다', async () => { | ||
// given | ||
const { result } = renderHook(() => useBookmarks(1, true), { | ||
wrapper: createQueryClientWrapper(), | ||
}); | ||
|
||
// when | ||
act(() => result.current.handleBookmarkFeed()); | ||
|
||
// then | ||
await waitFor(() => { | ||
const { | ||
data: { isBookmarked }, | ||
} = result.current.data; | ||
expect(isBookmarked).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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
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,46 @@ | ||
import { renderHook, act, waitFor } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { createQueryClientWrapper } from '@/shared/tests'; | ||
|
||
import { useHideCancel, useHides } from '../api'; | ||
|
||
describe('숨기기 기능 테스트', () => { | ||
it('숨기기 상태가 아닐 때, 숨기기 버튼을 클릭하면 게시물이 숨겨진다.', async () => { | ||
// given | ||
const { result } = renderHook(() => useHides(1), { | ||
wrapper: createQueryClientWrapper(), | ||
}); | ||
|
||
// when | ||
act(() => result.current.hideFeed()); | ||
|
||
// then | ||
await waitFor(() => { | ||
const { | ||
data: { isHidden }, | ||
} = result.current.data; | ||
|
||
expect(isHidden).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('숨기기 상태일 때, 취소 버튼을 클릭하면 숨기기가 취소된다.', async () => { | ||
// given | ||
const { result } = renderHook(() => useHideCancel(1), { | ||
wrapper: createQueryClientWrapper(), | ||
}); | ||
|
||
// when | ||
act(() => result.current.hideCancelFeed()); | ||
|
||
// then | ||
await waitFor(() => { | ||
const { | ||
data: { isHidden }, | ||
} = result.current.data; | ||
|
||
expect(isHidden).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,46 @@ | ||
import { renderHook, act, waitFor } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { createQueryClientWrapper } from '@/shared/tests'; | ||
|
||
import { useLikes } from '../api'; | ||
|
||
describe('좋아요 기능 테스트', () => { | ||
it('좋아요 상태가 아닐 때, 좋아요 버튼을 클릭하면 좋아요 상태가 변경된다.', async () => { | ||
// given | ||
const { result } = renderHook(() => useLikes(1, false), { | ||
wrapper: createQueryClientWrapper(), | ||
}); | ||
|
||
// when | ||
act(() => result.current.handleLikeFeed()); | ||
|
||
// then | ||
await waitFor(() => { | ||
const { | ||
data: { isLiked }, | ||
} = result.current.data; | ||
|
||
expect(isLiked).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('좋아요 상태일 때, 좋아요 버튼을 클릭하면 좋아요가 취소된다.', async () => { | ||
// given | ||
const { result } = renderHook(() => useLikes(1, true), { | ||
wrapper: createQueryClientWrapper(), | ||
}); | ||
|
||
// when | ||
act(() => result.current.handleLikeFeed()); | ||
|
||
// then | ||
await waitFor(() => { | ||
const { | ||
data: { isLiked }, | ||
} = result.current.data; | ||
|
||
expect(isLiked).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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
44 changes: 44 additions & 0 deletions
44
src/features/feed-reports/test/FeedReports.integration.test.tsx
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,44 @@ | ||
import { expect, test, vi } from 'vitest'; | ||
|
||
import { fireEvent, render, screen } from '@/shared/tests'; | ||
import { Toast } from '@/shared/toast'; | ||
|
||
import { FeedReportsForm } from '../ui'; | ||
|
||
vi.mock('@/shared/ui/modal/ModalOverlay', () => ({ | ||
ModalOverlay: ({ children }: { children: JSX.Element }) => ( | ||
<section>{children}</section> | ||
), | ||
})); | ||
|
||
vi.mock('@/features/feed-reports/model', () => ({ | ||
useReportForm: () => ({ | ||
content: '', | ||
isBlind: false, | ||
isDisabledReportForm: false, | ||
createReportBody: () => ({ | ||
category: '상업적/홍보성', | ||
content: '', | ||
isBlind: false, | ||
}), | ||
}), | ||
})); | ||
|
||
test('신고하기 버튼을 클릭하면, 신고 접수 토스트 메시지가 표시된다', async () => { | ||
// given | ||
render( | ||
<> | ||
<FeedReportsForm feedId={1} onClose={() => {}} /> | ||
<Toast /> | ||
</>, | ||
); | ||
|
||
const reportBtn = screen.getByRole('button', { name: '신고하기' }); | ||
|
||
// when | ||
fireEvent.click(reportBtn); | ||
|
||
// then | ||
const reportAcceptMsg = await screen.findByText('신고가 접수되었어요'); | ||
expect(reportAcceptMsg).toBeInTheDocument(); | ||
}); |
Oops, something went wrong.