Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Sep 3, 2024
1 parent 51411e7 commit b8338d3
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 0 deletions.
175 changes: 175 additions & 0 deletions src/components/Tool/Appeal/List/ContactsList/ContactsList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import React from 'react';
import { ThemeProvider } from '@mui/material/styles';
import { render } from '@testing-library/react';
import TestRouter from '__tests__/util/TestRouter';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { AppealsWrapper } from 'pages/accountLists/[accountListId]/tools/appeals/AppealsWrapper';
import theme from 'src/theme';
import { AppealQuery } from '../../AppealDetails/AppealsMainPanel/AppealInfo.generated';
import {
AppealStatusEnum,
AppealsContext,
AppealsType,
} from '../../AppealsContext/AppealsContext';
import { appealInfo } from '../../appealMockData';
import { ContactsList } from './ContactsList';

const accountListId = 'account-list-1';
const appealId = 'appealId';

const router = {
query: { accountListId },
isReady: true,
};

const setContactFocus = jest.fn();
const contactDetailsOpen = true;
const toggleSelectionById = jest.fn();
const isRowChecked = jest.fn();

const defaultAppealQuery: AppealQuery = {
appeal: {
...appealInfo,
},
};
const defaultContactsQueryResult = {
data: { contacts: { nodes: [] } },
loading: false,
};
type ComponentsProps = {
appealInfoLoading?: boolean;
tour?: boolean;
appealStatus?: AppealStatusEnum;
contactsQueryResult?: object;
};
const Components = ({
appealInfoLoading = false,
tour = false,
appealStatus = AppealStatusEnum.Asked,
contactsQueryResult = defaultContactsQueryResult,
}: ComponentsProps) => (
<TestRouter router={router}>
<GqlMockedProvider>
<ThemeProvider theme={theme}>
<AppealsWrapper>
<AppealsContext.Provider
value={
{
appealId,
accountListId,
tour,
isFiltered: true,
searchTerm: '',
setActiveFilters: jest.fn(),
activeFilters: {
appealStatus,
},
contactsQueryResult,
setContactFocus,
isRowChecked,
contactDetailsOpen,
toggleSelectionById,
} as unknown as AppealsType
}
>
<ContactsList
appealInfo={defaultAppealQuery}
appealInfoLoading={appealInfoLoading}
/>
</AppealsContext.Provider>
</AppealsWrapper>
</ThemeProvider>
</GqlMockedProvider>
</TestRouter>
);

describe('ContactsRow', () => {
describe('NullState Message', () => {
it('shows no contacts on Given', () => {
const { getByText } = render(
<Components appealStatus={AppealStatusEnum.Processed} />,
);

expect(
getByText('No donations yet towards this appeal'),
).toBeInTheDocument();
});

it('shows no contacts on Excluded', () => {
const { getByText } = render(
<Components appealStatus={AppealStatusEnum.Excluded} />,
);

expect(
getByText('No contacts have been excluded from this appeal'),
).toBeInTheDocument();
});

it('shows no contacts on Asked', () => {
const { getByText } = render(<Components />);

expect(
getByText('All contacts for this appeal have committed to this appeal'),
).toBeInTheDocument();
});

it('shows no contacts on Committed', () => {
const { getByText } = render(
<Components appealStatus={AppealStatusEnum.NotReceived} />,
);

expect(
getByText(
'There are no contacts for this appeal that have not been received.',
),
).toBeInTheDocument();
});

it('shows no contacts on Received', () => {
const { getByText } = render(
<Components appealStatus={AppealStatusEnum.ReceivedNotProcessed} />,
);

expect(
getByText(
'No gifts have been received and not yet processed to this appeal',
),
).toBeInTheDocument();
});
});

describe('Layout', () => {
it('Given', async () => {
const { queryByText } = render(
<Components appealStatus={AppealStatusEnum.Processed} />,
);
expect(await queryByText('Reason')).not.toBeInTheDocument();
});

it('Excluded', async () => {
const { findByText } = render(
<Components appealStatus={AppealStatusEnum.Excluded} />,
);
expect(await findByText('Reason')).toBeInTheDocument();
});

it('Asked', async () => {
const { queryByText } = render(<Components />);
expect(await queryByText('Reason')).not.toBeInTheDocument();
});

it('Committed', async () => {
const { queryByText } = render(
<Components appealStatus={AppealStatusEnum.NotReceived} />,
);
expect(await queryByText('Reason')).not.toBeInTheDocument();
});

it('Received', async () => {
const { queryByText } = render(
<Components appealStatus={AppealStatusEnum.ReceivedNotProcessed} />,
);
expect(await queryByText('Reason')).not.toBeInTheDocument();
});
});
});
55 changes: 55 additions & 0 deletions src/utils/functions/getLocalizedExcludedFromAppealReasons.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ExcludedAppealContactReasonEnum } from 'src/graphql/types.generated';
import { getLocalizedExcludedFromAppealReasons } from './getLocalizedExcludedFromAppealReasons';

const t = jest.fn().mockImplementation((message) => message);

describe('getRouterQueryParam', () => {
it('IncreasedRecently', () => {
expect(
getLocalizedExcludedFromAppealReasons(
t,
ExcludedAppealContactReasonEnum.IncreasedRecently,
),
).toEqual('Increased Recently');
});
it('JoinedRecently', () => {
expect(
getLocalizedExcludedFromAppealReasons(
t,
ExcludedAppealContactReasonEnum.JoinedRecently,
),
).toEqual('Joined Recently');
});
it('MarkedDoNotAsk', () => {
expect(
getLocalizedExcludedFromAppealReasons(
t,
ExcludedAppealContactReasonEnum.MarkedDoNotAsk,
),
).toEqual('Marked Do Not Ask');
});
it('PledgeAmountIncreasedRange', () => {
expect(
getLocalizedExcludedFromAppealReasons(
t,
ExcludedAppealContactReasonEnum.PledgeAmountIncreasedRange,
),
).toEqual('May have increased their giving in the last 3 months');
});
it('PledgeLateBy', () => {
expect(
getLocalizedExcludedFromAppealReasons(
t,
ExcludedAppealContactReasonEnum.PledgeLateBy,
),
).toEqual('May have missed a gift in the last 30-90 days');
});
it('StartedGivingRange', () => {
expect(
getLocalizedExcludedFromAppealReasons(
t,
ExcludedAppealContactReasonEnum.StartedGivingRange,
),
).toEqual('May have joined my team in the last 3 months');
});
});

0 comments on commit b8338d3

Please sign in to comment.