Skip to content

Commit

Permalink
Merge branch 'dev' into fix/DHIS2-15000-oug-shortname
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott authored May 10, 2024
2 parents bf0ba26 + b1b6148 commit 0703afa
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 16 deletions.
3 changes: 3 additions & 0 deletions cypress/elements/pivotTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const valueCellEl = 'visualization-value-cell'
const headerCellEl = 'visualization-column-header'

export const expectTableToBeVisible = () =>
cy.get('.pivot-table-container').should('have.length', 1).and('be.visible')

export const clickTableValueCell = (index) =>
cy.getBySel(valueCellEl).eq(index).click()

Expand Down
82 changes: 82 additions & 0 deletions cypress/integration/options/totals.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
AXIS_ID_COLUMNS,
AXIS_ID_ROWS,
DIMENSION_ID_DATA,
DIMENSION_ID_PERIOD,
VIS_TYPE_PIVOT_TABLE,
visTypeDisplayNames,
} from '@dhis2/analytics'
import { checkCheckbox } from '../../elements/common.js'
import {
clickDimensionModalHideButton,
clickDimensionModalUpdateButton,
expectDimensionModalToBeVisible,
selectAllItemsByButton,
selectDataElements,
selectFixedPeriods,
unselectAllItemsByButton,
} from '../../elements/dimensionModal/index.js'
import {
clickContextMenuAdd,
openContextMenu as openDimPanelContextMenu,
openDimension,
} from '../../elements/dimensionsPanel.js'
import { clickContextMenuMove, openContextMenu } from '../../elements/layout.js'
import { openOptionsModal } from '../../elements/menuBar.js'
import {
OPTIONS_TAB_DATA,
clickOptionsModalHideButton,
} from '../../elements/optionsModal/index.js'
import {
colTotalsOptionEl,
expectColumnsTotalsToBeChecked,
} from '../../elements/optionsModal/totals.js'
import { expectTableToBeVisible } from '../../elements/pivotTable.js'
import { goToStartPage } from '../../elements/startScreen.js'
import { changeVisType } from '../../elements/visualizationTypeSelector.js'
import { TEST_CUSTOM_DIMENSIONS } from '../../utils/data.js'

const AREA_DIMENSION = TEST_CUSTOM_DIMENSIONS.find((dim) => dim.name === 'Area')

describe('Options - Column totals', () => {
describe('Regression test for DHIS2-17297', () => {
it('does not crash', () => {
goToStartPage()
changeVisType(visTypeDisplayNames[VIS_TYPE_PIVOT_TABLE])

openOptionsModal(OPTIONS_TAB_DATA)
checkCheckbox(colTotalsOptionEl)

expectColumnsTotalsToBeChecked()

clickOptionsModalHideButton()

openContextMenu(DIMENSION_ID_DATA)
clickContextMenuMove(DIMENSION_ID_DATA, AXIS_ID_ROWS)
openContextMenu(DIMENSION_ID_PERIOD)
clickContextMenuMove(DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS)

openDimension(DIMENSION_ID_DATA)
selectDataElements(['ART enrollment stage 1'])
clickDimensionModalHideButton()

const year = new Date().getFullYear().toString()
openDimension(DIMENSION_ID_PERIOD)
unselectAllItemsByButton()
selectFixedPeriods(
[`May ${year}`, `June ${year}`, `July ${year}`],
'Monthly'
)
clickDimensionModalHideButton()

openDimPanelContextMenu(AREA_DIMENSION.id)
clickContextMenuAdd(AREA_DIMENSION.id, AXIS_ID_ROWS)
expectDimensionModalToBeVisible(AREA_DIMENSION.id)
selectAllItemsByButton()

clickDimensionModalUpdateButton()

expectTableToBeVisible()
})
})
})
31 changes: 15 additions & 16 deletions src/components/VisualizationPlugin/VisualizationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const VisualizationPlugin = ({
onDrill,
}) => {
const engine = useDataEngine()
const [visualization, setVisualization] = useState(undefined)
const [visualization, setVisualization] = useState(null)
const [ouLevels, setOuLevels] = useState(undefined)
const [fetchResult, setFetchResult] = useState(null)
const [contextualMenuRef, setContextualMenuRef] = useState(undefined)
Expand Down Expand Up @@ -173,6 +173,7 @@ export const VisualizationPlugin = ({

useEffect(() => {
setFetchResult(null)
setVisualization(null)

// filter out disabled options
const disabledOptions = getDisabledOptions({
Expand All @@ -186,8 +187,6 @@ export const VisualizationPlugin = ({
(option) => delete filteredVisualization[option]
)

setVisualization(filteredVisualization)

const doFetchAll = async () => {
const { responses, extraOptions } = await doFetchData(
filteredVisualization,
Expand Down Expand Up @@ -254,6 +253,7 @@ export const VisualizationPlugin = ({
extraOptions,
})
setShowLegendKey(filteredVisualization.legend?.showKey)

onLoadingComplete()
}

Expand All @@ -264,7 +264,15 @@ export const VisualizationPlugin = ({
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [originalVisualization, filters, forDashboard])

if (!fetchResult || !ouLevels) {
useEffect(() => {
if (fetchResult?.visualization && ouLevels) {
setVisualization(
convertOuLevelsToUids(ouLevels, fetchResult.visualization)
)
}
}, [fetchResult?.visualization, ouLevels])

if (!fetchResult || !visualization || !ouLevels) {
return null
}

Expand Down Expand Up @@ -406,10 +414,7 @@ export const VisualizationPlugin = ({
) {
return (
<PivotPlugin
visualization={convertOuLevelsToUids(
ouLevels,
fetchResult.visualization
)}
visualization={visualization}
responses={fetchResult.responses}
legendSets={legendSets}
onToggleContextualMenu={
Expand All @@ -422,10 +427,7 @@ export const VisualizationPlugin = ({
} else if (fetchResult.visualization.type === VIS_TYPE_OUTLIER_TABLE) {
return (
<OutlierTablePlugin
visualization={convertOuLevelsToUids(
ouLevels,
fetchResult.visualization
)}
visualization={visualization}
responses={fetchResult.responses}
filters={filters}
id={id}
Expand All @@ -436,10 +438,7 @@ export const VisualizationPlugin = ({
} else {
return (
<ChartPlugin
visualization={convertOuLevelsToUids(
ouLevels,
fetchResult.visualization
)}
visualization={visualization}
responses={fetchResult.responses}
extraOptions={fetchResult.extraOptions}
legendSets={legendSets}
Expand Down

0 comments on commit 0703afa

Please sign in to comment.