From ca2557be3561d86c8788f30ae4aa8bb91a925bbb Mon Sep 17 00:00:00 2001
From: sergiorodriguezgarcia
<113514397+sergiorodriguezgarcia@users.noreply.github.com>
Date: Tue, 23 Apr 2024 16:37:24 +0200
Subject: [PATCH] feat: Adding more tests to complete the coverage
---
webapp/src/tests/Login.test.js | 16 ++++++++++++++++
webapp/src/tests/Signup.test.js | 30 +++++++++++++++++-------------
2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/webapp/src/tests/Login.test.js b/webapp/src/tests/Login.test.js
index abf22641..a2fa1a88 100644
--- a/webapp/src/tests/Login.test.js
+++ b/webapp/src/tests/Login.test.js
@@ -114,4 +114,20 @@ describe('Login Component', () => {
expect(getByTestId('error-message')).toBeInTheDocument();
});
});
+
+ it('displays error message on unauthorized login attempt', async () => {
+ mockAxios.onPost().replyOnce(HttpStatusCode.Unauthorized);
+ const { getByPlaceholderText, getByTestId } = render();
+ const emailInput = getByPlaceholderText('session.email');
+ const passwordInput = getByPlaceholderText('session.password');
+ const loginButton = getByTestId('Login');
+
+ fireEvent.change(emailInput, { target: { value: 'test@example.com' } });
+ fireEvent.change(passwordInput, { target: { value: 'test' } });
+ fireEvent.click(loginButton);
+
+ await waitFor(() => {
+ expect(getByTestId('error-message')).toBeInTheDocument();
+ });
+ });
});
\ No newline at end of file
diff --git a/webapp/src/tests/Signup.test.js b/webapp/src/tests/Signup.test.js
index 550fe67a..18f91ecf 100644
--- a/webapp/src/tests/Signup.test.js
+++ b/webapp/src/tests/Signup.test.js
@@ -88,31 +88,35 @@ describe('Signup Component', () => {
expect(confirmPasswordInput.value).toBe('newPassword');
});
- it('displays error message on failed login attempt', async () => {
+ it('displays error message on failed register attempt', async () => {
mockAxios.onPost().replyOnce(HttpStatusCode.BadRequest);
const { getByPlaceholderText, getByTestId } = render();
const emailInput = getByPlaceholderText('session.email');
const passwordInput = getByPlaceholderText('session.password');
- const loginButton = getByTestId('Sign up');
+ const registerButton = getByTestId('Sign up');
fireEvent.change(emailInput, { target: { value: 'test@example.com' } });
fireEvent.change(passwordInput, { target: { value: 'password123' } });
- fireEvent.click(loginButton);
+ fireEvent.click(registerButton);
await waitFor(() => {
expect(getByTestId('error-message')).toBeInTheDocument();
});
});
- it('renders button "GoBack"', () => {
- const { getByTestId } = render(
-
-
-
-
-
- );
- const goBackButton = getByTestId('GoBack');
- expect(goBackButton).toBeInTheDocument();
+ it('displays error message on unauthorized register attempt', async () => {
+ mockAxios.onPost().replyOnce(HttpStatusCode.Unauthorized);
+ const { getByPlaceholderText, getByTestId } = render();
+ const emailInput = getByPlaceholderText('session.email');
+ const passwordInput = getByPlaceholderText('session.password');
+ const registerButton = getByTestId('Sign up');
+
+ fireEvent.change(emailInput, { target: { value: 'test@example.com' } });
+ fireEvent.change(passwordInput, { target: { value: 'test' } });
+ fireEvent.click(registerButton);
+
+ await waitFor(() => {
+ expect(getByTestId('error-message')).toBeInTheDocument();
+ });
});
});
\ No newline at end of file