-
Notifications
You must be signed in to change notification settings - Fork 8
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
[FE] 24시간 이하로 남으면 디데이 말고 시간 보여주기(#598) #609
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4e4c6c7
fix: 디데이가 1일 남은경우에도 24시간 미만 남은경우 남은 dday로 반환하도록 변경
pp449 f28f478
refactor: areDatesEqual 함수를 dateFormatter 유틸 함수로 이동
pp449 64005ad
fix: 중복된 함수 제거
pp449 3ed0201
test: 데이터 포메팅 유틸 함수 테스트코드 추가
pp449 ca15ee8
test: 테스트 시 이미지 모듈은 mock string 값이 반환되도록 모킹
pp449 b894edd
test: 룸 카드의 남은 기간 정보 UI 렌더링 테스트 추가
pp449 c33d016
fix: 진행중인 방의 D-Day 가 잘못 표기되는 문제 해결
pp449 834a645
test: 테스트 명세 오타 수정
pp449 20d2f4c
test: 방 상세정보의 모집/리뷰 마감까지 남은 시간 렌더링 테스트 추가
pp449 a1b0a0a
test: jest 환경에서 시간대를 한국 시간대를 사용하도록 변경
pp449 0c15ac0
feat: SEO 최적화를 위해 html에 메타태그 추가
pp449 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
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,120 @@ | ||
import { | ||
displayLeftTime, | ||
formatDateTimeString, | ||
formatDday, | ||
formatLeftTime, | ||
} from "@/utils/dateFormatter"; | ||
|
||
describe("날짜 포메팅 유틸 함수 테스트", () => { | ||
beforeAll(() => { | ||
const mockDate = new Date("2024-10-02T10:30:00+09:00"); | ||
const OriginalDate = Date; | ||
|
||
jest.spyOn(global, "Date").mockImplementation((value) => { | ||
return value ? new OriginalDate(value) : new OriginalDate(mockDate); | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe("formatDateTimeString 함수 테스트", () => { | ||
it("string 타입의 date를 받아 '연-월-일 시간:분' 포멧팅으로 반환 테스트", () => { | ||
const mockDeadlineDate = "2024-10-14T12:56:31"; | ||
const deadline = formatDateTimeString(mockDeadlineDate); | ||
|
||
expect(deadline).toBe("24-10-14 12:56"); | ||
}); | ||
}); | ||
|
||
describe("formatDday 함수 테스트", () => { | ||
it("날짜가 5일이 남은 경우 'D-5'가 반환", () => { | ||
const dateString = "2024-10-07T12:00:00+09:00"; | ||
const dDay = formatDday(dateString); | ||
|
||
expect(dDay).toBe("D-5"); | ||
}); | ||
|
||
it("날짜가 1일이 남았고, 시간상으로 24시간 이상 남은 경우 'D-1'이 반환", () => { | ||
const dateString = "2024-10-03T10:35:00+09:00"; | ||
const dDay = formatDday(dateString); | ||
|
||
expect(dDay).toBe("D-1"); | ||
}); | ||
|
||
it("날짜가 1일 남았고, 시간상으로 24시간 이하로 남은 경우 'D-0'이 반환", () => { | ||
const dateString = "2024-10-03T10:29:00+09:00"; | ||
const dDay = formatDday(dateString); | ||
|
||
expect(dDay).toBe("D-Day"); | ||
}); | ||
|
||
it("날짜가 0일 남았고, 시간이 남은 경우 'D-Day'가 반환", () => { | ||
const dateString = "2024-10-02T23:29:00+09:00"; | ||
const dDay = formatDday(dateString); | ||
|
||
expect(dDay).toBe("D-Day"); | ||
}); | ||
|
||
it("날짜가 0일 남았지만, 시간이 지난 경우 '종료됨'을 반환", () => { | ||
const dateString = "2024-10-02T10:29:00+09:00"; | ||
const dDay = formatDday(dateString); | ||
|
||
expect(dDay).toBe("종료됨"); | ||
}); | ||
|
||
it("날짜가 지난 경우 '종료됨'을 반환", () => { | ||
const dateString = "2024-10-01T10:35:00+09:00"; | ||
const dDay = formatDday(dateString); | ||
|
||
expect(dDay).toBe("종료됨"); | ||
}); | ||
}); | ||
|
||
describe("formatLeftTime 함수 테스트", () => { | ||
it("종료 시간이 1시간 이상이 남은 경우 'N시간 M분 전' 반환 테스트", () => { | ||
const dateString = "2024-10-02T15:00:30+09:00"; | ||
const leftTime = formatLeftTime(dateString); | ||
|
||
expect(leftTime).toBe("4시간 30분 전"); | ||
}); | ||
|
||
it("종료 시간이 1시간 미만으로 남은 경우 'M분 전' 반환 테스트", () => { | ||
const dateString = "2024-10-02T11:15:30+09:00"; | ||
const leftTime = formatLeftTime(dateString); | ||
|
||
expect(leftTime).toBe("45분 전"); | ||
}); | ||
|
||
it("종료 시간이 되었으면 '곧 종료' 반환 테스트", () => { | ||
const dateString = "2024-10-02T10:30:30+09:00"; | ||
const leftTime = formatLeftTime(dateString); | ||
|
||
expect(leftTime).toBe("곧 종료"); | ||
}); | ||
Comment on lines
+90
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 시간 차이가 1분 미만일 때만 곧 종료인 거죠??? 매칭 결과가 정각에 나오는 게 아니라 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넹 시간, 분이 일치한 경우 |
||
}); | ||
|
||
describe("displayLeftTime 함수 테스트", () => { | ||
it("2일 이상 남은 경우 남은 디데이 반환 테스트", () => { | ||
const dateString = "2024-10-05T10:30:30+09:00"; | ||
const leftTime = displayLeftTime(dateString); | ||
|
||
expect(leftTime).toBe("D-3"); | ||
}); | ||
|
||
it("날짜가 1일이 남았고, 시간상으로 24시간 이상 남은 경우 'D-1'이 반환", () => { | ||
const dateString = "2024-10-03T10:31:30+09:00"; | ||
const leftTime = displayLeftTime(dateString); | ||
|
||
expect(leftTime).toBe("D-1"); | ||
}); | ||
|
||
it("날짜가 1일이 남았고, 시간상으로 24시간 미만 남은 경우 남은 시간이 반환", () => { | ||
const dateString = "2024-10-03T10:29:30+09:00"; | ||
const leftTime = displayLeftTime(dateString); | ||
|
||
expect(leftTime).toBe("23시간 59분 전"); | ||
}); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헷갈렸던 부분들을 테스트 케이스를 보면서 이해할 수 있었어요!
완전 상세한 케이스 대박 👍 👍