From 367f00ad66f94bb2559f02b40c3e4807b9dab567 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Fri, 8 Dec 2023 10:41:25 +0100 Subject: [PATCH] test: add tests for error when renaming a saved visualization (DHIS2-16154) (#455) --- cypress/helpers/fileMenu.js | 20 +++++++++- cypress/integration/save.cy.js | 72 +++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/cypress/helpers/fileMenu.js b/cypress/helpers/fileMenu.js index c91f08d1f..eb68ea0c3 100644 --- a/cypress/helpers/fileMenu.js +++ b/cypress/helpers/fileMenu.js @@ -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' @@ -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() +} diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 2f9a3e23f..4a1d2c55d 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -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 { @@ -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()}`