diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 31aa417857..44161302ab 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -1,5 +1,6 @@ import { DIMENSION_ID_DATA, + DIMENSION_ID_ORGUNIT, visTypeDisplayNames, VIS_TYPE_SCATTER, } from '@dhis2/analytics' @@ -16,10 +17,10 @@ import { selectIndicators, selectDataElements, clickDimensionModalUpdateButton, + deselectOrgUnitTreeItem, } from '../elements/dimensionModal/index.js' import { openDimension } from '../elements/dimensionsPanel.js' import { - //openRandomAOCreatedByOthers, saveNewAO, closeFileMenuWithClick, saveAOAs, @@ -184,21 +185,36 @@ describe('saving an AO', () => { }) }) - /* - describe('"save" for a saved AO created by others', () => { - it('navigates to the start page', () => { + describe('"save" a copied AO created by others', () => { + it('works after editing', () => { + const TEST_VIS_BY_OTHERS_NAME = 'ANC: 1-3 dropout rate Yearly' + const TEST_VIS_BY_OTHERS_NAME_UPDATED = `${TEST_VIS_BY_OTHERS_NAME} - updated` + + // navigates to the start page and opens an AO created by others goToStartPage() - }) - it('opens a random AO created by others', () => { - openRandomAOCreatedByOthers() - }) - it('checks that Save is disabled - WIP', () => { - clickMenuBarFileButton() - expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVEAS) - // TODO: This is not always true, as different AOs can have different sharing settings. - // @edoardo will add additional tests here later - closeFileMenuWithClick() + openAOByName(TEST_VIS_BY_OTHERS_NAME) + expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME) + + // saves AO using "Save As" + saveAOAs(TEST_VIS_BY_OTHERS_NAME_UPDATED) + expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME_UPDATED) + expectVisualizationToBeVisible() + + // edits the AO + openDimension(DIMENSION_ID_ORGUNIT) + deselectOrgUnitTreeItem('Western Area') + clickDimensionModalUpdateButton() + + // saves AO using "Save" + saveExistingAO() + expectAOTitleToNotBeDirty() + expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME_UPDATED) + expectVisualizationToBeVisible() + + // deletes AO + deleteAO() + expectRouteToBeEmpty() + expectStartScreenToBeVisible() }) }) - */ }) diff --git a/src/actions/index.js b/src/actions/index.js index 0f0651ed9c..6e525c9d0e 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -6,6 +6,7 @@ import { DIMENSION_ID_PERIOD, DIMENSION_ID_ORGUNIT, DIMENSION_ID_ASSIGNED_CATEGORIES, + preparePayloadForSaveAs, } from '@dhis2/analytics' import i18n from '@dhis2/d2-i18n' import { apiPostDataStatistics } from '../api/dataStatistics.js' @@ -204,13 +205,13 @@ export const tDoSaveVisualization = try { dispatch(fromLoader.acSetPluginLoading(true)) - const visualization = getVisualizationFromCurrent( + let visualization = getVisualizationFromCurrent( sGetCurrent(getState()) ) // remove the id to trigger a POST request and save a new AO if (copy) { - delete visualization.id + visualization = preparePayloadForSaveAs(visualization) } visualization.name =