diff --git a/webapp/src/components/ForgetPassword/ForgetPassword.test.js b/webapp/src/components/ForgetPassword/ForgetPassword.test.js index 7f7eef5..740783c 100644 --- a/webapp/src/components/ForgetPassword/ForgetPassword.test.js +++ b/webapp/src/components/ForgetPassword/ForgetPassword.test.js @@ -74,7 +74,20 @@ describe('ForgetPassword Component', () => { 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') + + fillPassword('123456', '123456') + expect(screen.getByText(/addUser.very_weak_password/)).toBeInTheDocument(); + + fillPassword('Mario12@@', 'Mario12@@') + expect(screen.getByText(/addUser.weak_password/)).toBeInTheDocument(); + + fillPassword('NvtL+k?qg9', 'NvtL+k?qg9') + expect(screen.getByText(/addUser.good_password/)).toBeInTheDocument(); + + fillPassword('NvtL+k?qg953tD8', 'NvtL+k?qg953tD8') + expect(screen.getByText(/addUser.strong_password/)).toBeInTheDocument(); + + await insertPassword('NvtL+k?qg953tD8', 'NvtL+k?qg953tD8') //me redirigen a game Menu await waitFor(async () => expect(screen.getByText(i18en.t('gameMenu.title')).toBeInTheDocument())); //la cookie queda bien seteada @@ -168,12 +181,16 @@ async function insertCode(code){ } async function insertPassword(password, repeatPassword) { + fillPassword(password, repeatPassword) + const submitButton = screen.getByText(/forgotPassword.enter_password_button/i); // Ajusta el texto según el texto real del botón + userEvent.click(submitButton); +} + +function fillPassword(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); } \ No newline at end of file diff --git a/webapp/src/components/loginAndRegistration/AddUser.test.js b/webapp/src/components/loginAndRegistration/AddUser.test.js index f95b52e..8af3be7 100644 --- a/webapp/src/components/loginAndRegistration/AddUser.test.js +++ b/webapp/src/components/loginAndRegistration/AddUser.test.js @@ -33,7 +33,7 @@ describe('', () => { }); - const fillFormAndSubmit = (email, username, password, repeatPassword) => { + const fillForm = (email, username, password, repeatPassword) => { const emailInput = screen.getByPlaceholderText('addUser.email_placeholder'); fireEvent.change(emailInput, { target: { value: email } }); @@ -45,6 +45,10 @@ describe('', () => { const repeatPasswordInput = screen.getByPlaceholderText('addUser.repeat_password_placeholder'); fireEvent.change(repeatPasswordInput, { target: { value: repeatPassword } }); + }; + + const fillFormAndSubmit = (email, username, password, repeatPassword) => { + fillForm(email, username, password, repeatPassword) const submitButton = screen.getByText('addUser.register_button'); fireEvent.click(submitButton); @@ -70,7 +74,7 @@ describe('', () => { fillFormAndSubmit('user@example.com', 'username', '01234567890123456789012345678901234567890123456789012345678901234', '01234567890123456789012345678901234567890123456789012345678901234'); expect(screen.getByText('addUser.error_password_maximum_length')).toBeInTheDocument(); //Username with spaces - fillFormAndSubmit('user@example.com', 'user name', '12345678', '12345678'); + fillFormAndSubmit('user@example.com', 'user name', 'NvtL+k?qg953tD8', 'NvtL+k?qg953tD8'); expect(screen.getByText('addUser.error_username_spaces')).toBeInTheDocument(); //Show various errors @@ -87,6 +91,23 @@ describe('', () => { expect(axios.post).toHaveBeenCalledWith(expect.any(String), { email: 'user@example.com' ,username: 'existing_user', password: '12345678', repeatPassword: "12345678" }); }); + test('displays correct password strength messages', () => { + fillForm('user@example.com', 'user name', '123456', '123456'); + expect(screen.getByText(/addUser.very_weak_password/)).toBeInTheDocument(); + + fillForm('user@example.com', 'user name', 'Mario12@@', 'Mario12@@'); + expect(screen.getByText(/addUser.weak_password/)).toBeInTheDocument(); + + fillForm('user@example.com', 'user name', 'NvtL+k?qg9', 'NvtL+k?qg9'); + expect(screen.getByText(/addUser.good_password/)).toBeInTheDocument(); + + fillForm('user@example.com', 'user name', 'NvtL+k?qg953tD8', 'NvtL+k?qg953tD8'); + expect(screen.getByText(/addUser.strong_password/)).toBeInTheDocument(); + + fillForm('user@example.com', 'user name', '', ''); + expect(screen.getByText(/addUser.very_weak_password/)).toBeInTheDocument(); + }) + });