Skip to content

Commit

Permalink
Merge pull request #170 from Arquisoft/150-increase-code-coverage
Browse files Browse the repository at this point in the history
Added strenght check tests
  • Loading branch information
UO289845 committed Apr 28, 2024
2 parents bd70187 + 6d785ed commit 826c88a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
23 changes: 20 additions & 3 deletions webapp/src/components/ForgetPassword/ForgetPassword.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
25 changes: 23 additions & 2 deletions webapp/src/components/loginAndRegistration/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('<AddUser />', () => {

});

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 } });

Expand All @@ -45,6 +45,10 @@ describe('<AddUser />', () => {

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);
Expand All @@ -70,7 +74,7 @@ describe('<AddUser />', () => {
fillFormAndSubmit('[email protected]', 'username', '01234567890123456789012345678901234567890123456789012345678901234', '01234567890123456789012345678901234567890123456789012345678901234');
expect(screen.getByText('addUser.error_password_maximum_length')).toBeInTheDocument();
//Username with spaces
fillFormAndSubmit('[email protected]', 'user name', '12345678', '12345678');
fillFormAndSubmit('[email protected]', 'user name', 'NvtL+k?qg953tD8', 'NvtL+k?qg953tD8');
expect(screen.getByText('addUser.error_username_spaces')).toBeInTheDocument();

//Show various errors
Expand All @@ -87,6 +91,23 @@ describe('<AddUser />', () => {
expect(axios.post).toHaveBeenCalledWith(expect.any(String), { email: '[email protected]' ,username: 'existing_user', password: '12345678', repeatPassword: "12345678" });
});

test('displays correct password strength messages', () => {
fillForm('[email protected]', 'user name', '123456', '123456');
expect(screen.getByText(/addUser.very_weak_password/)).toBeInTheDocument();

fillForm('[email protected]', 'user name', 'Mario12@@', 'Mario12@@');
expect(screen.getByText(/addUser.weak_password/)).toBeInTheDocument();

fillForm('[email protected]', 'user name', 'NvtL+k?qg9', 'NvtL+k?qg9');
expect(screen.getByText(/addUser.good_password/)).toBeInTheDocument();

fillForm('[email protected]', 'user name', 'NvtL+k?qg953tD8', 'NvtL+k?qg953tD8');
expect(screen.getByText(/addUser.strong_password/)).toBeInTheDocument();

fillForm('[email protected]', 'user name', '', '');
expect(screen.getByText(/addUser.very_weak_password/)).toBeInTheDocument();
})

});


0 comments on commit 826c88a

Please sign in to comment.