Improved VisitsTable test

This commit is contained in:
Alejandro Celaya 2021-03-28 16:06:37 +02:00
parent eabd7d9ecb
commit 859cd9e5e3
2 changed files with 16 additions and 2 deletions

View file

@ -150,7 +150,7 @@ const VisitsTable = ({
</tr>
</thead>
<tbody>
{(!resultSet.visitsGroups[page - 1] || resultSet.visitsGroups[page - 1].length === 0) && (
{!resultSet.visitsGroups[page - 1]?.length && (
<tr>
<td colSpan={isOrphanVisits ? 8 : 7} className="text-center">
No visits found with current filtering

View file

@ -10,13 +10,14 @@ describe('<VisitsTable />', () => {
const matchMedia = () => Mock.of<MediaQueryList>({ matches: false });
const setSelectedVisits = jest.fn();
let wrapper: ShallowWrapper;
const createWrapper = (visits: NormalizedVisit[], selectedVisits: NormalizedVisit[] = []) => {
const createWrapper = (visits: NormalizedVisit[], selectedVisits: NormalizedVisit[] = [], isOrphanVisits = false) => {
wrapper = shallow(
<VisitsTable
visits={visits}
selectedVisits={selectedVisits}
setSelectedVisits={setSelectedVisits}
matchMedia={matchMedia}
isOrphanVisits={isOrphanVisits}
/>,
);
@ -134,4 +135,17 @@ describe('<VisitsTable />', () => {
searchField.simulate('change', '');
expect(wrapper.find('tbody').find('tr')).toHaveLength(7 + 2);
});
it.each([
[ true, 8 ],
[ false, 7 ],
])('displays proper amount of columns for orphan and non-orphan visits', (isOrphanVisits, expectedCols) => {
const wrapper = createWrapper([], [], isOrphanVisits);
const rowsWithColspan = wrapper.find('[colSpan]');
const cols = wrapper.find('th');
expect(cols).toHaveLength(expectedCols);
expect(rowsWithColspan).toHaveLength(2);
rowsWithColspan.forEach((row) => expect(row.prop('colSpan')).toEqual(expectedCols));
});
});