From 4e786265abdad2d0b3e96748a9b6dca7d48d2449 Mon Sep 17 00:00:00 2001 From: wjames111 Date: Thu, 5 Sep 2024 12:03:58 -0400 Subject: [PATCH] Test coverage for statusTitle. --- .../Tool/FixCommitmentInfo/Contact.tsx | 4 +-- .../FixCommitmentInfo.test.tsx | 25 ++++++++++++++++++- .../FixCommitmentInfo/FixCommitmentInfo.tsx | 5 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/Tool/FixCommitmentInfo/Contact.tsx b/src/components/Tool/FixCommitmentInfo/Contact.tsx index 5108b81ad..8fbaf58b0 100644 --- a/src/components/Tool/FixCommitmentInfo/Contact.tsx +++ b/src/components/Tool/FixCommitmentInfo/Contact.tsx @@ -166,7 +166,7 @@ interface Props { id: string; name: string; donations: DonationsType[]; - statusTitle: string; + statusTitle: string | null | undefined; statusValue: string; amount: number; amountCurrency: string; @@ -304,7 +304,7 @@ const Contact: React.FC = ({ {name} - {`Current: ${statusTitle} ${ + {`Current: ${statusTitle || ''} ${ amount && amountCurrency ? currencyFormat(amount, amountCurrency, locale) : '' diff --git a/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.test.tsx b/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.test.tsx index f50db2362..410fa7d63 100644 --- a/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.test.tsx +++ b/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.test.tsx @@ -76,13 +76,16 @@ describe('FixCommitmentContact', () => { }); it('default with test data', async () => { - const { getByText, findByText } = render(); + const { getByText, getAllByText, findByText } = render(); await findByText('Fix Commitment Info'); expect(getByText('Fix Commitment Info')).toBeInTheDocument(); expect( getByText('You have 2 partner statuses to confirm.'), ).toBeInTheDocument(); + expect(getAllByText('Current: Partner - Financial $1 Weekly')).toHaveLength( + 2, + ); }); it('has correct styles', async () => { @@ -179,4 +182,24 @@ describe('FixCommitmentContact', () => { expect(setContactFocus).toHaveBeenCalled(); }); + + it('updates contact info with dontChange enum', async () => { + const { findAllByTestId, findByText, getAllByTestId, queryByText } = render( + , + ); + + userEvent.click((await findAllByTestId('doNotChangeButton'))[0]); + + expect( + await findByText( + "Are you sure you wish to leave Tester 1's commitment information unchanged?", + ), + ).toBeInTheDocument(); + + userEvent.click(getAllByTestId('action-button')[1]); + + await waitFor(() => + expect(queryByText('Tester 1')).not.toBeInTheDocument(), + ); + }); }); diff --git a/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.tsx b/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.tsx index 770571982..d4743f103 100644 --- a/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.tsx +++ b/src/components/Tool/FixCommitmentInfo/FixCommitmentInfo.tsx @@ -273,9 +273,8 @@ const FixCommitmentInfo: React.FC = ({ key={contact.id} donations={contact.donations?.nodes} statusTitle={ - contact.status - ? contactPartnershipStatus[contact.status] - : '' + contact.status && + contactPartnershipStatus[contact.status] } statusValue={ getLocalizedContactStatus(t, contact.status) || ''