diff --git a/cypress/integration/confirmLeave.cy.js b/cypress/integration/confirmLeave.cy.js index 0f49e9ff03..f2e136c34f 100644 --- a/cypress/integration/confirmLeave.cy.js +++ b/cypress/integration/confirmLeave.cy.js @@ -17,34 +17,34 @@ import { import { TEST_AOS } from '../utils/data.js' import { getRandomArrayItem } from '../utils/random.js' -describe('confirm leave modal', () => { - const TEST_AO = getRandomArrayItem(TEST_AOS) - - it('navigates to the start page and loads a random saved AO', () => { +describe('Confirm leave modal', () => { + it('Confirm leave modal preserves AO changes when user cancels leave, and discards changes when user approves leave', () => { + const TEST_AO = getRandomArrayItem(TEST_AOS) + // navigates to the start page and loads a random saved AO goToStartPage() openAOByName(TEST_AO.name) expectVisualizationToBeVisible(TEST_AO.type) expectAOTitleToNotBeDirty() - }) - it(`replaces the selected period`, () => { + + // replaces the selected period replacePeriodItems(TEST_AO.type) expectVisualizationToBeVisible(TEST_AO.type) expectAOTitleToBeDirty() - }) - it('tries to open a new AO', () => { + + // tries to open a new AO createNewAO() expectConfirmLeaveModalToBeVisible() - }) - it('cancels leave', () => { + + // cancels leave confirmLeave(false) expectVisualizationToBeVisible(TEST_AO.type) expectAOTitleToBeDirty() - }) - it('tries to open a new AO', () => { + + // tries to open a new AO createNewAO() expectConfirmLeaveModalToBeVisible() - }) - it('confirms leave', () => { + + // confirms leave confirmLeave(true) expectStartScreenToBeVisible() expectVisualizationToNotBeVisible() diff --git a/cypress/integration/new.cy.js b/cypress/integration/new.cy.js index 33a979783d..5d2fcf2717 100644 --- a/cypress/integration/new.cy.js +++ b/cypress/integration/new.cy.js @@ -41,62 +41,61 @@ const TEST_INDICATOR_NAMES = TEST_INDICATORS.slice(1, 3).map( ) describe('creating a new AO', () => { - it('navigates to the start page', () => { - goToStartPage() - }) visTypes.forEach((visType) => { const visTypeName = visTypeDisplayNames[visType] - describe(visTypeName, () => { - it('creates a new AO', () => { - createNewAO() - expectStoreCurrentToBeEmpty() - expectVisualizationToNotBeVisible() - expectVisTypeToBeDefault() - }) - it('changes vis type', () => { - changeVisType(visTypeName) - expectVisTypeToBeValue(visTypeName) - }) - it('adds dimensions', () => { - openDimension(DIMENSION_ID_DATA) - if (visType === VIS_TYPE_SCATTER) { - selectIndicators(TEST_INDICATOR_NAMES.slice(0, 1)) - switchDataTab('Horizontal') - selectDataElements(TEST_DATA_ELEMENT_NAMES.slice(0, 1)) - } else { - if (getAxisMaxNumberOfItems(visType, TEST_AXIS_ID) === 1) { - // Gauge and SV can only have 1 data item - TEST_DATA_ELEMENT_NAMES.splice(1) - } + it(`create AO of type ${visTypeName}`, () => { + // navigates to start page + goToStartPage() + + // creates a new AO + createNewAO() + expectStoreCurrentToBeEmpty() + expectVisualizationToNotBeVisible() + expectVisTypeToBeDefault() + + // changes vis type + changeVisType(visTypeName) + expectVisTypeToBeValue(visTypeName) - selectDataElements(TEST_DATA_ELEMENT_NAMES) + // adds dimensions + openDimension(DIMENSION_ID_DATA) + + if (visType === VIS_TYPE_SCATTER) { + selectIndicators(TEST_INDICATOR_NAMES.slice(0, 1)) + switchDataTab('Horizontal') + selectDataElements(TEST_DATA_ELEMENT_NAMES.slice(0, 1)) + } else { + if (getAxisMaxNumberOfItems(visType, TEST_AXIS_ID) === 1) { + // Gauge and SV can only have 1 data item + TEST_DATA_ELEMENT_NAMES.splice(1) } - clickDimensionModalUpdateButton() + selectDataElements(TEST_DATA_ELEMENT_NAMES) + } - expectVisualizationToBeVisible(visType) + clickDimensionModalUpdateButton() - isYearOverYear(visType) && expectAOTitleToBeUnsaved() + expectVisualizationToBeVisible(visType) - // FIXME: Store is always in default state - /* !isYearOverYear(visType) + isYearOverYear(visType) && expectAOTitleToBeUnsaved() + + // FIXME: Store is always in default state + /* !isYearOverYear(visType) ? expectStoreCurrentColumnsToHaveLength(1) : expectAOTitleToBeUnsaved() */ - if (visType !== VIS_TYPE_SCATTER) { - TEST_DATA_ELEMENT_NAMES.forEach((item) => - expectChartToContainDimensionItem(visType, item) - ) - } - }) + if (visType !== VIS_TYPE_SCATTER) { + TEST_DATA_ELEMENT_NAMES.forEach((item) => + expectChartToContainDimensionItem(visType, item) + ) + } + if ([VIS_TYPE_SINGLE_VALUE, VIS_TYPE_GAUGE].includes(visType)) { - it('Data is locked to Series', () => { - expectDimensionOnAxisToHaveLockIcon( - DIMENSION_ID_DATA, - AXIS_ID_COLUMNS - ) - }) + expectDimensionOnAxisToHaveLockIcon( + DIMENSION_ID_DATA, + AXIS_ID_COLUMNS + ) } }) }) diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 44161302ab..70c983dd9a 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -61,160 +61,157 @@ const TEST_INDICATOR_NAMES = TEST_INDICATORS.slice(1, 4).map( // TODO: Add test to check that the description is saved and shown in the interpretations panel describe('saving an AO', () => { - describe('"save" and "save as" for a new AO', () => { - it('navigates to the start page', () => { - goToStartPage() - }) - it('checks that Save is disabled', () => { - clickMenuBarFileButton() - expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVE_EXISTING) - closeFileMenuWithClick() - }) - it(`changes vis type to ${TEST_VIS_TYPE_NAME}`, () => { - changeVisType(TEST_VIS_TYPE_NAME) - }) - it('adds Data dimension items', () => { - if (TEST_VIS_TYPE === VIS_TYPE_SCATTER) { - openDimension(DIMENSION_ID_DATA) - switchDataTab('Vertical') - selectIndicators([TEST_INDICATOR_NAMES[0]]) - clickDimensionModalUpdateButton() - openDimension(DIMENSION_ID_DATA) - switchDataTab('Horizontal') - selectIndicators([TEST_INDICATOR_NAMES[1]]) - clickDimensionModalUpdateButton() - } else { - openDimension(DIMENSION_ID_DATA) - selectDataElements( - TEST_DATA_ELEMENTS.slice(1, 2).map((item) => item.name) - ) - clickDimensionModalUpdateButton() - } - }) - it('displays an unsaved visualization', () => { - expectVisualizationToBeVisible(TEST_VIS_TYPE) - expectAOTitleToBeUnsaved() - expectRouteToBeEmpty() - }) - it('checks that Save is enabled', () => { - clickMenuBarFileButton() - expectFileMenuButtonToBeEnabled(FILE_MENU_BUTTON_SAVE_EXISTING) - closeFileMenuWithClick() - }) - it('checks that Save as is disabled', () => { - clickMenuBarFileButton() - expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVEAS) - closeFileMenuWithClick() - }) - it('saves new AO using "Save"', () => { - saveNewAO(TEST_VIS_NAME, TEST_VIS_DESCRIPTION) - expectAOTitleToBeValue(TEST_VIS_NAME) - expectVisualizationToBeVisible(TEST_VIS_TYPE) - }) - it('checks that the url was changed', () => { - expectRouteToBeAOId() - }) - it('all File menu buttons but Save are enabled', () => { - clickMenuBarFileButton() - const enabledButtons = [ - FILE_MENU_BUTTON_NEW, - FILE_MENU_BUTTON_OPEN, - FILE_MENU_BUTTON_SAVEAS, - FILE_MENU_BUTTON_RENAME, - FILE_MENU_BUTTON_TRANSLATE, - FILE_MENU_BUTTON_SHARE, - FILE_MENU_BUTTON_GETLINK, - FILE_MENU_BUTTON_DELETE, - ] - enabledButtons.forEach((button) => - expectFileMenuButtonToBeEnabled(button) + it('"save" and "save as" for a new AO', () => { + // navigates to the start page + goToStartPage() + + // checks that Save is disabled + clickMenuBarFileButton() + expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVE_EXISTING) + closeFileMenuWithClick() + + // changes vis type + cy.log(`changes vis type to ${TEST_VIS_TYPE_NAME}`) + changeVisType(TEST_VIS_TYPE_NAME) + + // adds Data dimension items + if (TEST_VIS_TYPE === VIS_TYPE_SCATTER) { + openDimension(DIMENSION_ID_DATA) + switchDataTab('Vertical') + selectIndicators([TEST_INDICATOR_NAMES[0]]) + clickDimensionModalUpdateButton() + openDimension(DIMENSION_ID_DATA) + switchDataTab('Horizontal') + selectIndicators([TEST_INDICATOR_NAMES[1]]) + clickDimensionModalUpdateButton() + } else { + openDimension(DIMENSION_ID_DATA) + selectDataElements( + TEST_DATA_ELEMENTS.slice(1, 2).map((item) => item.name) ) - closeFileMenuWithClick() - }) - it(`replaces the selected period`, () => { - replacePeriodItems(TEST_VIS_TYPE) - expectAOTitleToBeDirty() - expectVisualizationToBeVisible(TEST_VIS_TYPE) - }) - it('saves AO using "Save"', () => { - saveExistingAO() - expectAOTitleToNotBeDirty() - expectAOTitleToBeValue(TEST_VIS_NAME) - expectVisualizationToBeVisible(TEST_VIS_TYPE) - }) - it('saves AO using "Save As"', () => { - saveAOAs(TEST_VIS_NAME_UPDATED) - expectAOTitleToBeValue(TEST_VIS_NAME_UPDATED) - expectVisualizationToBeVisible(TEST_VIS_TYPE) - }) + clickDimensionModalUpdateButton() + } + + // displays an unsaved visualization + expectVisualizationToBeVisible(TEST_VIS_TYPE) + expectAOTitleToBeUnsaved() + expectRouteToBeEmpty() + + // checks that Save is enabled + clickMenuBarFileButton() + expectFileMenuButtonToBeEnabled(FILE_MENU_BUTTON_SAVE_EXISTING) + closeFileMenuWithClick() + + // checks that Save as is disabled + clickMenuBarFileButton() + expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVEAS) + closeFileMenuWithClick() + + // saves new AO using "Save" + saveNewAO(TEST_VIS_NAME, TEST_VIS_DESCRIPTION) + expectAOTitleToBeValue(TEST_VIS_NAME) + expectVisualizationToBeVisible(TEST_VIS_TYPE) + + // checks that the url was changed + expectRouteToBeAOId() + + // all File menu buttons but Save are enabled + clickMenuBarFileButton() + const enabledButtons = [ + FILE_MENU_BUTTON_NEW, + FILE_MENU_BUTTON_OPEN, + FILE_MENU_BUTTON_SAVEAS, + FILE_MENU_BUTTON_RENAME, + FILE_MENU_BUTTON_TRANSLATE, + FILE_MENU_BUTTON_SHARE, + FILE_MENU_BUTTON_GETLINK, + FILE_MENU_BUTTON_DELETE, + ] + enabledButtons.forEach((button) => + expectFileMenuButtonToBeEnabled(button) + ) + closeFileMenuWithClick() + + // replaces the selected period + replacePeriodItems(TEST_VIS_TYPE) + expectAOTitleToBeDirty() + expectVisualizationToBeVisible(TEST_VIS_TYPE) + + // saves AO using "Save" + saveExistingAO() + expectAOTitleToNotBeDirty() + expectAOTitleToBeValue(TEST_VIS_NAME) + expectVisualizationToBeVisible(TEST_VIS_TYPE) + + // saves AO using "Save As" + saveAOAs(TEST_VIS_NAME_UPDATED) + expectAOTitleToBeValue(TEST_VIS_NAME_UPDATED) + expectVisualizationToBeVisible(TEST_VIS_TYPE) }) - describe('"save" and "save as" for a saved AO created by you', () => { - it('navigates to the start page and opens a saved AO', () => { - cy.intercept( - /systemSettings(\S)*keyAnalysisRelativePeriod(\S)*/, - (req) => { - req.reply((res) => { - res.send({ - body: { - ...res.body, - keyHideMonthlyPeriods: false, - }, - }) + it('"save" and "save as" for a saved AO created by you', () => { + // navigates to the start page and opens a saved AO + cy.intercept( + /systemSettings(\S)*keyAnalysisRelativePeriod(\S)*/, + (req) => { + req.reply((res) => { + res.send({ + body: { + ...res.body, + keyHideMonthlyPeriods: false, + }, }) - } - ) - goToStartPage() - openAOByName(TEST_VIS_NAME_UPDATED) - expectAOTitleToBeValue(TEST_VIS_NAME_UPDATED) - }) - it(`replaces the selected period`, () => { - replacePeriodItems(TEST_VIS_TYPE, { useAltData: true }) - expectAOTitleToBeDirty() - }) - it('saves AO using "Save"', () => { - saveExistingAO() - expectAOTitleToNotBeDirty() - expectAOTitleToBeValue(TEST_VIS_NAME) - expectVisualizationToBeVisible(TEST_VIS_TYPE) - }) - it('deletes AO', () => { - deleteAO() - expectRouteToBeEmpty() - expectStartScreenToBeVisible() - }) + }) + } + ) + goToStartPage() + openAOByName(TEST_VIS_NAME_UPDATED) + expectAOTitleToBeValue(TEST_VIS_NAME_UPDATED) + + // replaces the selected period + replacePeriodItems(TEST_VIS_TYPE, { useAltData: true }) + expectAOTitleToBeDirty() + + // saves AO using "Save" + saveExistingAO() + expectAOTitleToNotBeDirty() + expectAOTitleToBeValue(TEST_VIS_NAME) + expectVisualizationToBeVisible(TEST_VIS_TYPE) + + // deletes AO + deleteAO() + expectRouteToBeEmpty() + expectStartScreenToBeVisible() }) - 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` + it('"save" a copied AO created by others 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() - openAOByName(TEST_VIS_BY_OTHERS_NAME) - expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME) + // navigates to the start page and opens an AO created by others + goToStartPage() + 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() + // 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() + // 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() - // saves AO using "Save" - saveExistingAO() - expectAOTitleToNotBeDirty() - expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME_UPDATED) - expectVisualizationToBeVisible() - - // deletes AO - deleteAO() - expectRouteToBeEmpty() - expectStartScreenToBeVisible() - }) + // deletes AO + deleteAO() + expectRouteToBeEmpty() + expectStartScreenToBeVisible() }) }) diff --git a/cypress/integration/start.cy.js b/cypress/integration/start.cy.js index 058ea1b97f..abbd2fee4b 100644 --- a/cypress/integration/start.cy.js +++ b/cypress/integration/start.cy.js @@ -35,52 +35,53 @@ import { expectVisTypeToBeDefault } from '../elements/visualizationTypeSelector. import { expectWindowTitleToBeDefault } from '../elements/window.js' import { expectStoreCurrentToBeEmpty } from '../utils/store.js' -describe('viewing the start screen', () => { - it('navigates to the start page', () => { +describe('Start screen', () => { + it('Start screen shows the correct initial state', () => { + // navigates to the start page goToStartPage() - }) - it('window has a title', () => { + + // window has a title expectWindowTitleToBeDefault() - }) - it('store is empty', () => { + + // store is empty expectStoreCurrentToBeEmpty() - }) - it('no chart is visible', () => { + + // no chart is visible expectVisualizationToNotBeVisible() - }) - it('displays most viewed section', () => { + + // displays most viewed section expectMostViewedToBeVisible() - }) - it('vis type is default', () => { + + // vis type is default expectVisTypeToBeDefault() - }) - it('axis series has data dimension', () => { + + // axis series has data dimension expectAxisToHaveDimension(AXIS_ID_COLUMNS, DIMENSION_ID_DATA) - }) - it('data dimension has no items', () => { + + // data dimension has no items expectDimensionToNotHaveItems(DIMENSION_ID_DATA) - }) - it('axis category has period dimension', () => { + + // axis category has period dimension expectAxisToHaveDimension(AXIS_ID_ROWS, DIMENSION_ID_PERIOD) - }) - it('period dimension has 1 item', () => { + + // period dimension has 1 item expectDimensionToHaveItemAmount(DIMENSION_ID_PERIOD, 1) - }) - it('axis filter has orgunit dimension', () => { + + // axis filter has orgunit dimension expectAxisToHaveDimension(AXIS_ID_FILTERS, DIMENSION_ID_ORGUNIT) - }) - it('orgunit dimension has 1 item', () => { + + // orgunit dimension has 1 item expectDimensionToHaveItemAmount(DIMENSION_ID_ORGUNIT, 1) - }) - it('primary File menu buttons are enabled and menu is closed with click', () => { + + // primary File menu buttons are enabled and menu is closed with click clickMenuBarFileButton() const enabledButtons = [FILE_MENU_BUTTON_NEW, FILE_MENU_BUTTON_OPEN] enabledButtons.forEach((button) => expectFileMenuButtonToBeEnabled(button) ) closeFileMenuWithClick() - }) - it('secondary File menu buttons are disabled and menu is closed with click', () => { + + // secondary File menu buttons are disabled and menu is closed with click clickMenuBarFileButton() const disabledButtons = [ FILE_MENU_BUTTON_SAVEAS, @@ -94,8 +95,8 @@ describe('viewing the start screen', () => { expectFileMenuButtonToBeDisabled(button) ) closeFileMenuWithClick() - }) - it('File menu is closed with Escape', () => { + + // File menu is closed with Escape clickMenuBarFileButton() closeFileMenuWithEsc() })