diff --git a/src/components/UserPasswordUpdate/UserPasswordUpdate.test.tsx b/src/components/UserPasswordUpdate/UserPasswordUpdate.test.tsx
index 7b07db0cc7..285b430c59 100644
--- a/src/components/UserPasswordUpdate/UserPasswordUpdate.test.tsx
+++ b/src/components/UserPasswordUpdate/UserPasswordUpdate.test.tsx
@@ -3,11 +3,18 @@ import { act, render, screen } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import userEvent from '@testing-library/user-event';
import { I18nextProvider } from 'react-i18next';
-
import { UPDATE_USER_PASSWORD_MUTATION } from 'GraphQl/Mutations/mutations';
import i18nForTest from 'utils/i18nForTest';
import UserPasswordUpdate from './UserPasswordUpdate';
import { StaticMockLink } from 'utils/StaticMockLink';
+import { toast as mockToast } from 'react-toastify';
+
+jest.mock('react-toastify', () => ({
+ toast: {
+ error: jest.fn(),
+ success: jest.fn(),
+ },
+}));
const MOCKS = [
{
@@ -48,9 +55,10 @@ describe('Testing User Password Update', () => {
};
const formData = {
- previousPassword: 'anshgoyal',
- newPassword: 'anshgoyalansh',
- confirmNewPassword: 'anshgoyalansh',
+ previousPassword: 'Palisadoes',
+ newPassword: 'ThePalisadoesFoundation',
+ wrongPassword: 'This is wrong passoword',
+ confirmNewPassword: 'ThePalisadoesFoundation',
};
global.alert = jest.fn();
@@ -89,4 +97,54 @@ describe('Testing User Password Update', () => {
screen.getByPlaceholderText(/Confirm New Password/i)
).toBeInTheDocument();
});
+
+ test('displays an error when the password field is empty', async () => {
+ render(
+
+
+
+
+
+ );
+
+ userEvent.click(screen.getByText(/Save Changes/i));
+
+ await wait();
+ expect(mockToast.error).toHaveBeenCalledWith(
+ 'The password field cannot be empty.'
+ );
+ });
+
+ test('displays an error when new and confirm password field does not match', async () => {
+ render(
+
+
+
+
+
+ );
+
+ await wait();
+
+ userEvent.type(
+ screen.getByPlaceholderText(/Previous Password/i),
+ formData.previousPassword
+ );
+ userEvent.type(
+ screen.getAllByPlaceholderText(/New Password/i)[0],
+ formData.wrongPassword
+ );
+ userEvent.type(
+ screen.getByPlaceholderText(/Confirm New Password/i),
+ formData.confirmNewPassword
+ );
+
+ userEvent.click(screen.getByText(/Save Changes/i));
+
+ expect(screen.getByText(/Cancel/i)).toBeTruthy();
+ await wait();
+ expect(mockToast.error).toHaveBeenCalledWith(
+ 'New and Confirm password do not match.'
+ );
+ });
});