Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPDX-7786 Don't round donations #833

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ query GetExpectedMonthlyTotals(
total
}
currency
currencySymbol
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,27 @@ describe('AppointmentResults', () => {
'Monthly Support Gained',
);
expect(monthlyIncreaseRow.children[1]).toHaveTextContent('$111');
expect(monthlyIncreaseRow.children[2]).toHaveTextContent('$667');
expect(monthlyIncreaseRow.children[3]).toHaveTextContent('$778');
expect(monthlyIncreaseRow.children[4]).toHaveTextContent('$519');
expect(monthlyIncreaseRow.children[2]).toHaveTextContent('$666.66');
expect(monthlyIncreaseRow.children[3]).toHaveTextContent('$777.77');
expect(monthlyIncreaseRow.children[4]).toHaveTextContent('$518.51');

const monthlyDecreaseRow = rows[6];
expect(monthlyDecreaseRow.children[0]).toHaveTextContent(
'Monthly Support Lost',
);
expect(monthlyDecreaseRow.children[1]).toHaveTextContent('-$222');
expect(monthlyDecreaseRow.children[2]).toHaveTextContent('-$444');
expect(monthlyDecreaseRow.children[3]).toHaveTextContent('-$889');
expect(monthlyDecreaseRow.children[4]).toHaveTextContent('-$519');
expect(monthlyDecreaseRow.children[3]).toHaveTextContent('-$888.88');
expect(monthlyDecreaseRow.children[4]).toHaveTextContent('-$518.51');

const specialIncreaseRow = rows[7];
expect(specialIncreaseRow.children[0]).toHaveTextContent(
'Special Needs Gained',
);
expect(specialIncreaseRow.children[1]).toHaveTextContent('$333');
expect(specialIncreaseRow.children[2]).toHaveTextContent('$556');
expect(specialIncreaseRow.children[3]).toHaveTextContent('$1,000');
expect(specialIncreaseRow.children[4]).toHaveTextContent('$630');
expect(specialIncreaseRow.children[2]).toHaveTextContent('$555.55');
expect(specialIncreaseRow.children[3]).toHaveTextContent('$999.99');
expect(specialIncreaseRow.children[4]).toHaveTextContent('$629.62');
});

it('loads data for the weekly period', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('ContactDonationsList', () => {
});

it('test Renderer', async () => {
const { findByRole, getByRole } = render(
const { findByRole, getByRole, getAllByRole } = render(
<GqlMockedProvider<{ ContactDonationsList: ContactDonationsListQuery }>
mocks={{
ContactDonationsList: {
Expand All @@ -53,6 +53,8 @@ describe('ContactDonationsList', () => {
amount: {
currency: 'USD',
convertedCurrency: 'EUR',
amount: 10,
convertedAmount: 9.9,
},
};
}),
Expand Down Expand Up @@ -86,5 +88,9 @@ describe('ContactDonationsList', () => {
).childElementCount,
).toMatchInlineSnapshot(`14`);
// TODO: Fix toMatchInlineSnapshot to be `27`
const rows = getAllByRole('row');
const donationRow = rows[1];
expect(donationRow.children[1]).toHaveTextContent('$10');
expect(donationRow.children[2]).toHaveTextContent('€9.90');
});
});
4 changes: 2 additions & 2 deletions src/components/Dashboard/Balance/Balance.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Balance', () => {
<Balance balance={1000.99} />
</GqlMockedProvider>,
);
expect(getByTestId('BalanceTypography').textContent).toEqual('$1,001');
expect(getByTestId('BalanceTypography').textContent).toEqual('$1,000.99');
// TODO: needs fix, switching from the HandOffLink to NextLink breaks this
// expect(
// getByRole('link', { hidden: true, name: 'View Gifts' }),
Expand All @@ -32,7 +32,7 @@ describe('Balance', () => {
<Balance balance={1000.99} currencyCode="EUR" />
</GqlMockedProvider>,
);
expect(getByTestId('BalanceTypography').textContent).toEqual('€1,001');
expect(getByTestId('BalanceTypography').textContent).toEqual('€1,000.99');
});

it('loading', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Dashboard/MonthlyGoal/MonthlyGoal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('MonthlyGoal', () => {
/>,
);
expect(getByTestId('MonthlyGoalTypographyGoal').textContent).toEqual(
'€1,000',
'€999.50',
);
expect(
getByTestId('MonthlyGoalTypographyReceivedPercentage').textContent,
Expand All @@ -101,7 +101,7 @@ describe('MonthlyGoal', () => {
getByTestId('MonthlyGoalTypographyBelowGoalPercentage').textContent,
).toEqual('25%');
expect(getByTestId('MonthlyGoalTypographyBelowGoal').textContent).toEqual(
'€250',
'€249.50',
);
expect(
queryByTestId('MonthlyGoalTypographyAboveGoalPercentage'),
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('MonthlyGoal', () => {
getByTestId('MonthlyGoalTypographyAboveGoalPercentage').textContent,
).toEqual('650%');
expect(getByTestId('MonthlyGoalTypographyAboveGoal').textContent).toEqual(
'€6,501',
'€6,500.50',
);
expect(
queryByTestId('MonthlyGoalTypographyBelowGoalPercentage'),
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('MonthlyGoal', () => {
);
expect(
getByTestId('MonthlyGoalTypographyGoalMobile').textContent,
).toEqual('€1,000');
).toEqual('€999.50');
});
});
});
6 changes: 3 additions & 3 deletions src/components/Dashboard/ThisWeek/Appeals/Appeals.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ describe('Appeals', () => {
);

expect(getByTestId('AppealsBoxName').textContent).toEqual('My Appeal');
expect(getByTestId('AppealsBoxAmount').textContent).toEqual('€5,000 EUR');
expect(getByTestId('AppealsBoxAmount').textContent).toEqual('€4,999.99');
expect(
getByTestId('AppealsTypographyPledgesAmountProcessedPercentage')
.textContent,
).toEqual('20%');
expect(
getByTestId('AppealsTypographyPledgesAmountProcessed').textContent,
).toEqual('€1,000');
).toEqual('€999.99');
expect(
getByTestId('AppealsTypographyPledgesAmountTotalPercentage').textContent,
).toEqual('50%');
expect(
getByTestId('AppealsTypographyPledgesAmountTotal').textContent,
).toEqual('€2,500');
).toEqual('€2,499.99');
});
});
1 change: 0 additions & 1 deletion src/components/Dashboard/ThisWeek/Appeals/Appeals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ const Appeals = ({ loading, appeal }: Props): ReactElement => {
appeal?.amountCurrency,
locale,
)}
{' ' + appeal?.amountCurrency}
</Box>
</Box>
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mocks = {
},
},
GetDonationsTable: {
currency: 'CAD',
donations: {
nodes: [
{
Expand Down Expand Up @@ -288,6 +289,11 @@ describe('DonationsReportTable', () => {

it('is not clickable when contact is missing', async () => {
const mocks = {
GetAccountListCurrency: {
accountList: {
currency: 'CAD',
},
},
GetDonationsTable: {
donations: {
nodes: [
Expand Down Expand Up @@ -405,14 +411,14 @@ describe('DonationsReportTable', () => {
).toBeInTheDocument();

userEvent.click(await findByRole('columnheader', { name: 'Amount' }));
const cellsAsc = getAllByRole('cell', { name: /CAD/ });
expect(cellsAsc[0]).toHaveTextContent('10 CAD');
expect(cellsAsc[1]).toHaveTextContent('100 CAD');
const cellsAsc = getAllByRole('cell', { name: /CA/ });
expect(cellsAsc[0]).toHaveTextContent('CA$10');
expect(cellsAsc[1]).toHaveTextContent('CA$100');

userEvent.click(await findByRole('columnheader', { name: 'Amount' }));
const cellsDesc = getAllByRole('cell', { name: /CAD/ });
expect(cellsDesc[0]).toHaveTextContent('100 CAD');
expect(cellsDesc[1]).toHaveTextContent('10 CAD');
const cellsDesc = getAllByRole('cell', { name: /CA/ });
expect(cellsDesc[0]).toHaveTextContent('CA$100');
expect(cellsDesc[1]).toHaveTextContent('CA$10');
});

it('updates the page size without rerendering until the month changes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { DateTime } from 'luxon';
import { useTranslation } from 'react-i18next';
import { useFetchAllPages } from 'src/hooks/useFetchAllPages';
import { useLocale } from 'src/hooks/useLocale';
import { dateFormatShort } from 'src/lib/intlFormat/intlFormat';
import { currencyFormat, dateFormatShort } from 'src/lib/intlFormat/intlFormat';
import { EmptyDonationsTable } from '../../../common/EmptyDonationsTable/EmptyDonationsTable';
import {
ExpectedDonationDataFragment,
Expand Down Expand Up @@ -199,6 +199,7 @@ export const DonationsReportTable: React.FC<DonationReportTableProps> = ({
return (
<Typography sx={{ cursor: 'pointer' }}>
<Link
underline="hover"
onClick={() =>
donation.contactId && onSelectContact(donation.contactId)
}
Expand All @@ -214,9 +215,7 @@ export const DonationsReportTable: React.FC<DonationReportTableProps> = ({

return (
<Typography>
{`${Math.round(donation.convertedAmount * 100) / 100} ${
canac marked this conversation as resolved.
Show resolved Hide resolved
donation.currency
}`}
{currencyFormat(donation.convertedAmount, donation.currency, locale)}
</Typography>
);
};
Expand All @@ -225,9 +224,11 @@ export const DonationsReportTable: React.FC<DonationReportTableProps> = ({
const donation = params.row as Donation;
return (
<Typography>
{`${Math.round(donation.foreignAmount * 100) / 100} ${
donation.foreignCurrency
}`}
{currencyFormat(
donation.foreignAmount,
donation.foreignCurrency,
locale,
)}
</Typography>
);
};
Expand Down Expand Up @@ -439,16 +440,18 @@ export const DonationsReportTable: React.FC<DonationReportTableProps> = ({
<Typography
style={{ float: 'left', fontWeight: 'bold' }}
>
{Math.round(total.convertedTotal * 100) / 100}{' '}
{accountCurrency}
{currencyFormat(
total.convertedTotal,
accountCurrency,
locale,
)}
</Typography>
</TableCell>
<TableCell style={{}}>
<Typography
style={{ float: 'left', fontWeight: 'bold' }}
>
{Math.round(total.foreignTotal * 100) / 100}{' '}
{currency}
{currencyFormat(total.foreignTotal, currency, locale)}
</Typography>
</TableCell>
</TableRow>
Expand All @@ -464,7 +467,7 @@ export const DonationsReportTable: React.FC<DonationReportTableProps> = ({
</TableCell>
<TableCell>
<Typography style={{ float: 'left', fontWeight: 'bold' }}>
{Math.round(totalDonations * 100) / 100}
{currencyFormat(totalDonations, accountCurrency, locale)}
</Typography>
</TableCell>
<TableCell />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,50 @@ const router = {
isReady: true,
};

const mockedDonations = {
GetExpectedMonthlyTotals: {
expectedMonthlyTotalReport: {
currency: 'CAD',
received: {
donations: [
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
{
convertedCurrency: 'CAD',
donationCurrency: 'CAD',
pledgeCurrency: 'CAD',
},
],
},
likely: {
donations: [
{
convertedCurrency: 'CAD',
donationCurrency: 'CAD',
pledgeCurrency: 'CAD',
},
],
},
unlikely: {
donations: [
{
convertedCurrency: 'CAD',
donationCurrency: 'CAD',
pledgeCurrency: 'CAD',
},
],
},
},
},
};

describe('ExpectedMonthlyTotalReport', () => {
it('renders with data', async () => {
const { getAllByTestId, queryByRole, queryAllByRole } = render(
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<GqlMockedProvider<{
GetExpectedMonthlyTotals: GetExpectedMonthlyTotalsQuery;
}>
mocks={mockedDonations}
>
<ExpectedMonthlyTotalReport
accountListId={'abc'}
isNavListOpen={true}
Expand Down Expand Up @@ -90,7 +129,7 @@ describe('ExpectedMonthlyTotalReport', () => {
render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<GqlMockedProvider onCall={mutationSpy}>
<GqlMockedProvider onCall={mutationSpy} mocks={mockedDonations}>
<ExpectedMonthlyTotalReport
accountListId={'abc'}
designationAccounts={['account-1']}
Expand Down Expand Up @@ -120,7 +159,7 @@ describe('ExpectedMonthlyTotalReport', () => {
render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<GqlMockedProvider onCall={mutationSpy}>
<GqlMockedProvider onCall={mutationSpy} mocks={mockedDonations}>
<ExpectedMonthlyTotalReport
accountListId={'abc'}
isNavListOpen={true}
Expand Down Expand Up @@ -148,7 +187,7 @@ describe('ExpectedMonthlyTotalReport', () => {
const { getByTestId } = render(
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<GqlMockedProvider>
<GqlMockedProvider mocks={mockedDonations}>
<ExpectedMonthlyTotalReport
accountListId={'abc'}
isNavListOpen={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it('renders with data', () => {
totalLikely={data.expectedMonthlyTotalReport.likely.total}
totalUnlikely={data.expectedMonthlyTotalReport.unlikely.total}
total={1000}
currency={data.expectedMonthlyTotalReport.currency || ''}
currency={'USD'}
/>
</ThemeProvider>,
);
Expand Down
Loading
Loading