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-7716 Add Mass Actions to Partner Giving Analysis page #773

Merged
merged 8 commits into from
Jul 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ const PartnerGivingAnalysisReportPage: React.FC = () => {
mainContent={
<PartnerGivingAnalysisReport
accountListId={accountListId}
activeFilters={activeFilters}
isNavListOpen={isNavListOpen}
onNavListToggle={handleNavListToggle}
onSelectContact={handleSelectContact}
title={t('Partner Giving Analysis')}
contactFilters={debouncedFilters}
contactDetailsOpen={typeof selectedContactId !== 'undefined'}
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
/>
}
rightPanel={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const ContactsMainPanelHeader: React.FC = () => {
toggleStarredFilter={setStarredFilter}
headerCheckboxState={selectionType}
selectedIds={selectedIds}
showShowingCount={viewMode === TableViewModeEnum.List}
buttonGroup={
<Hidden xsDown>
<Box display="flex" alignItems="center">
Expand Down
12 changes: 8 additions & 4 deletions src/components/Reports/AccountsListLayout/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import theme from 'src/theme';
import FilterList from '@mui/icons-material/FilterList';

interface AccountsListHeaderProps {
showNavListButton?: boolean;
isNavListOpen: boolean;
onNavListToggle: () => void;
title: string;
Expand All @@ -15,7 +16,7 @@ interface AccountsListHeaderProps {
const StickyHeader = styled(Box)(({}) => ({
position: 'sticky',
top: 0,
height: 96,
//height: 96,
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
}));

const NavListButton = styled(IconButton, {
Expand All @@ -40,6 +41,7 @@ export const AccountsListHeader: FC<AccountsListHeaderProps> = ({
rightExtra,
isNavListOpen,
onNavListToggle,
showNavListButton = true,
}) => {
const { t } = useTranslation();

Expand All @@ -51,9 +53,11 @@ export const AccountsListHeader: FC<AccountsListHeaderProps> = ({
alignItems="center"
sx={{ lineHeight: 1.1 }}
>
<NavListButton panelOpen={isNavListOpen} onClick={onNavListToggle}>
<NavListIcon titleAccess={t('Toggle Filter Panel')} />
</NavListButton>
{showNavListButton !== false && (
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
<NavListButton panelOpen={isNavListOpen} onClick={onNavListToggle}>
<NavListIcon titleAccess={t('Toggle Filter Panel')} />
</NavListButton>
)}
<Typography variant="h5" sx={{ flex: 1 }}>
{title}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,38 @@ import { GetPartnerGivingAnalysisReportQuery } from './PartnerGivingAnalysisRepo
import { PartnerGivingAnalysisReport } from './PartnerGivingAnalysisReport';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import theme from 'src/theme';
import { GetIdsForMassSelectionQuery } from 'src/hooks/GetIdsForMassSelection.generated';

const accountListId = '111';
const title = 'test title';
const contactDetailsOpen = false;
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
const onNavListToggle = jest.fn();
const onSelectContact = jest.fn();
const activeFilters = {};
// const contactFilters = {};
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
const defaultProps = {
accountListId,
title,
onNavListToggle,
onSelectContact,
contactDetailsOpen,
activeFilters,
// contactFilters,
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
};

const mockEnqueue = jest.fn();

jest.mock('notistack', () => ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
...jest.requireActual('notistack'),
useSnackbar: () => {
return {
enqueueSnackbar: mockEnqueue,
};
},
}));

jest.mock('next/router', () => ({
useRouter: () => {
return {
Expand All @@ -29,6 +49,7 @@ jest.mock('next/router', () => ({

type Mocks = {
GetPartnerGivingAnalysisReport: GetPartnerGivingAnalysisReportQuery;
GetIdsForMassSelection?: GetIdsForMassSelectionQuery;
};

const mocks: Mocks = {
Expand Down Expand Up @@ -60,7 +81,7 @@ const mocks: Mocks = {
totalDonations: 13118.42,
},
{
donationPeriodAverage: 86.4682954545454545,
donationPeriodAverage: 86.4684354186,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
Expand All @@ -71,14 +92,125 @@ const mocks: Mocks = {
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '04',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '05',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '06',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '07',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '08',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '09',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '10',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
{
donationPeriodAverage: 86.46,
donationPeriodCount: 221,
donationPeriodSum: 25218.42,
lastDonationAmount: 150.92,
lastDonationCurrency: 'CAD',
lastDonationDate: '2021-08-07',
id: '11',
name: 'Jasmine (Princess)',
pledgeCurrency: 'CAD',
totalDonations: 25218.42,
},
],
pagination: {
page: 1,
pageSize: 10,
totalItems: 120,
totalPages: 12,
},
totalContacts: 300,
totalContacts: 11,
},
},
GetIdsForMassSelection: {
contacts: {
nodes: [
{
id: '01',
},
{
id: '02',
},
{
id: '03',
},
],
},
},
};
Expand Down Expand Up @@ -121,7 +253,7 @@ describe('PartnerGivingAnalysisReport', () => {

expect(getByRole('table')).toBeInTheDocument();
expect(getAllByTestId('PartnerGivingAnalysisReportTableRow').length).toBe(
3,
11,
);
expect(getByTestId('PartnerGivingAnalysisReport')).toBeInTheDocument();
});
Expand Down Expand Up @@ -217,11 +349,12 @@ describe('PartnerGivingAnalysisReport', () => {
queryByTestId('LoadingPartnerGivingAnalysisReport'),
).not.toBeInTheDocument();
});

expect(
mutationSpy.mock.calls[1][0].operation.variables.input.sortField,
mutationSpy.mock.calls[2][0].operation.variables.input.sortField,
).toEqual('donationPeriodCount');
expect(
mutationSpy.mock.calls[1][0].operation.variables.input.sortDirection,
mutationSpy.mock.calls[2][0].operation.variables.input.sortDirection,
).toEqual('ASCENDING');

userEvent.click(getByText('Gift Count'));
Expand All @@ -230,11 +363,12 @@ describe('PartnerGivingAnalysisReport', () => {
queryByTestId('LoadingPartnerGivingAnalysisReport'),
).not.toBeInTheDocument();
});

expect(
mutationSpy.mock.calls[2][0].operation.variables.input.sortField,
mutationSpy.mock.calls[3][0].operation.variables.input.sortField,
).toEqual('donationPeriodCount');
expect(
mutationSpy.mock.calls[2][0].operation.variables.input.sortDirection,
mutationSpy.mock.calls[3][0].operation.variables.input.sortDirection,
).toEqual('DESCENDING');

userEvent.click(getByText('Gift Average'));
Expand All @@ -244,10 +378,10 @@ describe('PartnerGivingAnalysisReport', () => {
).not.toBeInTheDocument();
});
expect(
mutationSpy.mock.calls[3][0].operation.variables.input.sortField,
mutationSpy.mock.calls[4][0].operation.variables.input.sortField,
).toEqual('donationPeriodAverage');
expect(
mutationSpy.mock.calls[3][0].operation.variables.input.sortDirection,
mutationSpy.mock.calls[4][0].operation.variables.input.sortDirection,
).toEqual('ASCENDING');
});

Expand All @@ -272,7 +406,7 @@ describe('PartnerGivingAnalysisReport', () => {
).not.toBeInTheDocument();
});

userEvent.type(getByPlaceholderText('Search contacts'), 'John');
userEvent.type(getByPlaceholderText('Search Contacts'), 'John');
await waitFor(() => {
expect(
queryByTestId('LoadingPartnerGivingAnalysisReport'),
Expand All @@ -285,13 +419,13 @@ describe('PartnerGivingAnalysisReport', () => {
});

expect(
mutationSpy.mock.calls[1][0].operation.variables.input.contactFilters,
mutationSpy.mock.calls[2][0].operation.variables.input.contactFilters,
).toEqual({ nameLike: '%John%' });
});

it('sets the pagination limit', async () => {
const mutationSpy = jest.fn();
const { getByRole, queryByTestId } = render(
const { getByRole, queryByTestId, getByTestId, getByText } = render(
<ThemeProvider theme={theme}>
<GqlMockedProvider<{
GetPartnerGivingAnalysisReport: GetPartnerGivingAnalysisReportQuery;
Expand All @@ -318,8 +452,18 @@ describe('PartnerGivingAnalysisReport', () => {
});

expect(
mutationSpy.mock.calls[1][0].operation.variables.input.pageSize,
mutationSpy.mock.calls[2][0].operation.variables.input.pageSize,
).toBe(50);

userEvent.selectOptions(getByRole('combobox'), '10');
userEvent.click(getByTestId('KeyboardArrowRightIcon'));
await waitFor(() => {
expect(
queryByTestId('LoadingPartnerGivingAnalysisReport'),
).not.toBeInTheDocument();
});

expect(getByText('11–20 of 120')).toBeInTheDocument();
});

it('selects and unselects all', async () => {
Expand Down Expand Up @@ -348,6 +492,7 @@ describe('PartnerGivingAnalysisReport', () => {

// Select all
userEvent.click(getAllByRole('checkbox')[0]);
expect(getAllByRole('checkbox')[0]).toBeChecked();
expect(getAllByRole('checkbox')[1]).toBeChecked();
expect(getAllByRole('checkbox')[2]).toBeChecked();
expect(getAllByRole('checkbox')[3]).toBeChecked();
Expand All @@ -367,6 +512,14 @@ describe('PartnerGivingAnalysisReport', () => {
userEvent.click(getAllByRole('checkbox')[1]);
userEvent.click(getAllByRole('checkbox')[2]);
userEvent.click(getAllByRole('checkbox')[3]);
userEvent.click(getAllByRole('checkbox')[4]);
userEvent.click(getAllByRole('checkbox')[5]);
userEvent.click(getAllByRole('checkbox')[6]);
userEvent.click(getAllByRole('checkbox')[7]);
userEvent.click(getAllByRole('checkbox')[8]);
userEvent.click(getAllByRole('checkbox')[9]);
userEvent.click(getAllByRole('checkbox')[10]);
userEvent.click(getAllByRole('checkbox')[11]);
expect(getAllByRole('checkbox')[0]).toBeChecked();

// Deselect all individually
Expand All @@ -376,7 +529,7 @@ describe('PartnerGivingAnalysisReport', () => {
expect(getAllByRole('checkbox')[0]).not.toBeChecked();
});

it('contact names are clickable', async () => {
it('can click on contact names', async () => {
const mutationSpy = jest.fn();
const { getByText, queryByTestId } = render(
<ThemeProvider theme={theme}>
Expand Down
Loading
Loading