Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added strenght check tests #170

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
})

});