diff --git a/src/containers/ContactManagement/AdminContactManagement/AdminContactManagement.test.tsx b/src/containers/ContactManagement/AdminContactManagement/AdminContactManagement.test.tsx index fbe30a6fc..2181fd1a2 100644 --- a/src/containers/ContactManagement/AdminContactManagement/AdminContactManagement.test.tsx +++ b/src/containers/ContactManagement/AdminContactManagement/AdminContactManagement.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MockedProvider } from '@apollo/client/testing'; @@ -60,3 +60,30 @@ test('Files other than .csv should raise a warning message upon upload', async ( ).toBeInTheDocument(); }); }); + +test('it removes the selected file', async () => { + render(contactManagement); + + fireEvent.click(screen.getByTestId('uploadFile')); + + const csvContent = `name,phone,collection + John Doe,919876543210,"Optin collection,Optout Collection" + Virat Kohli,919876543220,Cricket`; + const file = new File([csvContent], 'test.csv', { type: 'text/csv' }); + + await waitFor(() => { + const fileInput = screen.getByTestId('uploadFile'); + userEvent.upload(fileInput, file); + }); + + await waitFor(() => { + // the filename should be visible instead of Select .csv after upload + expect(screen.getByText('test.csv')).toBeInTheDocument(); + }); + + fireEvent.click(screen.getByTestId('cross-icon')); + + await waitFor(() => { + expect(screen.queryByText('test.csv')).not.toBeInTheDocument(); + }); +}); diff --git a/src/containers/NotificationList/NotificationList.test.tsx b/src/containers/NotificationList/NotificationList.test.tsx index 3333e5636..2b0e7bee3 100644 --- a/src/containers/NotificationList/NotificationList.test.tsx +++ b/src/containers/NotificationList/NotificationList.test.tsx @@ -11,9 +11,11 @@ import { markAllNotificationAsRead, getInfoNotificationsQuery, getStatus, + getStatusWithError, } from 'mocks/Notifications'; import { setUserSession } from 'services/AuthService'; import { NotificationList } from './NotificationList'; +import * as Notification from 'common/notification'; setUserSession(JSON.stringify({ roles: ['Admin'] })); @@ -32,16 +34,21 @@ const mocks: any = [ getInfoNotificationsQuery({ severity: 'Critical' }), getInfoNotificationsQuery({ severity: '' }), getInfoNotificationsQuery(), - getStatus, ]; -const notifications = ( - - - - - -); +const notifications = (mock?: any) => { + let MOCKS = mocks; + if (mock) { + MOCKS = [...MOCKS, mock]; + } + return ( + + + + + + ); +}; const mockedUsedNavigate = vi.fn(); vi.mock('react-router-dom', async () => ({ @@ -50,7 +57,7 @@ vi.mock('react-router-dom', async () => ({ })); test('It should load notifications', async () => { - render(notifications); + render(notifications()); await waitFor(() => { expect(screen.getByTestId('loading')).toBeInTheDocument(); @@ -75,7 +82,7 @@ test('It should load notifications', async () => { }); test('click on forward arrrow', async () => { - render(notifications); + render(notifications(getStatus)); await waitFor(() => { expect(screen.getByTestId('loading')).toBeInTheDocument(); @@ -97,7 +104,7 @@ test('click on forward arrrow', async () => { }); test('it should show copy text and view option on clicking entity ', async () => { - const { getByTestId, getByText } = render(notifications); + const { getByTestId, getByText } = render(notifications()); await waitFor(() => { const entityMenu = screen.getAllByTestId('NotificationRowMenu'); expect(entityMenu[0]).toBeInTheDocument(); @@ -126,7 +133,7 @@ test('it should show copy text and view option on clicking entity ', async () => }); test('it should show filter radio button', async () => { - render(notifications); + render(notifications()); await waitFor(() => { const checkboxInput = screen.getAllByTestId('radio'); @@ -135,7 +142,7 @@ test('it should show filter radio button', async () => { }); test('it should have Info, Warning and critical checkbox', async () => { - render(notifications); + render(notifications()); await waitFor(() => { const checkboxInput = screen.getAllByTestId('radio'); @@ -145,3 +152,26 @@ test('it should have Info, Warning and critical checkbox', async () => { expect(checkboxInput[3]).toHaveTextContent('All'); }); }); + +test('it should show "Contact import is in progress" message', async () => { + const notificationSpy = vi.spyOn(Notification, 'setNotification'); + render(notifications(getStatusWithError)); + + await waitFor(() => { + expect(screen.getByTestId('loading')).toBeInTheDocument(); + }); + + await waitFor(() => { + expect(screen.getByText('Notifications')).toBeInTheDocument(); + }); + + const arrowButtons = screen.getAllByTestId('ArrowForwardIcon'); + + arrowButtons.forEach(async (button) => { + fireEvent.click(button); + + await waitFor(() => { + expect(notificationSpy).toHaveBeenCalledWith(); + }); + }); +}); diff --git a/src/mocks/Notifications.tsx b/src/mocks/Notifications.tsx index 6ad914fe7..ff0338fd3 100644 --- a/src/mocks/Notifications.tsx +++ b/src/mocks/Notifications.tsx @@ -74,12 +74,21 @@ export const getNotificationsQuery = { { category: 'Contact Upload', entity: '{"user_job_id":1}', - id: '60', + id: '7', isRead: true, message: 'Contact upload completed', severity: '"Information"', updatedAt: '2024-08-09T05:50:00Z', }, + { + category: 'unknown category', + entity: '{}', + id: '8', + isRead: true, + message: '', + severity: '', + updatedAt: '2024-08-09T05:50:00Z', + }, ], }, }, @@ -221,9 +230,26 @@ export const getStatus = { result: { data: { getContactUploadReport: { - csvRows: '', + csvRows: 'Contact import done', error: null, }, }, }, }; + +export const getStatusWithError = { + request: { + query: GET_CONTACT_IMPORT_STATUS, + variables: { + userJobId: 1, + }, + }, + result: { + data: { + getContactUploadReport: { + csvRows: null, + error: 'Contact upload is in progress', + }, + }, + }, +};