-
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
Changes from all commits
4e4c6c7
f28f478
64005ad
3ed0201
ca15ee8
b894edd
c33d016
834a645
20d2f4c
a1b0a0a
0c15ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
const { server } = require("@/mocks/server"); | ||
|
||
jest.mock("@/assets", () => ""); | ||
process.env.TZ = "Asia/Seoul"; | ||
Comment on lines
+3
to
+4
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. 이렇게 시간대를 맞출 수 있군요 👍 |
||
|
||
// 모든 테스트 전에 MSW 서버를 시작합니다. | ||
beforeAll(() => server.listen()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { ThemeProvider } from "styled-components"; | ||
import RoomInfoCard from "@/components/roomDetailPage/roomInfoCard/RoomInfoCard"; | ||
import { RoomInfo } from "@/@types/roomInfo"; | ||
import { theme } from "@/styles/theme"; | ||
|
||
const mockBaseRoomInfo: RoomInfo = { | ||
id: 1, | ||
manager: "darr", | ||
currentParticipants: 5, | ||
roomStatus: "OPEN", | ||
participationStatus: "PARTICIPATED", | ||
memberRole: "BOTH", | ||
title: "테스트 제목", | ||
content: "테스트 본문", | ||
repositoryLink: "테스트 링크", | ||
thumbnailLink: "테스트 썸네일", | ||
matchingSize: 5, | ||
keywords: ["테스트"], | ||
limitedParticipants: 10, | ||
recruitmentDeadline: "2024-10-05T10:30:00+09:00", | ||
reviewDeadline: "2024-10-08T10:30:00+09:00", | ||
}; | ||
|
||
describe("RoomInfoCard 컴포넌트 테스트", () => { | ||
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); | ||
}); | ||
}); | ||
|
||
it("'모집'중인 방에 2일 이상 남으면 '리뷰 마감까지 남은 일', '모집 마감까지 남은 일'이 보인다", async () => { | ||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockBaseRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
Comment on lines
+37
to
+41
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. 이 부분이 계속 반복되고 있어서 함수로 분리해도 좋을 것 같아요😊 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. 우선 이렇게 해뒀는데 만약 모달, 토스트도 같이 상호작용이 되어야하는 부분이 생긴다면 해당 내용까지 묶어서 함수로 만들어도 좋을거 같네요! |
||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent("D-3"); | ||
expect(reviewLeftDay).toHaveTextContent("D-6"); | ||
}); | ||
|
||
it("'모집'이 24시간 미만, '리뷰'가 24시간 이상 남은 경우 '모집 마감까지 남은 시간', '리뷰 마감까지 남은 일'이 보인다", async () => { | ||
const mockRoomInfo: RoomInfo = { | ||
...mockBaseRoomInfo, | ||
recruitmentDeadline: "2024-10-03T00:30:00+09:00", | ||
reviewDeadline: "2024-10-05T00:30:00+09:00", | ||
}; | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent("14시간 0분 전"); | ||
expect(reviewLeftDay).toHaveTextContent("D-2"); | ||
}); | ||
|
||
it("'모집'이 24시간 미만, '리뷰'가 24시간 미만인 경우 '모집 마감까지 남은 시간', '리뷰 마감까지 남은 시간'이 보인다", async () => { | ||
const mockRoomInfo: RoomInfo = { | ||
...mockBaseRoomInfo, | ||
recruitmentDeadline: "2024-10-02T12:30:00+09:00", | ||
reviewDeadline: "2024-10-03T00:30:00+09:00", | ||
}; | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent("2시간 0분 전"); | ||
expect(reviewLeftDay).toHaveTextContent("14시간 0분 전"); | ||
}); | ||
|
||
it("'모집'완료 후 '진행 중'으로 바뀌었을 때 '리뷰'가 24시간 이상인 경우 '리뷰 마감까지 남은 일'이 보인다", async () => { | ||
const mockRoomInfo: RoomInfo = { | ||
...mockBaseRoomInfo, | ||
recruitmentDeadline: "2024-10-01T12:30:00+09:00", | ||
reviewDeadline: "2024-10-04T00:30:00+09:00", | ||
}; | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent(""); | ||
expect(reviewLeftDay).toHaveTextContent("D-1"); | ||
}); | ||
|
||
it("'모집'완료 후 '진행 중'으로 바뀌었을 때 '리뷰'가 24시간 미만인 경우 '리뷰 마감까지 남은 시간'이 보인다", async () => { | ||
const mockRoomInfo: RoomInfo = { | ||
...mockBaseRoomInfo, | ||
recruitmentDeadline: "2024-10-01T12:30:00+09:00", | ||
reviewDeadline: "2024-10-03T00:30:00+09:00", | ||
}; | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent(""); | ||
expect(reviewLeftDay).toHaveTextContent("14시간 0분 전"); | ||
}); | ||
|
||
it("'종료됨' 상태인 방에서는 남은 기간이 보이지 않는다", async () => { | ||
const mockRoomInfo: RoomInfo = { | ||
...mockBaseRoomInfo, | ||
roomStatus: "CLOSE", | ||
recruitmentDeadline: "2024-10-01T12:30:00+09:00", | ||
reviewDeadline: "2024-10-03T00:30:00+09:00", | ||
}; | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent(""); | ||
expect(reviewLeftDay).toHaveTextContent(""); | ||
}); | ||
|
||
it("'실패' 상태인 방에서는 남은 기간이 보이지 않는다", async () => { | ||
const mockRoomInfo: RoomInfo = { | ||
...mockBaseRoomInfo, | ||
roomStatus: "FAIL", | ||
recruitmentDeadline: "2024-10-01T12:30:00+09:00", | ||
reviewDeadline: "2024-10-03T00:30:00+09:00", | ||
}; | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<RoomInfoCard roomInfo={mockRoomInfo} /> | ||
</ThemeProvider>, | ||
); | ||
|
||
const recruitLeftDay = screen.getByTestId("recruitLeftTime"); | ||
const reviewLeftDay = screen.getByTestId("reviewLeftTime"); | ||
|
||
expect(recruitLeftDay).toHaveTextContent(""); | ||
expect(reviewLeftDay).toHaveTextContent(""); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ const RoomInfoCard = ({ roomInfo }: { roomInfo: RoomInfo }) => { | |
<S.DateTimeText> | ||
{formatDateTimeString(roomInfo.recruitmentDeadline)} | ||
</S.DateTimeText> | ||
<S.StyledDday> | ||
<S.StyledDday data-testid="recruitLeftTime"> | ||
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.
|
||
{roomInfo.roomStatus === "OPEN" && | ||
formatDday(roomInfo.recruitmentDeadline) !== "종료됨" && | ||
displayLeftTime(roomInfo.recruitmentDeadline)} | ||
|
@@ -80,8 +80,9 @@ const RoomInfoCard = ({ roomInfo }: { roomInfo: RoomInfo }) => { | |
</S.RoomContentSmall> | ||
<div> | ||
<S.DateTimeText>{formatDateTimeString(roomInfo.reviewDeadline)}</S.DateTimeText> | ||
<S.StyledDday> | ||
{formatDday(roomInfo.reviewDeadline) !== "종료됨" && | ||
<S.StyledDday data-testid="reviewLeftTime"> | ||
{(roomInfo.roomStatus === "OPEN" || roomInfo.roomStatus === "PROGRESS") && | ||
formatDday(roomInfo.reviewDeadline) !== "종료됨" && | ||
displayLeftTime(roomInfo.reviewDeadline)} | ||
</S.StyledDday> | ||
</div> | ||
|
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.
이렇게 ci에서도 잘 돌아가게 해결했군요😊💯