Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sinne10 committed Apr 16, 2024
1 parent 46c3e92 commit aeda7db
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions webapp/src/components/loginAndRegistration/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,23 @@ describe('<AddUser />', () => {
fireEvent.click(submitButton);
};

test('displays error message when passwords do not match', () => {
test('displays correct error messages', async () => {
//Passwords do not match
fillFormAndSubmit('username', '12345678', '123456789');
expect(screen.getByText('addUser.error_passwords_no_match')).toBeInTheDocument();
});

test('displays error message when spaces in password', () => {
//Password with spaces
fillFormAndSubmit('username', '1234 5678', '1234 5678');
expect(screen.getByText('addUser.error_password_spaces')).toBeInTheDocument();
});

test('displays error message when passwords too short', () => {
//Password too short
fillFormAndSubmit('username', '1234567', '1234567');
expect(screen.getByText('addUser.error_password_minimum_length')).toBeInTheDocument();
});

test('displays error message when passwords too long', () => {
//Password too long
fillFormAndSubmit('username', '01234567890123456789012345678901234567890123456789012345678901234', '01234567890123456789012345678901234567890123456789012345678901234');
expect(screen.getByText('addUser.error_password_maximum_length')).toBeInTheDocument();
});

test('displays error message when spaces in username', () => {
//Username with spaces
fillFormAndSubmit('user name', '12345678', '12345678');
expect(screen.getByText('addUser.error_username_spaces')).toBeInTheDocument();
});

test('displays error message when username is already in use', async () => {
//Username in use
axios.post.mockRejectedValue({ response: { data: { error: 'Username already in use' } } });
fillFormAndSubmit('existing_user', '12345678', '12345678');
await waitFor(() => {
Expand Down

0 comments on commit aeda7db

Please sign in to comment.