From 00b2f60ce7371e5cc373491e85927b9789f991f7 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Mon, 6 Nov 2023 13:32:32 +0100 Subject: [PATCH 1/8] test: add helper function for FileMenu rename --- cypress/helpers/fileMenu.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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() +} From 8ec142a833fe2954616d80062b1c6de2e6500dbb Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Mon, 6 Nov 2023 13:32:58 +0100 Subject: [PATCH 2/8] test: add Cypress tests for rename --- cypress/integration/save.cy.js | 59 +++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 3f0e0abed..d703cd217 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -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 { @@ -41,6 +45,59 @@ 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() + + // rename the AO, changing name only + renameVisualization(UPDATED_AO_NAME) + expectTableToBeVisible() + + 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()}` From f82abf1da4a2cee04645c2a519e4819b3c4a70b4 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Thu, 30 Nov 2023 10:14:07 +0100 Subject: [PATCH 3/8] test: add test on vis name after renaming --- cypress/integration/save.cy.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index d703cd217..953fa0217 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -58,7 +58,10 @@ describe('rename', () => { // rename the AO, changing name only renameVisualization(UPDATED_AO_NAME) - expectTableToBeVisible() + + cy.reload() + + expectAOTitleToContain(UPDATED_AO_NAME) deleteVisualization() }) From a129840a4f821511d42a2de584f0757744f74b16 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Thu, 30 Nov 2023 11:41:22 +0100 Subject: [PATCH 4/8] test: assert original name before reloading --- cypress/integration/save.cy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 953fa0217..53232630e 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -59,6 +59,8 @@ describe('rename', () => { // rename the AO, changing name only renameVisualization(UPDATED_AO_NAME) + expectAOTitleToContain(AO_NAME) + cy.reload() expectAOTitleToContain(UPDATED_AO_NAME) From fa8af79ffd561c53f4121cb83a6767035911daab Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Thu, 30 Nov 2023 11:43:03 +0100 Subject: [PATCH 5/8] test: expect table to be visible after renaming --- cypress/integration/save.cy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 53232630e..197649511 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -60,10 +60,12 @@ describe('rename', () => { renameVisualization(UPDATED_AO_NAME) expectAOTitleToContain(AO_NAME) + expectTableToBeVisible() cy.reload() expectAOTitleToContain(UPDATED_AO_NAME) + expectTableToBeVisible() deleteVisualization() }) From d50d12162af1a1fc1f5b8b3e64b71f61dddb448e Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Thu, 30 Nov 2023 13:57:23 +0100 Subject: [PATCH 6/8] test: expect table before title is updated --- cypress/integration/save.cy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 197649511..154935a46 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -59,13 +59,13 @@ describe('rename', () => { // rename the AO, changing name only renameVisualization(UPDATED_AO_NAME) - expectAOTitleToContain(AO_NAME) expectTableToBeVisible() + expectAOTitleToContain(AO_NAME) cy.reload() - expectAOTitleToContain(UPDATED_AO_NAME) expectTableToBeVisible() + expectAOTitleToContain(UPDATED_AO_NAME) deleteVisualization() }) From 5a5f0b188da292019f85739825edade0578cdc39 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Thu, 30 Nov 2023 13:59:17 +0100 Subject: [PATCH 7/8] test: disable cache when reloading --- cypress/integration/save.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 154935a46..ab3b7081d 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -62,7 +62,7 @@ describe('rename', () => { expectTableToBeVisible() expectAOTitleToContain(AO_NAME) - cy.reload() + cy.reload(true) expectTableToBeVisible() expectAOTitleToContain(UPDATED_AO_NAME) From 086e52a8e3902652f5e8b56c9f358761fd62c579 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Thu, 30 Nov 2023 16:03:26 +0100 Subject: [PATCH 8/8] test: attempt to fix test by waiting for PATCH to complete --- cypress/integration/save.cy.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index ab3b7081d..d60f3e57e 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -56,9 +56,15 @@ describe('rename', () => { 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)