-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #207 test: communutiy page my group test code add
- Loading branch information
Showing
5 changed files
with
161 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const getMyGroupList = (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json([ | ||
{ | ||
groupId: 1, | ||
name: "그룹 이름 1", | ||
description: "그룹 소개", | ||
member: 1, | ||
image: | ||
"https://selody-images2.s3.ap-northeast-2.amazonaws.com/group/group.png", | ||
}, | ||
]), | ||
); | ||
}; | ||
|
||
export const postGroup = (req, res, ctx) => { | ||
try { | ||
const { name, description, profileImg } = req.body; | ||
|
||
if (!name) { | ||
return res( | ||
ctx.status(400), | ||
ctx.json({ error: "형식에 맞지 않는 데이터" }), | ||
); | ||
} | ||
|
||
return res( | ||
ctx.status(201), | ||
ctx.json({ | ||
name, | ||
description, | ||
profileImg, | ||
}), | ||
); | ||
} catch (error) { | ||
return res(ctx.status(500), ctx.json({ error: "Internal Server Error" })); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,18 +1,119 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
|
||
import "@testing-library/jest-dom/extend-expect"; | ||
|
||
import { userEvent } from "@storybook/testing-library"; | ||
import { screen } from "@testing-library/react"; | ||
|
||
import { render } from "../../jest.setup.js"; | ||
import GroupCreateModal from "../../src/components/Common/GroupModal/GroupCreateModal/GroupCreateModal.jsx"; | ||
import Header from "../../src/components/Header/Header/Header.jsx"; | ||
import CommunityPage from "../../src/pages/CommunityPage/CommunityPage.jsx"; | ||
|
||
describe("Community", () => { | ||
it("test initial render", () => { | ||
render(<CommunityPage />); | ||
const GROUP_NAME = "그룹 이름 1"; | ||
|
||
expect(screen.getByText("내 그룹")).toBeInTheDocument(); | ||
expect(screen.getByText("내 그룹 피드")).toBeInTheDocument(); | ||
expect(screen.getByText("그룹 검색")).toBeInTheDocument(); | ||
describe("Community 페이지 렌더링", () => { | ||
beforeAll(() => { | ||
ReactDOM.createPortal = jest.fn((element) => { | ||
return element; | ||
}); | ||
window.scrollTo = jest.fn(); | ||
}); | ||
describe("내 그룹 렌더링", () => { | ||
describe("그룹이 없을 때", () => { | ||
describe("그룹 추가하기 버튼 미클릭시", () => { | ||
it("그룹 추가하기 버튼 렌더링", () => { | ||
render(<CommunityPage />); | ||
|
||
expect(screen.getByText("그룹 추가하기")).toBeInTheDocument(); | ||
expect(screen.getByTestId("group-add-button")).toBeInTheDocument(); | ||
}); | ||
}); | ||
describe("그룹 추가하기 버튼 클릭시", () => { | ||
describe("그룹 추가하기 클릭시 그룹 생성 모달 오픈", () => { | ||
it("모달 요소 렌더링", () => { | ||
render( | ||
<> | ||
<CommunityPage /> | ||
<Header /> | ||
</>, | ||
{ | ||
preloadedState: { | ||
auth: { user: { userId: 1 } }, | ||
ui: { openedModal: null }, | ||
}, | ||
}, | ||
); | ||
|
||
userEvent.click(screen.getByTestId("group-add-button")); | ||
|
||
const createButton = screen.getByRole("button", { | ||
name: "생성하기", | ||
}); | ||
const imgInput = screen.getByTestId("group-img-input"); | ||
const nameInput = screen.getByPlaceholderText("그룹 이름"); | ||
const descriptionInput = | ||
screen.getByPlaceholderText("그룹 상세 소개"); | ||
|
||
expect(nameInput).toBeInTheDocument(); | ||
expect(descriptionInput).toBeInTheDocument(); | ||
expect(createButton).toBeInTheDocument(); | ||
expect(imgInput).toBeInTheDocument(); | ||
}); | ||
|
||
it("그룹 생성하기 버튼 활성화", () => { | ||
render(<GroupCreateModal />); | ||
|
||
const nameInput = screen.getByPlaceholderText("그룹 이름"); | ||
const createButton = screen.getByRole("button", { | ||
name: "생성하기", | ||
}); | ||
|
||
expect(createButton).toBeDisabled(); | ||
|
||
userEvent.clear(nameInput); | ||
userEvent.type(nameInput, GROUP_NAME); | ||
|
||
expect(createButton).toBeEnabled(); | ||
}); | ||
it("그룹 생성", async () => { | ||
render( | ||
<> | ||
<CommunityPage /> | ||
<Header /> | ||
</>, | ||
{ | ||
preloadedState: { | ||
auth: { user: { userId: 1 } }, | ||
ui: { openedModal: null }, | ||
}, | ||
}, | ||
); | ||
|
||
userEvent.click(screen.getByTestId("group-add-button")); | ||
|
||
const nameInput = screen.getByPlaceholderText("그룹 이름"); | ||
const createButton = screen.getByRole("button", { | ||
name: "생성하기", | ||
}); | ||
|
||
userEvent.clear(nameInput); | ||
userEvent.type(nameInput, GROUP_NAME); | ||
|
||
await userEvent.click(createButton); | ||
|
||
expect( | ||
await screen.findByRole("heading", { | ||
name: GROUP_NAME, | ||
}), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
// describe("그룹이 있을 때", () => { | ||
|
||
// }) | ||
}); | ||
}); |
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