-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
257 additions
and
24 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 |
---|---|---|
@@ -1,7 +1,3 @@ | ||
{ | ||
"extends": [ | ||
"next/core-web-vitals", | ||
"prettier", | ||
"plugin:storybook/recommended" | ||
] | ||
"extends": ["next/core-web-vitals", "prettier", "plugin:storybook/recommended"] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,48 @@ | ||
import Home from '@/app/page'; | ||
import render from '@/__tests__/setups/render'; | ||
import { screen } from '@testing-library/react'; | ||
import { redirect } from 'next/navigation'; | ||
import { IsLoggedIn, checkIsLoggedIn } from '@/services/auth/getMember'; | ||
|
||
vi.mock('next/headers', async () => { | ||
return { | ||
cookies: () => { | ||
return { | ||
get: (name: string) => { | ||
return { | ||
value: 'cookie', | ||
}; | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
vi.mock('@/services/auth/getMember'); | ||
|
||
describe('홈 페이지 테스트', () => { | ||
it('로그인 안했을 때 홈 페이지를 렌더링 합니다.', async () => { | ||
vi.mocked(checkIsLoggedIn).mockReturnValue(Promise.resolve({ isLoggedIn: true })); | ||
render(await Home()); | ||
const button = screen.getByText('로그인하기'); | ||
|
||
expect(button).toBeInTheDocument(); | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it('로그인 했을 때는 유저의 홈으로 리다이렉트 합니다.', async () => { | ||
const member = { memberId: 2 }; | ||
vi.mocked(checkIsLoggedIn).mockReturnValue( | ||
Promise.resolve({ isLoggedIn: true, member }) as Promise<IsLoggedIn>, | ||
); | ||
|
||
vi.mock('next/navigation', async () => { | ||
return { | ||
redirect: vi.fn(), | ||
}; | ||
}); | ||
|
||
render(await Home()); | ||
|
||
expect(redirect).toHaveBeenCalledWith(`member/2`); | ||
}); | ||
}); |
Oops, something went wrong.