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.
- Loading branch information
1 parent
ab4c5a1
commit a8aeed5
Showing
1 changed file
with
62 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 |
---|---|---|
|
@@ -19,6 +19,10 @@ i18en.use(initReactI18next).init({ | |
}); | ||
global.i18en = i18en; | ||
const mockAxios = new MockAdapter(axios); | ||
|
||
const code = 111111 | ||
const token = "mockedToken" | ||
|
||
describe('ForgetPassword Component', () => { | ||
test('renders Ask Email component', async () => { | ||
act( () => { | ||
|
@@ -28,42 +32,41 @@ describe('ForgetPassword Component', () => { | |
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" | ||
act( () => { | ||
render(<MemoryRouter><ForgetPassword /></MemoryRouter>); | ||
|
||
test('show email errors', async () => { | ||
await 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'); | ||
|
||
await act(async () => { await insertEmail('testexample.com', '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); | ||
await waitFor(() => { | ||
expect(screen.getByText('addUser.error_wrong_email_format')).toBeInTheDocument(); | ||
}) | ||
}) | ||
|
||
|
||
test('change password', async () => { | ||
act( () => { | ||
render(<MemoryRouter><ForgetPassword /></MemoryRouter>); | ||
}); | ||
mockAxios.onPost('http://localhost:8000/forgetPassword').reply(200, "Email sent"); | ||
await waitFor(() => expect(screen.getByText(i18en.t("forgotPassword.enter_email"))).toBeInTheDocument()); | ||
insertEmail('[email protected]', 'testuser') | ||
|
||
|
||
act(async ()=>{ | ||
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 | ||
userEvent.type(inputs[0], '1'); // Introducir el carácter '1', puedes cambiarlo al que desees | ||
userEvent.type(inputs[1], '1'); | ||
userEvent.type(inputs[2], '1'); | ||
userEvent.type(inputs[3], '1'); | ||
userEvent.type(inputs[4], '1'); | ||
userEvent.type(inputs[5], '1'); | ||
// Simula un clic en el botón de submit | ||
fireEvent.click(screen.getByText(/"forgotPassword.send_code"/)); | ||
mockAxios.onGet('http://localhost:8000/tokenFromCode/' + code).reply(200, | ||
{token: token}); | ||
insertCode(['1', '1', '1', '1' ,'1' ,'1' ,'1']) | ||
|
||
//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}); | ||
await insertPassword('123456789', '123456789') | ||
//me redirigen a game Menu | ||
await waitFor(async () => expect(screen.getByText(i18en.t('gameMenu.title')).toBeInTheDocument())); | ||
//la cookie queda bien seteada | ||
|
@@ -73,3 +76,38 @@ describe('ForgetPassword Component', () => { | |
|
||
|
||
}); | ||
|
||
async function insertEmail(email, username) { | ||
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); | ||
userEvent.type(usernameInput, username); | ||
const submitButton = screen.getByText(/forgotPassword.enter_email_button/i); // Ajusta el texto según el texto real del botón | ||
userEvent.click(submitButton); | ||
} | ||
|
||
async function insertCode(code){ | ||
const inputs = screen.getAllByPlaceholderText('X'); | ||
// Introducir el mismo carácter en todos los inputs | ||
userEvent.type(inputs[0], code[0]); | ||
userEvent.type(inputs[1], code[1]); | ||
userEvent.type(inputs[2], code[2]); | ||
userEvent.type(inputs[3], code[3]); | ||
userEvent.type(inputs[4], code[4]); | ||
userEvent.type(inputs[5], code[5]); | ||
// Simula un clic en el botón de submit | ||
fireEvent.click(screen.getByText(/"forgotPassword.send_code"/)); | ||
} | ||
|
||
async function insertPassword(password, repeatPassword) { | ||
const passwordInput = screen.getByPlaceholderText(/addUser.password_placeholder/i); | ||
const passwordRepeatInput = screen.getByPlaceholderText(/addUser.repeat_password_placeholder/i); | ||
|
||
expect(screen.getByText(/addUser.email_placeholder/)).toBeInTheDocument(); | ||
userEvent.type(passwordInput, password); | ||
userEvent.type(passwordRepeatInput, repeatPassword); | ||
const submitButton = screen.getByText(/forgotPassword.enter_password_button/i); // Ajusta el texto según el texto real del botón | ||
userEvent.click(submitButton); | ||
} |