From 859cd9e5e3fb55bd133df68edbb843d402ce870c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 28 Mar 2021 16:06:37 +0200 Subject: [PATCH] Improved VisitsTable test --- src/visits/VisitsTable.tsx | 2 +- test/visits/VisitsTable.test.tsx | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/visits/VisitsTable.tsx b/src/visits/VisitsTable.tsx index 0e7bcb71..e5bcd849 100644 --- a/src/visits/VisitsTable.tsx +++ b/src/visits/VisitsTable.tsx @@ -150,7 +150,7 @@ const VisitsTable = ({ - {(!resultSet.visitsGroups[page - 1] || resultSet.visitsGroups[page - 1].length === 0) && ( + {!resultSet.visitsGroups[page - 1]?.length && ( No visits found with current filtering diff --git a/test/visits/VisitsTable.test.tsx b/test/visits/VisitsTable.test.tsx index a2d01c4a..393ab64d 100644 --- a/test/visits/VisitsTable.test.tsx +++ b/test/visits/VisitsTable.test.tsx @@ -10,13 +10,14 @@ describe('', () => { const matchMedia = () => Mock.of({ 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( , ); @@ -134,4 +135,17 @@ describe('', () => { 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)); + }); });