Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for error when renaming a saved visualization (DHIS2-16154) #455

Merged
merged 8 commits into from
Dec 8, 2023
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 @@ -14,11 +14,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 All @@ -41,6 +45,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
Loading