generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more to the jest test for forgetPassword
- Loading branch information
Showing
2 changed files
with
15 additions
and
9 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import i18en from 'i18next'; | |
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import userEvent from '@testing-library/user-event'; | ||
import Cookies from 'js-cookie'; | ||
|
||
i18en.use(initReactI18next).init({ | ||
resources: {}, | ||
|
@@ -20,33 +21,32 @@ global.i18en = i18en; | |
const mockAxios = new MockAdapter(axios); | ||
describe('ForgetPassword Component', () => { | ||
test('renders Ask Email component', async () => { | ||
await act(async () => { | ||
act( () => { | ||
render(<MemoryRouter><ForgetPassword /></MemoryRouter>); | ||
}); | ||
await waitFor(() => expect(screen.getByText(i18en.t("forgotPassword.enter_email"))).toBeInTheDocument()); | ||
expect(screen.getByText(/addUser.email_placeholder/)).toBeInTheDocument(); | ||
expect(screen.getByText(/addUser.username_placeholder/)).toBeInTheDocument(); | ||
}); | ||
test('renders AskForCode component', async () => { | ||
|
||
var code = 111111 | ||
var token = "mockedToken" | ||
await act(async () => { | ||
act( () => { | ||
render(<MemoryRouter><ForgetPassword /></MemoryRouter>); | ||
}); | ||
await waitFor(() => expect(screen.getByText(i18en.t("forgotPassword.enter_email"))).toBeInTheDocument()); | ||
const emailInput = screen.getByPlaceholderText(/addUser.email_placeholder/i); | ||
const usernameInput = screen.getByPlaceholderText(/addUser.username_placeholder/i); | ||
|
||
//introducimos email y username | ||
expect(screen.getByText(/addUser.email_placeholder/)).toBeInTheDocument(); | ||
userEvent.type(emailInput, '[email protected]'); | ||
userEvent.type(usernameInput, 'testuser'); | ||
|
||
// Hacer clic en el botón de enviar | ||
const submitButton = screen.getByText(/forgotPassword.enter_email_button/i); // Ajusta el texto según el texto real del botón | ||
userEvent.click(submitButton); | ||
mockAxios.onPost('http://localhost:8000/forgetPassword').reply(200, "Email sent"); | ||
act(async ()=>{ | ||
userEvent.click(submitButton); | ||
mockAxios.onPost('http://localhost:8000/forgetPassword').reply(200, "Email sent"); | ||
await waitFor(async () => expect(screen.getByText(i18en.t("forgotPassword.enter_code")).toBeInTheDocument())); | ||
const inputs = screen.getAllByPlaceholderText('X'); | ||
// Introducir el mismo carácter en todos los inputs | ||
|
@@ -60,8 +60,14 @@ describe('ForgetPassword Component', () => { | |
fireEvent.click(screen.getByText(/"forgotPassword.send_code"/)); | ||
mockAxios.onGet('http://localhost:8000/tokenFromCode/' + code).reply(200, | ||
{token: token}); | ||
var username = "testUsername" | ||
|
||
//llegamos al replace | ||
await waitFor(async () => expect(screen.getByText(i18en.t("forgotPassword.enter_password")).toBeInTheDocument())); | ||
|
||
mockAxios.onPost('http://localhost:8000/changePassword').reply(200, { token: token, username: username}); | ||
//me redirigen a game Menu | ||
await waitFor(async () => expect(screen.getByText(i18en.t('gameMenu.title')).toBeInTheDocument())); | ||
//la cookie queda bien seteada | ||
expect(Cookies.get('user')).toHaveProperty('token', token); | ||
}); | ||
}); | ||
|
||
|
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