-
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.
(#100)
- Loading branch information
Showing
2 changed files
with
2 additions
and
66 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,77 +1,26 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { renderWithWrapper } from 'test/helpers/wrapper'; | ||
import LoginPage from '~/routes/auth.login'; | ||
|
||
describe('Login page', () => { | ||
it('should login successfully', async () => { | ||
const { user } = renderWithWrapper(<LoginPage />); | ||
|
||
// メールアドレスを入力 | ||
const emailForm = screen.getByTestId('email-input'); | ||
await user.type(emailForm, 'user@example.com'); | ||
expect(emailForm).toHaveValue('user@example.com'); | ||
|
||
// パスワードを入力 | ||
const passwordForm = screen.getByTestId('password-input'); | ||
await user.type(passwordForm, 'passw0rd'); | ||
expect(passwordForm).toHaveValue('passw0rd'); | ||
|
||
// ログインボタンをクリック | ||
const submitButton = screen.getByRole('button', { name: 'ログイン' }); | ||
await user.click(submitButton); | ||
|
||
// ログイン成功の通知が表示される | ||
const banner = await screen.findByText('ログインに成功しました'); | ||
expect(banner).toBeInTheDocument(); | ||
}); | ||
|
||
it('should fail to pass when email is invalid', async () => { | ||
const { user } = renderWithWrapper(<LoginPage />); | ||
|
||
// メールアドレスを入力 | ||
const emailForm = screen.getByTestId('email-input'); | ||
await user.type(emailForm, 'user@invalid'); | ||
|
||
// ログインボタンをクリック | ||
const submitButton = screen.getByRole('button', { name: 'ログイン' }); | ||
await user.click(submitButton); | ||
|
||
// エラーメッセージが表示される | ||
const message = await screen.findByText('有効でないメールアドレスです'); | ||
expect(message).toBeInTheDocument(); | ||
}); | ||
|
||
test('should fail to pass when password length is less than 8', async () => { | ||
const { user } = renderWithWrapper(<LoginPage />); | ||
|
||
it('should fail to pass when password length is less than 8', async () => { | ||
// パスワードを入力 | ||
const passwordForm = screen.getByTestId('password-input'); | ||
await user.type(passwordForm, 'pass'); | ||
|
||
// ログインボタンをクリック | ||
const submitButton = screen.getByRole('button', { name: 'ログイン' }); | ||
await user.click(submitButton); | ||
|
||
// エラーメッセージが表示される | ||
// prettier-ignore | ||
const message = await screen.findByText("パスワードは8文字以上で入力してください"); | ||
expect(message).toBeInTheDocument(); | ||
}); | ||
|
||
test('should fail to pass when password is not alphanumeric', async () => { | ||
const { user } = renderWithWrapper(<LoginPage />); | ||
|
||
it('should fail to pass when password is not alphanumeric', async () => { | ||
// パスワードを入力 | ||
const passwordForm = screen.getByTestId('password-input'); | ||
await user.type(passwordForm, 'password'); | ||
|
||
// ログインボタンをクリック | ||
const submitButton = screen.getByRole('button', { name: 'ログイン' }); | ||
await user.click(submitButton); | ||
|
||
// エラーメッセージが表示される | ||
// prettier-ignore | ||
const message = await screen.findByText("パスワードにはアルファベットと数字を含めてください"); | ||
expect(message).toBeInTheDocument(); | ||
}); | ||
}); |
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