-
Notifications
You must be signed in to change notification settings - Fork 3
[refactor] 동아리 소개 컴포넌트 리팩토링 및 유틸 함수 단위 테스트 추가 #1068
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
Merged
seongwon030
merged 4 commits into
develop-fe
from
refactor/#1067-club-intro-performance-and-award-utils-MOA-535
Jan 19, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,99 @@ | ||
| import { Award, SemesterTerm, SemesterTermType } from '@/types/club'; | ||
| import { formatSemesterLabel, getAwardKey } from './awardHelpers'; | ||
|
|
||
| describe('awardHelpers', () => { | ||
| const createAward = ( | ||
| year: number, | ||
| semester: SemesterTermType, | ||
| achievements: string[] = [], | ||
| ): Award => ({ | ||
| year, | ||
| semester, | ||
| achievements, | ||
| }); | ||
|
|
||
| const validAward2024First = createAward(2024, SemesterTerm.FIRST); | ||
| const validAward2024Second = createAward(2024, SemesterTerm.SECOND); | ||
| const validAward2023First = createAward(2023, SemesterTerm.FIRST); | ||
| const validAward2025Second = createAward(2025, SemesterTerm.SECOND); | ||
|
|
||
| describe('formatSemesterLabel', () => { | ||
| it('1학기를 올바른 형식으로 반환해야 한다', () => { | ||
| expect(formatSemesterLabel(validAward2024First)).toBe('2024 1학기'); | ||
| }); | ||
|
|
||
| it('2학기를 올바른 형식으로 반환해야 한다', () => { | ||
| expect(formatSemesterLabel(validAward2024Second)).toBe('2024 2학기'); | ||
| }); | ||
|
|
||
| it('year가 없으면 null을 반환해야 한다', () => { | ||
| const award: Partial<Award> = { | ||
| semester: SemesterTerm.FIRST, | ||
| achievements: [], | ||
| }; | ||
|
|
||
| expect(formatSemesterLabel(award as Award)).toBeNull(); | ||
| }); | ||
|
|
||
| it('semester가 없으면 null을 반환해야 한다', () => { | ||
| const award: Partial<Award> = { | ||
| year: 2024, | ||
| achievements: [], | ||
| }; | ||
|
|
||
| expect(formatSemesterLabel(award as Award)).toBeNull(); | ||
| }); | ||
|
|
||
| it('year와 semester가 모두 없으면 null을 반환해야 한다', () => { | ||
| const award: Partial<Award> = { | ||
| achievements: [], | ||
| }; | ||
|
|
||
| expect(formatSemesterLabel(award as Award)).toBeNull(); | ||
| }); | ||
|
|
||
| it('award가 null이면 null을 반환해야 한다', () => { | ||
| expect(formatSemesterLabel(null as unknown as Award)).toBeNull(); | ||
| }); | ||
|
|
||
| it('award가 undefined이면 null을 반환해야 한다', () => { | ||
| expect(formatSemesterLabel(undefined as unknown as Award)).toBeNull(); | ||
| }); | ||
|
|
||
| it('다양한 연도를 올바르게 처리해야 한다', () => { | ||
| expect(formatSemesterLabel(validAward2023First)).toBe('2023 1학기'); | ||
| expect(formatSemesterLabel(validAward2025Second)).toBe('2025 2학기'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getAwardKey', () => { | ||
| it('year, semester, index를 조합한 고유 키를 생성해야 한다', () => { | ||
| expect(getAwardKey(validAward2024First, 0)).toBe('2024-FIRST-0'); | ||
| }); | ||
|
|
||
| it('인덱스가 다르면 다른 키를 생성해야 한다', () => { | ||
| const key1 = getAwardKey(validAward2024First, 0); | ||
| const key2 = getAwardKey(validAward2024First, 1); | ||
|
|
||
| expect(key1).not.toBe(key2); | ||
| expect(key1).toBe('2024-FIRST-0'); | ||
| expect(key2).toBe('2024-FIRST-1'); | ||
| }); | ||
|
|
||
| it('학기가 다르면 다른 키를 생성해야 한다', () => { | ||
| expect(getAwardKey(validAward2024First, 0)).toBe('2024-FIRST-0'); | ||
| expect(getAwardKey(validAward2024Second, 0)).toBe('2024-SECOND-0'); | ||
| }); | ||
|
|
||
| it('연도가 다르면 다른 키를 생성해야 한다', () => { | ||
| const award2024 = createAward(2024, SemesterTerm.FIRST); | ||
|
|
||
| expect(getAwardKey(validAward2023First, 0)).toBe('2023-FIRST-0'); | ||
| expect(getAwardKey(award2024, 0)).toBe('2024-FIRST-0'); | ||
| }); | ||
|
|
||
| it('큰 인덱스 숫자를 올바르게 처리해야 한다', () => { | ||
| expect(getAwardKey(validAward2024First, 999)).toBe('2024-FIRST-999'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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,13 @@ | ||
| import { Award, SemesterTerm } from '@/types/club'; | ||
|
|
||
| export const formatSemesterLabel = (award: Award): string | null => { | ||
| if (award?.year && award?.semester) { | ||
| const semesterLabel = | ||
| award.semester === SemesterTerm.FIRST ? '1학기' : '2학기'; | ||
| return `${award.year} ${semesterLabel}`; | ||
| } | ||
| return null; | ||
seongwon030 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export const getAwardKey = (award: Award, index: number): string => | ||
| `${award.year}-${award.semester}-${index}`; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.