-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from Readme-Monster/Feature-38
[RM-38]: HomepageUI
- Loading branch information
Showing
18 changed files
with
1,219 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { MemoryRouter, Route, Routes } from 'react-router-dom'; | ||
import React, { ReactNode } from 'react'; | ||
import { ReactElement } from 'react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { Routes as AppRoutes } from '../../src/pages/Routes'; | ||
import App from "../../src/pages/App"; | ||
|
||
describe('Routes 테스트', () => { | ||
test('기본 경로("/")에서 HomePage 컴포넌트가 렌더링되어야 함', () => { | ||
render( | ||
<MemoryRouter initialEntries={['/']}> | ||
<AppRoutes /> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByTestId('home')).toBeInTheDocument(); | ||
}); | ||
|
||
test('잘못된 경로에 접근했을 때 루트 경로("/")로 리다이렉트되어야 함', () => { | ||
render( | ||
<MemoryRouter initialEntries={['/some/wrong/path']}> | ||
<AppRoutes /> | ||
</MemoryRouter> | ||
); | ||
expect(screen.getByTestId('home')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('App',()=>{ | ||
test('App 컴포넌트가 성공적으로 렌더링되어야 함', async () => { | ||
renderWithRouter(<App />, { route: '/' }); | ||
const linkElement = screen.getByTestId('home'); | ||
expect(await linkElement).toBeInTheDocument(); | ||
}); | ||
|
||
function renderWithRouter(Component: ReactElement, options: { route: string }) { | ||
return render(<MemoryRouter initialEntries={[options.route]}>{Component}</MemoryRouter>); | ||
} | ||
}) |
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,59 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import HomePage, { Button } from "../../../src/pages/HomePage"; | ||
|
||
describe('HomePage 테스트', () => { | ||
test('HomePage가 정상적으로 렌더링되어야 함', () => { | ||
render( | ||
<MemoryRouter initialEntries={['/']}> | ||
<HomePage /> | ||
</MemoryRouter> | ||
); | ||
|
||
expect(screen.getByTestId('logo')).toBeInTheDocument(); | ||
expect(screen.getByTestId('title')).toBeInTheDocument(); | ||
expect(screen.getByTestId('description')).toBeInTheDocument(); | ||
}); | ||
|
||
test("올바른 props로 두 개의 버튼이 렌더링되어야 함", () => { | ||
render( | ||
<MemoryRouter initialEntries={['/']}> | ||
<HomePage /> | ||
</MemoryRouter>); | ||
|
||
const firstButton = screen.getByTestId("firstButton"); | ||
expect(firstButton).toBeInTheDocument(); | ||
|
||
const secondButton = screen.getByTestId("secondButton"); | ||
expect(secondButton).toBeInTheDocument(); | ||
}); | ||
|
||
test("버튼 클릭시 올바른 URL로 이동해야 함", () => { | ||
const pushMock = jest.fn(); | ||
|
||
const useRouterMock = jest.spyOn(require("../../../src/pages/routing"), "useRouter").mockReturnValue({ | ||
push: pushMock | ||
}); | ||
render( | ||
<MemoryRouter initialEntries={['/']}> | ||
<HomePage /> | ||
</MemoryRouter> | ||
); | ||
|
||
// 첫 번째 버튼 클릭 | ||
const firstButton = screen.getByTestId("firstButton"); | ||
fireEvent.click(firstButton); | ||
expect(pushMock).toHaveBeenCalledWith("/login"); | ||
|
||
// 두 번째 버튼 클릭 | ||
const secondButton = screen.getByTestId("secondButton"); | ||
fireEvent.click(secondButton); | ||
expect(pushMock).toHaveBeenCalledWith("/signup"); | ||
|
||
useRouterMock.mockRestore(); | ||
}); | ||
}); |
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,3 +1,3 @@ | ||
module.exports = { | ||
presets: ["@babel/preset-env", "@babel/preset-react"], | ||
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"], | ||
}; |
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,3 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,62 @@ | ||
import React from "react"; | ||
import { RoutePath,useRouter } from "./routing"; | ||
|
||
interface ButtonProps { | ||
url: RoutePath; | ||
color: string; | ||
backgroundColor: string; | ||
description: string; | ||
hover: string; | ||
testId: string; | ||
} | ||
|
||
function HomePage() { | ||
|
||
return ( | ||
<div> | ||
<div className="flex-Center flex-col" data-testid="home"> | ||
<img alt="로고" src="/img/logo.png" width="140" height="140" data-testid="logo"/> | ||
<span className="text-textPrimary text-3xl md:text-6xl sm:text-5xl font-bold line-lg" data-testid="title">README-MONSTER</span> | ||
<p className="max-w-md mx-auto mt-3 text-textSecondary text-gray-500 display-contents sm:text-lg md:mt-5 md:text-xl md:max-w-3xl" data-testid="description"> | ||
<span>당신의 프로젝트 README를</span><span>자동으로 만들 수 있는 가장 빠르고 쉬운 방법</span> | ||
</p> | ||
</div> | ||
<div className="flex justify-center mt-6" data-testid="button"> | ||
<Button url="/login" color="text-white" backgroundColor="bg-textBlue" hover="hover:bg-textBlueHover" description="시작하기" testId="firstButton"/> | ||
<Button url="/signup" color="text-textPrimary" backgroundColor="bg-gray-200" hover="hover:bg-textgreyHover" description="더 알아보기" testId="secondButton"/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default HomePage; | ||
|
||
export function Button({ url, color, backgroundColor, description, hover, testId }: ButtonProps){ | ||
const router = useRouter(); | ||
const handleClick = () => { | ||
router.push(url); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col items-center"> | ||
<span className="inline-flex rounded-md shadow"> | ||
<a | ||
className={` | ||
inline-flex items-center px-4 py-2 | ||
font-medium text-xl | ||
${backgroundColor} | ||
${hover} | ||
border border-transparent rounded-lg | ||
${color} | ||
w-[250px] h-[54px] | ||
justify-center` | ||
} | ||
onClick={handleClick} | ||
data-testid={testId} | ||
> | ||
{description} | ||
</a> | ||
</span> | ||
</div> | ||
); | ||
} |
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,13 @@ | ||
import React from "react"; | ||
import { Route, Routes as ReactRouterRoutes, Navigate } from "react-router-dom"; | ||
import HomePage from "./HomePage"; | ||
|
||
|
||
export const Routes = () => { | ||
return ( | ||
<ReactRouterRoutes> | ||
<Route path="/" element={<HomePage />} /> | ||
<Route path="*" element={<Navigate replace to="/" />} /> | ||
</ReactRouterRoutes> | ||
); | ||
}; |
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,23 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
import { useMemo } from "react"; | ||
import { stringify } from "qs"; | ||
|
||
export function useRouter() { | ||
const navigate = useNavigate(); | ||
return useMemo(() => { | ||
return { | ||
back(steps = 1) { | ||
navigate(-steps); | ||
}, | ||
push(path: RoutePath, search?: string) { | ||
navigate({ pathname: path, search: search ? stringify(search, { indices: false }) : undefined }); | ||
}, | ||
}; | ||
}, [navigate]); | ||
} | ||
|
||
export type RoutePath = | ||
| "/" | ||
| "/login" | ||
| "/signup"; | ||
|
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -23,5 +23,5 @@ | |
}, | ||
"include": [ | ||
"src" | ||
] | ||
, "jest.config.js", "App.test.tsx" ] | ||
} |
Oops, something went wrong.