Skip to content

Commit

Permalink
fix: sorting of layers by drag and drop was not working [DHIS2-16024] (
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen authored Nov 1, 2023
1 parent fc2ebd9 commit e006287
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
9 changes: 9 additions & 0 deletions cypress/elements/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export class Layer {
return this
}

selectOuLevel(level) {
cy.getByDataTest('org-unit-level-select').click()

cy.contains(level).click()
cy.get('body').click() // Close the modal menu

return this
}

typeStartDate(dateString) {
cy.get('label')
.contains('Start date')
Expand Down
59 changes: 59 additions & 0 deletions cypress/integration/layers/multilayers.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getMaps } from '../../elements/map_canvas.js'
import { OrgUnitLayer } from '../../elements/orgunit_layer.js'
import { ThematicLayer } from '../../elements/thematic_layer.js'

const INDICATOR_NAME = 'ANC 1 Coverage'

describe('Multiple Layers', () => {
beforeEach(() => {
cy.visit('/')
})

const TLayer = new ThematicLayer()
const OULayer = new OrgUnitLayer()

it('adds a thematic layer and an orgunit layer', () => {
TLayer.openDialog('Thematic')
.selectIndicatorGroup('ANC')
.selectIndicator(INDICATOR_NAME)
.selectTab('Period')
.selectPeriodType('Yearly')
.selectTab('Org Units')
.selectOu('Sierra Leone')
.selectOuLevel('District')
.addToMap()

TLayer.validateDialogClosed(true)

TLayer.validateCardTitle(INDICATOR_NAME)

getMaps().should('have.length', 1)

OULayer.openDialog('Org units')
.selectOu('Sierra Leone')
.selectOuLevel('District')
.addToMap()

OULayer.validateDialogClosed(true)

OULayer.validateCardTitle('Organisation units')
OULayer.validateCardItems(['District'])

cy.getByDataTest('sortable-layers-list')
.children()
.should('have.length', 2)

// confirm the order of the cards
cy.getByDataTest('sortable-layers-list')
.children()
.first()
.should('contain', 'Organisation units')

cy.getByDataTest('sortable-layers-list')
.children()
.last()
.should('contain', INDICATOR_NAME)

// TODO - add a test for drag/drop reordering of the layers
})
})
2 changes: 1 addition & 1 deletion cypress/plugins/excludeByVersionTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getExcludedTags = (v) => {

if (currentInstanceVersion < MIN_DHIS2_VERSION) {
throw new Error(
'Instance version is lower than the minimum supported version'
`Instance version ${v} is lower than the minimum supported version ${MIN_DHIS2_VERSION}`
)
}

Expand Down
1 change: 1 addition & 0 deletions src/components/layers/LayerCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const LayerCard = ({
className={cx(styles.card, {
[styles.expanded]: isExpanded,
})}
data-test={`card-${title.replace(/ /g, '')}`}
>
<Card dataTest={isOverlay ? 'layercard' : 'basemapcard'}>
<div className={styles.cardHeader}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/layers/LayersPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const SortableLayer = SortableElement(OverlayCard)

// Draggable layers - last layer on top
const SortableLayersList = SortableContainer(({ layers }) => (
<div>
<div data-test="sortable-layers-list">
{layers.map((layer, index) => (
<SortableLayer key={layer.id} index={index} layer={layer} />
))}
Expand All @@ -25,7 +25,8 @@ const LayersPanel = () => {

const dispatch = useDispatch()

const onSort = () => dispatch(sortLayers())
const onSort = ({ oldIndex, newIndex }) =>
dispatch(sortLayers({ oldIndex, newIndex }))

return (
<div
Expand Down

0 comments on commit e006287

Please sign in to comment.