Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cypress/elements/visualizationTypeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const changeVisType = (visTypeName) => {
cy.getBySel(vstCardEl).contains(visTypeName).click()
}

export const clickOpenAsMap = () => {
clickVisTypeSelector()
cy.getBySel(vstCardEl).contains('Open as Map').click()
}

export const expectVisTypeToBeValue = (value) =>
cy
.getBySel(vstButtonTextEl)
Expand Down
48 changes: 48 additions & 0 deletions cypress/integration/openAsMap.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
expectAOTitleToBeValue,
expectVisualizationToBeVisible,
} from '../elements/chart.js'
import { openAOByName } from '../elements/fileMenu/open.js'
import { goToStartPage } from '../elements/startScreen.js'
import { clickOpenAsMap } from '../elements/visualizationTypeSelector.js'

/* Duplicated from src instead of imported: importing app source pulls the
* React component and its CSS module into the Cypress browserify bundle,
* which cannot parse them */
const MAPS_APP_URL = 'dhis-web-maps'
const USER_DATASTORE_CURRENT_AO_KEY = 'currentAnalyticalObject'

describe('open as map', () => {
it('opens Maps in a new tab instead of navigating away', () => {
const pivotTableName = 'ANC: ANC 1 Visits Cumulative Numbers'

/* Stub window.open so Cypress does not actually navigate to the
* Maps app in a new tab */
const windowOpenStub = cy.stub().as('open')
cy.on('window:before:load', (win) => {
cy.stub(win, 'open').callsFake(windowOpenStub)
})

goToStartPage()
openAOByName(pivotTableName)
expectAOTitleToBeValue(pivotTableName)
expectVisualizationToBeVisible('PIVOT_TABLE')

clickOpenAsMap()

cy.get('@open').should('have.been.calledOnce')
cy.get('@open').should((stub) => {
const url = stub.getCall(0).args[0]
const target = stub.getCall(0).args[1]
const features = stub.getCall(0).args[2]

expect(url).to.satisfy((url) =>
url.endsWith(
`/${MAPS_APP_URL}/#/${USER_DATASTORE_CURRENT_AO_KEY}`
)
)
expect(target).to.equal('_blank')
expect(features).to.equal('noopener')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ const UnconnectedVisualizationTypeSelector = ({
ui
)

set(currentAnalyticalObject)
await set(currentAnalyticalObject)

window.location.href = `${baseUrl}/${MAPS_APP_URL}/#/${USER_DATASTORE_CURRENT_AO_KEY}`
window.open(
`${baseUrl}/${MAPS_APP_URL}/#/${USER_DATASTORE_CURRENT_AO_KEY}`,
'_blank',
'noopener'
)
}

const VisTypesList = (
Expand Down
Loading