Skip to content

Commit

Permalink
test: add tests for error when renaming a saved visualization (DHIS2-…
Browse files Browse the repository at this point in the history
…16154) (#455)
  • Loading branch information
edoardo committed Jan 4, 2024
1 parent d9904f0 commit 367f00a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
20 changes: 19 additions & 1 deletion cypress/helpers/fileMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clearInput, typeInput } from './common.js'
import { clearInput, typeInput, clearTextarea, typeTextarea } from './common.js'

export const ITEM_NEW = 'file-menu-new'
export const ITEM_OPEN = 'file-menu-open'
Expand Down Expand Up @@ -50,3 +50,21 @@ export const deleteVisualization = () => {

cy.getBySel('titlebar').should('not.exist')
}

export const renameVisualization = (name, description) => {
cy.getBySel('dhis2-analytics-hovermenubar').contains('File').click()

cy.getBySel(ITEM_RENAME).click()

if (name) {
clearInput('file-menu-rename-modal-name-content')
typeInput('file-menu-rename-modal-name-content', name)
}

if (description) {
clearTextarea('file-menu-rename-modal-description-content')
typeTextarea('file-menu-rename-modal-description-content', description)
}

cy.getBySel('file-menu-rename-modal-rename').click()
}
72 changes: 71 additions & 1 deletion cypress/integration/save.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ import {
} from '../helpers/dimensions.js'
import {
deleteVisualization,
renameVisualization,
resaveVisualization,
saveVisualization,
saveVisualizationAs,
} from '../helpers/fileMenu.js'
import { clickMenubarUpdateButton } from '../helpers/menubar.js'
import {
clickMenubarUpdateButton,
clickMenubarInterpretationsButton,
} from '../helpers/menubar.js'
import { selectFixedPeriod, selectRelativePeriod } from '../helpers/period.js'
import { goToStartPage } from '../helpers/startScreen.js'
import {
Expand Down Expand Up @@ -48,6 +52,72 @@ const setupTable = () => {
expectTableToBeVisible()
}

describe('rename', () => {
it('replace existing name works correctly', () => {
const AO_NAME = `TEST RENAME ${new Date().toLocaleString()}`
const UPDATED_AO_NAME = AO_NAME + ' 2'
setupTable()

// save
saveVisualization(AO_NAME)
expectAOTitleToContain(AO_NAME)
expectTableToBeVisible()

cy.intercept('PATCH', '**/api/*/eventVisualizations/*').as(
'patch-rename'
)

// rename the AO, changing name only
renameVisualization(UPDATED_AO_NAME)

cy.wait('@patch-rename')

expectTableToBeVisible()
expectAOTitleToContain(AO_NAME)

cy.reload(true)

expectTableToBeVisible()
expectAOTitleToContain(UPDATED_AO_NAME)

deleteVisualization()
})

it('add non existing description works correctly', () => {
const AO_NAME = `TEST RENAME ${new Date().toLocaleString()}`
const AO_DESC = 'with description'
const AO_DESC_UPDATED = AO_DESC + ' edited'
setupTable()

// save
saveVisualization(AO_NAME)
expectAOTitleToContain(AO_NAME)
expectTableToBeVisible()

// rename the AO, adding a description
renameVisualization(AO_NAME, AO_DESC)

clickMenubarInterpretationsButton()
cy.getBySel('details-panel').should('be.visible')
cy.getBySel('details-panel').contains(AO_DESC)
clickMenubarInterpretationsButton()

expectTableToBeVisible()

// rename the AO, replacing the description
renameVisualization(AO_NAME, AO_DESC_UPDATED)

clickMenubarInterpretationsButton()
cy.getBySel('details-panel').should('be.visible')
cy.getBySel('details-panel').contains(AO_DESC_UPDATED)
clickMenubarInterpretationsButton()

expectTableToBeVisible()

deleteVisualization()
})
})

describe('save', () => {
it('new AO with name saves correctly', () => {
const AO_NAME = `TEST ${new Date().toLocaleString()}`
Expand Down

0 comments on commit 367f00a

Please sign in to comment.