forked from Laboratoria/SAP007-burger-queen-api-client
-
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.
Teste dos componentes da primeira história concluídos e testando a pá…
…gina de Login
- Loading branch information
Showing
5 changed files
with
58 additions
and
10 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
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,49 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import user from '@testing-library/user-event'; | ||
import Login from '.'; | ||
import * as storage from '../../services/storage'; | ||
|
||
let email = ''; | ||
let password = ''; | ||
|
||
const API = jest.mock('../../services/user', () => ({ | ||
...jest.requireActual('../../services/user'), | ||
userLogin: jest.fn() | ||
.mockImplementation(email, password) | ||
.mockResolvedValue('') | ||
})); | ||
|
||
describe('Login and UseForm', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Deverá logar usuário corretamente, validanto todos os testes', async () => { | ||
render( | ||
<MemoryRouter> | ||
<Login /> | ||
</MemoryRouter> | ||
); | ||
email = '[email protected]'; | ||
password = '123456'; | ||
|
||
/* Event change on input */ | ||
const getEmail = screen.getByPlaceholderText('Digite o seu email'); | ||
const getPassword = screen.getByPlaceholderText('Digite a sua senha'); | ||
user.type(getEmail, email); | ||
user.type(getPassword, password); | ||
|
||
/* Saving value */ | ||
getEmail.value = email; | ||
getPassword.value = password; | ||
|
||
/* Event click on ENTER button*/ | ||
const login = screen.getByRole('login'); | ||
user.click(login); | ||
storage.setUserData('Tiemi', password, 'admin'); | ||
expect(API.userLogin).toHaveBeenCalled(); | ||
expect(API.userLogin).toHaveBeenCalledTimes(1); | ||
storage.deleteUserData(); | ||
}); | ||
}); |
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