Skip to content

Commit

Permalink
test: 테스트 코드 수정 사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yungo1846 committed Aug 10, 2021
1 parent 7e7ed52 commit cd91c60
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 95 deletions.
2 changes: 1 addition & 1 deletion frontend/reply-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reply-module",
"version": "^0.3.0",
"version": "^0.4.0",
"description": "댓글 모듈",
"main": "index.js",
"author": "도비, 곤이",
Expand Down
33 changes: 22 additions & 11 deletions frontend/reply-module/src/__test__/fixture/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,97 @@ export const comments: Comment[] = [
user: socialLoginUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 2,
content: "두번째댓글",
user: socialLoginUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 3,
content: "세번째댓글",
user: socialLoginUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 4,
content: "네번째댓글",
user: socialLoginUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 5,
content: "다섯번째댓글",
user: socialLoginUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 6,
content: "여섯번째댓글",
user: guestUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 7,
content: "일곱번째댓글",
user: guestUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 8,
content: "여덟번째댓글",
user: guestUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 9,
content: "아홉번째댓글",
user: guestUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 10,
content: "열번째댓글",
user: guestUser,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
},
{
id: 11,
content: "열한번째댓글",
user: socialLoginUser2,
likingUsers: [],
createdDate: new Date().toDateString(),
modifiedDate: new Date().toDateString()
modifiedDate: new Date().toDateString(),
subComments: []
}
].sort(() => Math.random() - 0.5);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@testing-library/jest-dom/extend-expect";
import { fireEvent, render, waitFor } from "@testing-library/react";
import { getPasswordConfirmResult } from "../../api/getPasswordConfirmResult";
import CommentList from "../../components/organisms/CommentList";
import { useDeleteComment, useEditComment, useShowMoreComments } from "../../hooks";
import { useDeleteComment, useEditComment } from "../../hooks";
import { useLikeComment } from "../../hooks/useLikeComment";
import { Comment } from "../../types";
import { comments as _comments } from "../fixture/comments";
Expand All @@ -14,7 +14,6 @@ jest.mock("../../hooks/useDeleteComment");
jest.mock("../../hooks/useCreateComment");
jest.mock("../../hooks/useLikeComment");
jest.mock("../../api/getPasswordConfirmResult");
jest.mock("../../hooks/useShowMoreComments");

window.alert = function (str) {
console.log(str);
Expand Down Expand Up @@ -53,13 +52,6 @@ describe("관리자 유저일 때의 동작 테스트", () => {
error: false
};
});
(useShowMoreComments as jest.Mock).mockImplementation(() => {
return {
showMoreComments: () => {},
isLoading: false,
error: false
};
});
});
test("관리자 유저인 경우, 비회원 유저의 댓글을 삭제할 수 있다.", async () => {
const user = socialLoginUser;
Expand All @@ -71,6 +63,7 @@ describe("관리자 유저일 때의 동작 테스트", () => {
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={user}
project={project}
comments={guestComments}
Expand Down Expand Up @@ -102,6 +95,7 @@ describe("관리자 유저일 때의 동작 테스트", () => {
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={user}
project={project}
comments={socialLoginedComments}
Expand Down Expand Up @@ -134,6 +128,7 @@ describe("관리자 유저일 때의 동작 테스트", () => {
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={user}
project={project}
comments={guestComments}
Expand Down Expand Up @@ -164,6 +159,7 @@ describe("관리자 유저일 때의 동작 테스트", () => {
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={user}
project={project}
comments={socialLoginedCommentsWrittenByOther}
Expand Down Expand Up @@ -193,6 +189,7 @@ describe("관리자 유저일 때의 동작 테스트", () => {
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={user}
project={project}
comments={socialLoginedCommentsWrittenByMe}
Expand All @@ -210,32 +207,4 @@ describe("관리자 유저일 때의 동작 테스트", () => {

expect(commentList.queryByTestId("comment-option-edit-button")).toBeTruthy();
});
test("관리자 유저의 댓글은 오른쪽에 정렬된다.", async () => {
const user = socialLoginUser;
const project = myProject;
const comments: Comment[] = JSON.parse(JSON.stringify(_comments));

const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
user={user}
project={project}
comments={comments}
notice={""}
onShowMoreComment={() => {}}
sortOption={"oldest"}
onSelectSortOption={() => {}}
/>
);

await waitFor(() => {
const $$comments = commentList.container.querySelectorAll("section > div:nth-child(2) > div > div");

$$comments.forEach(($comment, index) => {
if (comments[index].user.id === project.userId) {
expect($comment).toHaveStyle("flex-direction: row-reverse");
}
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { getPasswordConfirmResult } from "../../api/getPasswordConfirmResult";
import CommentInput from "../../components/organisms/CommentInput/index";
import CommentList from "../../components/organisms/CommentList";
import { useCreateComment, useDeleteComment, useEditComment, useShowMoreComments } from "../../hooks";
import { useCreateComment, useDeleteComment, useEditComment } from "../../hooks";
import { useLikeComment } from "../../hooks/useLikeComment";
import { Comment } from "../../types";
import { comments as _comments } from "../fixture/comments";
Expand All @@ -15,7 +15,6 @@ jest.mock("../../hooks/useLikeComment");
jest.mock("../../utils/request");
jest.mock("../../utils/focusContentEditableTextToEnd");
jest.mock("../../api/getPasswordConfirmResult");
jest.mock("../../hooks/useShowMoreComments");

window.alert = function (str) {
console.log(str);
Expand Down Expand Up @@ -53,13 +52,6 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
(getPasswordConfirmResult as jest.Mock).mockImplementation(() => {
return true;
});
(useShowMoreComments as jest.Mock).mockImplementation(() => {
return {
showMoreComments: () => {},
isLoading: false,
error: false
};
});
(useLikeComment as jest.Mock).mockImplementation(() => {
return {
likeComment: () => {},
Expand All @@ -75,6 +67,7 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
comments={comments}
project={undefined}
notice={""}
Expand All @@ -91,35 +84,10 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
}
});
});

test("비로그인 유저인 경우, 모든 댓글들이 왼쪽에 정렬된다", async () => {
const comments: Comment[] = JSON.parse(JSON.stringify(_comments));
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
comments={comments}
project={undefined}
notice={""}
onShowMoreComment={() => {}}
sortOption={"oldest"}
onSelectSortOption={() => {}}
/>
);

await waitFor(() => {
const $$comments = commentList.container.querySelectorAll("section > div:nth-child(2) > div > div");

$$comments.forEach(($comment, index) => {
if (comments[index].user.type === "GuestUser") {
expect($comment).toHaveStyle("flex-direction: row");
}
});
});
});
});
describe("비로그인 유저 댓글 생성", () => {
test("비로그인 유저인 경우, 댓글 입력에 게스트 비밀번호/이름 입력란이 노출된다.", () => {
const commentInput = render(<CommentInput user={undefined} url={null} projectSecretKey={null} />);
const commentInput = render(<CommentInput user={undefined} />);
const $commentInputArea = commentInput.container.querySelector("form > div:nth-child(1)");
const [$guestNickName, $guestPassword] = Array.from(commentInput.container.querySelectorAll("form input"));

Expand All @@ -129,7 +97,7 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
});

test("비로그인 유저인 경우, 댓글 생성 시 댓글 내용/작성자 이름/비밀번호를 모두 입력해야 댓글을 작성할 수 있다.", async () => {
const commentInput = render(<CommentInput user={undefined} url={null} projectSecretKey={null} />);
const commentInput = render(<CommentInput user={undefined} />);
const $commentInputTextArea = commentInput.getByTestId("comment-input-text-box") as HTMLElement;
const $guestNickName = commentInput.getByPlaceholderText(/이름/i);
const $guestPassword = commentInput.getByPlaceholderText(/비밀번호/i);
Expand Down Expand Up @@ -158,6 +126,7 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={undefined}
comments={guestUserComments}
project={undefined}
Expand Down Expand Up @@ -191,6 +160,7 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
const commentList = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={undefined}
comments={guestUserComments}
project={undefined}
Expand Down Expand Up @@ -232,6 +202,7 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
const { rerender } = render(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={undefined}
project={undefined}
comments={comments}
Expand All @@ -249,6 +220,7 @@ describe("비로그인 유저 댓글 CRUD 테스트 코드를 작성한다.", ()
rerender(
<CommentList
totalCommentsCount={_comments.length}
isLoading={false}
user={undefined}
project={undefined}
comments={comments}
Expand Down
Loading

0 comments on commit cd91c60

Please sign in to comment.