-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle sections without data elements [DHIS2-15883] (#359)
- Loading branch information
Showing
3 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/data-workspace/indicators-table-body/indicators-table-body.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { getAllByTestId, queryAllByTestId } from '@testing-library/react' | ||
import React from 'react' | ||
import { render } from '../../test-utils/index.js' | ||
import { FinalFormWrapper } from '../final-form-wrapper.js' | ||
import { IndicatorsTableBody } from './indicators-table-body.js' | ||
|
||
const tableIndicators = [ | ||
{ | ||
name: 'indieGator', | ||
displayFormName: "I'm an indicator!", | ||
decimals: 2, | ||
indicatorType: { | ||
factor: 1, | ||
}, | ||
numerator: '#{fakeUID1}', | ||
denominator: '#{fakeUID2}', | ||
id: 'indicator1', | ||
}, | ||
] | ||
|
||
describe('<IndicatorsTableBody />', () => { | ||
it('should not render padding cells if maxColumnsInSection=0', () => { | ||
const result = render( | ||
<IndicatorsTableBody | ||
indicators={tableIndicators} | ||
maxColumnsInSection={0} | ||
/>, | ||
{ | ||
wrapper: ({ children }) => ( | ||
<FinalFormWrapper dataValueSet={{}}> | ||
{children} | ||
</FinalFormWrapper> | ||
), | ||
} | ||
) | ||
|
||
const inputRows = result.getAllByTestId( | ||
'dhis2-dataentry-indicatorstablerow' | ||
) | ||
|
||
const cellsInFirstRow = queryAllByTestId( | ||
inputRows[0], | ||
'dhis2-dataentry-indicatorspaddingcell' | ||
) | ||
expect(cellsInFirstRow.length).toBe(0) | ||
}) | ||
|
||
it('should not render padding cells if maxColumnsInSection=-Infinity', () => { | ||
const result = render( | ||
<IndicatorsTableBody | ||
indicators={tableIndicators} | ||
maxColumnsInSection={-Infinity} | ||
/>, | ||
{ | ||
wrapper: ({ children }) => ( | ||
<FinalFormWrapper dataValueSet={{}}> | ||
{children} | ||
</FinalFormWrapper> | ||
), | ||
} | ||
) | ||
|
||
const inputRows = result.getAllByTestId( | ||
'dhis2-dataentry-indicatorstablerow' | ||
) | ||
expect(inputRows.length).toBe(1) | ||
|
||
const cellsInFirstRow = queryAllByTestId( | ||
inputRows[0], | ||
'dhis2-dataentry-indicatorspaddingcell' | ||
) | ||
expect(cellsInFirstRow.length).toBe(0) | ||
}) | ||
|
||
it('should render 3 padding cells if 1 indicator and maxColumnsInSection=4', () => { | ||
const result = render( | ||
<IndicatorsTableBody | ||
indicators={tableIndicators} | ||
maxColumnsInSection={4} | ||
/>, | ||
{ | ||
wrapper: ({ children }) => ( | ||
<FinalFormWrapper dataValueSet={{}}> | ||
{children} | ||
</FinalFormWrapper> | ||
), | ||
} | ||
) | ||
|
||
const inputRows = result.getAllByTestId( | ||
'dhis2-dataentry-indicatorstablerow' | ||
) | ||
|
||
const cellsInFirstRow = getAllByTestId( | ||
inputRows[0], | ||
'dhis2-dataentry-indicatorspaddingcell' | ||
) | ||
expect(cellsInFirstRow.length).toBe(3) | ||
}) | ||
|
||
it('should render 4 padding cells if 1 indicator, maxColumnsInSection=4, and row totals displayed', () => { | ||
const result = render( | ||
<IndicatorsTableBody | ||
indicators={tableIndicators} | ||
maxColumnsInSection={4} | ||
renderRowTotals={true} | ||
/>, | ||
{ | ||
wrapper: ({ children }) => ( | ||
<FinalFormWrapper dataValueSet={{}}> | ||
{children} | ||
</FinalFormWrapper> | ||
), | ||
} | ||
) | ||
|
||
const inputRows = result.getAllByTestId( | ||
'dhis2-dataentry-indicatorstablerow' | ||
) | ||
|
||
const cellsInFirstRow = getAllByTestId( | ||
inputRows[0], | ||
'dhis2-dataentry-indicatorspaddingcell' | ||
) | ||
expect(cellsInFirstRow.length).toBe(4) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83c062e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://dhis2-data-entry.netlify.app as production
🚀 Deployed on https://651ec777136f2c0bb1d7814d--dhis2-data-entry.netlify.app