-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemindersTable.test.tsx
More file actions
128 lines (112 loc) · 4.4 KB
/
RemindersTable.test.tsx
File metadata and controls
128 lines (112 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { ThemeProvider } from '@mui/material/styles';
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { render, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Formik } from 'formik';
import { VirtuosoMockContext } from 'react-virtuoso';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import theme from 'src/theme';
import { mockData } from '../mockData';
import { RemindersTable, RowValues } from './RemindersTable';
const onSubmit = jest.fn();
const mutationSpy = jest.fn();
const initialValues: RowValues = {
status: Object.fromEntries(mockData.map((row) => [row.id, row.status])),
};
const TestComponent: React.FC = () => (
<ThemeProvider theme={theme}>
<VirtuosoMockContext.Provider
value={{ viewportHeight: 300, itemHeight: 100 }}
>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<GqlMockedProvider onCall={mutationSpy}>
<Formik<RowValues> initialValues={initialValues} onSubmit={onSubmit}>
<RemindersTable data={mockData} />
</Formik>
</GqlMockedProvider>
</LocalizationProvider>
</VirtuosoMockContext.Provider>
</ThemeProvider>
);
describe('RemindersTable', () => {
it('should render with the correct data', async () => {
const { findByRole, getByRole, getAllByRole } = render(<TestComponent />);
expect(
getByRole('columnheader', { name: 'Ministry Partner' }),
).toBeInTheDocument();
expect(
getByRole('columnheader', { name: 'Last Gift' }),
).toBeInTheDocument();
expect(
getByRole('columnheader', { name: 'Last Reminder' }),
).toBeInTheDocument();
expect(
getByRole('columnheader', { name: 'Reminder Status' }),
).toBeInTheDocument();
const cells = within(await findByRole('table')).getAllByRole('cell');
const partner = cells.find((cell) =>
within(cell).queryByText(
'Adamson, Eugene Michael (Mike) and Marilyn Jean',
),
);
expect(partner).toBeTruthy();
const date = cells.find((cell) => within(cell).queryByText('Aug 13, 2025'));
expect(date).toBeTruthy();
const select = getAllByRole('combobox', { name: /reminder status/i });
expect(select[0]).toHaveTextContent('Not Yet Enrolled');
});
it('should change the select value', async () => {
const { getAllByRole, getByRole } = render(<TestComponent />);
const select = getAllByRole('combobox', { name: /reminder status/i });
expect(select[0]).toHaveTextContent('Not Yet Enrolled');
await userEvent.click(select[0]);
const option = getByRole('option', { name: 'Monthly' });
expect(option).toBeInTheDocument();
await userEvent.click(option);
expect(select[0]).toHaveTextContent('Monthly');
});
it('should render empty table message when no data available', () => {
const { getByText } = render(
<ThemeProvider theme={theme}>
<VirtuosoMockContext.Provider
value={{ viewportHeight: 300, itemHeight: 100 }}
>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<GqlMockedProvider onCall={mutationSpy}>
<RemindersTable data={[]} />
</GqlMockedProvider>
</LocalizationProvider>
</VirtuosoMockContext.Provider>
</ThemeProvider>,
);
expect(getByText('No ministry partners found')).toBeInTheDocument();
expect(
getByText('Add a ministry partner to get started'),
).toBeInTheDocument();
});
it('should render no designation account message when designation error is present', () => {
const { getByText } = render(
<ThemeProvider theme={theme}>
<VirtuosoMockContext.Provider
value={{ viewportHeight: 300, itemHeight: 100 }}
>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<GqlMockedProvider onCall={mutationSpy}>
<RemindersTable
data={[]}
error={{ message: 'Designation account not found', name: '' }}
/>
</GqlMockedProvider>
</LocalizationProvider>
</VirtuosoMockContext.Provider>
</ThemeProvider>,
);
expect(getByText('No designation account found')).toBeInTheDocument();
expect(
getByText(
'This account is not associated with a designation account number',
),
).toBeInTheDocument();
});
});