From 2fa695da415fe0c95fbedc17db4a94efc1424c99 Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Thu, 23 Nov 2023 15:32:30 +0500 Subject: [PATCH] tests: add test coverage --- lib/DonorFilter/PluggableDonorFilter.test.js | 26 +++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/DonorFilter/PluggableDonorFilter.test.js b/lib/DonorFilter/PluggableDonorFilter.test.js index ab014e96..709cde8c 100644 --- a/lib/DonorFilter/PluggableDonorFilter.test.js +++ b/lib/DonorFilter/PluggableDonorFilter.test.js @@ -10,7 +10,7 @@ jest.mock('../Donors', () => ({ ...jest.requireActual('../Donors'), useFetchDonors: jest.fn(() => ({ isLoading: false, - donors: [], + donors: [{ id: '1', name: 'Amazon' }], })), DonorsLookup: jest.fn(({ children, ...rest }) => { return ( @@ -43,7 +43,7 @@ const renderFilter = (props) => (render( id="donor" activeFilters={[]} labelId={labelId} - name="donor" + name={mockVendorData.name} onChange={() => {}} {...props} />, @@ -67,6 +67,26 @@ describe('PluggableDonorFilter', () => { expect(addDonorsButton).toBeDefined(); user.click(addDonorsButton); - expect(mockOnAddDonors).toHaveBeenCalledWith({ name: 'donor', values: [mockVendorData.id] }); + expect(mockOnAddDonors).toHaveBeenCalledWith({ + name: mockVendorData.name, + values: [mockVendorData.id], + }); + }); + + it('should clear all donors', () => { + const mockOnAddDonors = jest.fn(); + const { getAllByRole } = renderFilter({ + onChange: mockOnAddDonors, + activeFilters: [mockVendorData.id], + }); + + const clearAllButton = getAllByRole('button')[1]; + + expect(clearAllButton).toBeDefined(); + user.click(clearAllButton); + expect(mockOnAddDonors).toHaveBeenCalledWith({ + name: mockVendorData.name, + values: [], + }); }); });