Skip to content

Commit

Permalink
frontend testing
Browse files Browse the repository at this point in the history
  • Loading branch information
qria committed Dec 10, 2022
1 parent a46ce92 commit 6c17f2f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
25 changes: 25 additions & 0 deletions frontend/src/Pages/GiftRecommendPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fireEvent, render, screen } from "@testing-library/react"
import axios from "axios";
import { Provider } from "react-redux";
import { MemoryRouter, Route, Routes } from "react-router";
import { GiftState } from "../store/slices/gift";
Expand Down Expand Up @@ -103,7 +104,31 @@ describe("<GiftRecommendPage />", () => {
)
});
it("should render GiftRecommendPage", async () => {
axios.post = jest.fn().mockResolvedValue({ data: ["keyword1", "keyword2"] });
const { container } = render(giftRecommendPage);
expect(container).toBeTruthy()
fireEvent.click(screen.queryByText(/^10대 남성$/i)!)
fireEvent.click(screen.queryByText(/^20대 남성$/i)!)
fireEvent.click(screen.queryByText(/^30대 남성$/i)!)
fireEvent.click(screen.queryByText(/^10대 여성$/i)!)
fireEvent.click(screen.queryByText(/^20대 여성$/i)!)
fireEvent.click(screen.queryByText(/^30대 여성$/i)!)

fireEvent.click(screen.queryByText(/^전품목$/i)!)
fireEvent.click(screen.queryByText(/^패션의류$/i)!)
fireEvent.click(screen.queryByText(/^패션잡화$/i)!)
fireEvent.click(screen.queryByText(/^화장품미용$/i)!)
fireEvent.click(screen.queryByText(/^디지털가전$/i)!)
fireEvent.click(screen.queryByText(/^가구인테리어$/i)!)
fireEvent.click(screen.queryByText(/^식품$/i)!)
fireEvent.click(screen.queryByText(/^스포츠레저$/i)!)
fireEvent.click(screen.queryByText(/^생활건강$/i)!)
fireEvent.click(screen.queryByText(/^여가생활편의$/i)!)

fireEvent.click(screen.queryByText(/^~3만원$/i)!)
fireEvent.click(screen.queryByText(/^3만원~5만원$/i)!)
fireEvent.click(screen.queryByText(/^5만원~10만원$/i)!)
fireEvent.click(screen.queryByText(/^10만원~$/i)!)
fireEvent.click(screen.queryByText(/^전체보기$/i)!)
})
})
4 changes: 0 additions & 4 deletions frontend/src/Pages/GiftRecommendPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const GiftRecommendPage = () => {
const [keywordCategory, setKeywordCategory] = useState('All')
const [keywordList, setKeywordList] = useState([])
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);


useEffect(() => {
Expand All @@ -33,18 +32,15 @@ const GiftRecommendPage = () => {
try {
setError(false);
setKeywordList([]);
setLoading(true);
const paylaod = { 'category_id': keywordCategory, 'age_gender': keywordAge }
const response = await axios.post(BACKEND_URL + "/gift/shop_keyword/", paylaod);
setKeywordList(response.data)
}
catch (e) {
setError(true)
}
setLoading(false);
}

if (loading) return <div>로딩중..</div>;
if (error) return <div>에러가 발생했습니다</div>;

return (
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/Pages/LoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ describe("<LoginPage />", () => {
it("should render without errors", () => {
renderWithProviders(<LoginPage />);
})
it("should push login", () => {
renderWithProviders(<LoginPage />);
const loginButton = screen.queryByText(/^로그인$/i)
loginButton && fireEvent.click(loginButton)
})
})

0 comments on commit 6c17f2f

Please sign in to comment.