From aad037a829a54a106d431dfbb1e8db43666e625c Mon Sep 17 00:00:00 2001 From: Nina Kylstad Date: Fri, 24 Nov 2023 11:04:06 +0100 Subject: [PATCH 1/2] added some tests --- frontend/language/src/nb.json | 2 +- .../src/integration/studio/settingsModal.js | 71 +++++++++++++++++++ .../cypress/src/selectors/accessControlTab.js | 17 +++++ .../src/selectors/administrationTab.js | 7 ++ .../cypress/src/selectors/policyEditorTab.js | 8 +++ .../cypress/src/selectors/settingsTab.js | 16 +++++ .../testing/cypress/src/support/studio.js | 4 ++ 7 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 frontend/testing/cypress/src/integration/studio/settingsModal.js create mode 100644 frontend/testing/cypress/src/selectors/accessControlTab.js create mode 100644 frontend/testing/cypress/src/selectors/administrationTab.js create mode 100644 frontend/testing/cypress/src/selectors/policyEditorTab.js create mode 100644 frontend/testing/cypress/src/selectors/settingsTab.js diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index 1b2972301d3..a8afae429da 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1132,7 +1132,7 @@ "settings_modal.setup_tab_heading": "Oppsett", "settings_modal.setup_tab_switch_autoDeleteOnProcessEnd": "Automatisk sletting etter innsending", "settings_modal.setup_tab_switch_copyInstanceSettings_enabled": "Bruker kan kopiere instansen", - "settings_modal.setup_tab_switch_messageBoxConfig_hideSettings_hideAlways": "Skjul i arkiv hos bruker etter innsending ", + "settings_modal.setup_tab_switch_messageBoxConfig_hideSettings_hideAlways": "Skjul i arkiv hos bruker etter innsending", "settings_modal.setup_tab_switch_onEntry_show": "Vis pÄstartede instanser", "shared.header_all": "Alle", "shared.header_button": "Altinn profilmeny", diff --git a/frontend/testing/cypress/src/integration/studio/settingsModal.js b/frontend/testing/cypress/src/integration/studio/settingsModal.js new file mode 100644 index 00000000000..53a4823b672 --- /dev/null +++ b/frontend/testing/cypress/src/integration/studio/settingsModal.js @@ -0,0 +1,71 @@ +/// +/// + +import * as texts from '../../../../../language/src/nb.json'; +import { accessControlTab } from '../../selectors/accessControlTab'; +import { administrationTab } from '../../selectors/administrationTab'; +import { policyEditorTab } from '../../selectors/policyEditorTab'; +import { settingsTab } from '../../selectors/settingsTab'; + +const designerAppId = `${Cypress.env('autoTestUser')}/${Cypress.env('designerAppName')}`; + +context('Designer', () => { + before(() => { + // cy.deleteAllApps(Cypress.env('autoTestUser'), Cypress.env('accessToken')); + cy.studioLogin(Cypress.env('autoTestUser'), Cypress.env('autoTestUserPwd')); + // cy.createApp(Cypress.env('autoTestUser'), Cypress.env('designerAppName')); + }); + beforeEach(() => { + cy.visit('/dashboard'); + // Navigate to designerApp + cy.visit('/editor/' + designerAppId); + cy.openSettingsModal(); + }); + + it('is possible to open the settings modal', () => { + cy.findByRole('heading', { name: texts['settings_modal.heading'] }).should('be.visible'); + }); + + it('is possible to see and edit information on About App tab', () => { + administrationTab.getHeader().should('be.visible'); + administrationTab.getAppNameField().clear().type('New app name'); + administrationTab.getAppNameField().invoke('val').should('contain', 'New app name'); + }); + + it('is possible to toggle settings on app settings tab', () => { + settingsTab.getTab().click(); + settingsTab.getHeader().should('be.visible'); + settingsTab.getAutoDelete().should('be.visible'); + settingsTab.getEnableCopyInstance().should('be.visible'); + settingsTab.getHideInInbox().should('be.visible'); + settingsTab.getShowStartedInstances().should('be.visible'); + }); + + it('is possible to load the policy editor tab', () => { + policyEditorTab.getTab().click(); + policyEditorTab.getHeader().should('be.visible'); + policyEditorTab.getSecurityLevelSelect().should('be.visible'); + }); + + it('is possible to load the access control tab', () => { + accessControlTab.getTab().click(); + accessControlTab.getHeader().should('be.visible'); + accessControlTab.getBankruptcyParty().should('be.visible'); + accessControlTab.getOrganisationParty().should('be.visible'); + accessControlTab.getPersonParty().should('be.visible'); + accessControlTab.getSubUnitParty().should('be.visible'); + }); + + it.only('is possible to update settings on the access control tab', () => { + accessControlTab.getTab().click(); + accessControlTab.getHeader().should('be.visible'); + accessControlTab.getBankruptcyParty().should('be.visible').click(); + accessControlTab.getBankruptcyPartyCheckbox().should('be.checked'); + + // Close modal and re-open to confirm data is set as expected + cy.findByRole('button', { name: texts['modal.close_icon'] }).click(); + cy.openSettingsModal(); + accessControlTab.getTab().click(); + accessControlTab.getBankruptcyPartyCheckbox().should('be.checked'); + }); +}); diff --git a/frontend/testing/cypress/src/selectors/accessControlTab.js b/frontend/testing/cypress/src/selectors/accessControlTab.js new file mode 100644 index 00000000000..c147c1934d1 --- /dev/null +++ b/frontend/testing/cypress/src/selectors/accessControlTab.js @@ -0,0 +1,17 @@ +import * as texts from '@altinn-studio/language/src/nb.json'; + +export const accessControlTab = { + getHeader: () => + cy.findByRole('heading', { name: texts['settings_modal.access_control_tab_heading'] }), + getTab: () => cy.findByText(texts['settings_modal.access_control_tab_heading']), + getBankruptcyParty: () => + cy.findByText(texts['settings_modal.access_control_tab_option_bankruptcy_estate']), + getBankruptcyPartyCheckbox: () => + cy.findByRole('checkbox', { + name: texts['settings_modal.access_control_tab_option_bankruptcy_estate'], + }), + getOrganisationParty: () => + cy.findByText(texts['settings_modal.access_control_tab_option_organisation']), + getPersonParty: () => cy.findByText(texts['settings_modal.access_control_tab_option_person']), + getSubUnitParty: () => cy.findByText(texts['settings_modal.access_control_tab_option_sub_unit']), +}; diff --git a/frontend/testing/cypress/src/selectors/administrationTab.js b/frontend/testing/cypress/src/selectors/administrationTab.js new file mode 100644 index 00000000000..46c6a2ed00a --- /dev/null +++ b/frontend/testing/cypress/src/selectors/administrationTab.js @@ -0,0 +1,7 @@ +import * as texts from '@altinn-studio/language/src/nb.json'; + +export const administrationTab = { + getAppNameField: () => + cy.findByRole('textbox', { name: texts['settings_modal.about_tab_name_label'] }), + getHeader: () => cy.findByRole('heading', { name: texts['administration.administration'] }), +}; diff --git a/frontend/testing/cypress/src/selectors/policyEditorTab.js b/frontend/testing/cypress/src/selectors/policyEditorTab.js new file mode 100644 index 00000000000..379ac85010f --- /dev/null +++ b/frontend/testing/cypress/src/selectors/policyEditorTab.js @@ -0,0 +1,8 @@ +import * as texts from '@altinn-studio/language/src/nb.json'; + +export const policyEditorTab = { + getHeader: () => cy.findByRole('heading', { name: texts['settings_modal.policy_tab_heading'] }), + getTab: () => cy.findByText(texts['settings_modal.policy_tab_heading']), + getSecurityLevelSelect: () => + cy.findByRole('combobox', { name: texts['policy_editor.select_auth_level_label'] }), +}; diff --git a/frontend/testing/cypress/src/selectors/settingsTab.js b/frontend/testing/cypress/src/selectors/settingsTab.js new file mode 100644 index 00000000000..af07a6b2aed --- /dev/null +++ b/frontend/testing/cypress/src/selectors/settingsTab.js @@ -0,0 +1,16 @@ +import * as texts from '@altinn-studio/language/src/nb.json'; + +export const settingsTab = { + getHeader: () => cy.findByRole('heading', { name: texts['settings_modal.setup_tab_heading'] }), + getTab: () => cy.findByText(texts['settings_modal.setup_tab_heading']), + getAutoDelete: () => + cy.findByText(texts['settings_modal.setup_tab_switch_autoDeleteOnProcessEnd']), + getHideInInbox: () => + cy.findByText( + texts['settings_modal.setup_tab_switch_messageBoxConfig_hideSettings_hideAlways'], + ), + getEnableCopyInstance: () => + cy.findByText(texts['settings_modal.setup_tab_switch_copyInstanceSettings_enabled']), + getShowStartedInstances: () => + cy.findByText(texts['settings_modal.setup_tab_switch_onEntry_show']), +}; diff --git a/frontend/testing/cypress/src/support/studio.js b/frontend/testing/cypress/src/support/studio.js index 5bd2a85ec67..0703ebb55c9 100644 --- a/frontend/testing/cypress/src/support/studio.js +++ b/frontend/testing/cypress/src/support/studio.js @@ -107,3 +107,7 @@ Cypress.Commands.add('ensureCreatePageIsLoaded', () => { cy.wait('@getLayoutSettings').its('response.statusCode').should('eq', 200); cy.findByRole('button', { name: `${texts['ux_editor.pages_add']}` }).should('be.visible'); }); + +Cypress.Commands.add('openSettingsModal', () => { + cy.findByRole('button', { name: texts['settings_modal.heading'] }).click(); +}); From 75b1446b9a2356824e50519c50d5dfa9e559b13c Mon Sep 17 00:00:00 2001 From: Nina Kylstad Date: Mon, 18 Dec 2023 14:23:29 +0100 Subject: [PATCH 2/2] local changes tests --- .../src/integration/studio/settingsModal.js | 39 ++++++++++++++----- .../src/selectors/administrationTab.js | 2 +- .../cypress/src/selectors/localChangesTab.js | 23 +++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 frontend/testing/cypress/src/selectors/localChangesTab.js diff --git a/frontend/testing/cypress/src/integration/studio/settingsModal.js b/frontend/testing/cypress/src/integration/studio/settingsModal.js index 53a4823b672..282922cdec6 100644 --- a/frontend/testing/cypress/src/integration/studio/settingsModal.js +++ b/frontend/testing/cypress/src/integration/studio/settingsModal.js @@ -4,16 +4,17 @@ import * as texts from '../../../../../language/src/nb.json'; import { accessControlTab } from '../../selectors/accessControlTab'; import { administrationTab } from '../../selectors/administrationTab'; +import { localChangesTab } from '../../selectors/localChangesTab'; import { policyEditorTab } from '../../selectors/policyEditorTab'; import { settingsTab } from '../../selectors/settingsTab'; const designerAppId = `${Cypress.env('autoTestUser')}/${Cypress.env('designerAppName')}`; -context('Designer', () => { +context('SettingsModal', () => { before(() => { - // cy.deleteAllApps(Cypress.env('autoTestUser'), Cypress.env('accessToken')); + cy.deleteAllApps(Cypress.env('autoTestUser'), Cypress.env('accessToken')); cy.studioLogin(Cypress.env('autoTestUser'), Cypress.env('autoTestUserPwd')); - // cy.createApp(Cypress.env('autoTestUser'), Cypress.env('designerAppName')); + cy.createApp(Cypress.env('autoTestUser'), Cypress.env('designerAppName')); }); beforeEach(() => { cy.visit('/dashboard'); @@ -21,11 +22,19 @@ context('Designer', () => { cy.visit('/editor/' + designerAppId); cy.openSettingsModal(); }); + after(() => { + cy.deleteAllApps(Cypress.env('autoTestUser'), Cypress.env('accessToken')); + }); it('is possible to open the settings modal', () => { cy.findByRole('heading', { name: texts['settings_modal.heading'] }).should('be.visible'); }); + it('is possible to close the settings modal', () => { + cy.findByRole('button', { name: texts['modal.close_icon'] }).click(); + cy.findByRole('heading', { name: texts['settings_modal.heading'] }).should('not.exist'); + }); + it('is possible to see and edit information on About App tab', () => { administrationTab.getHeader().should('be.visible'); administrationTab.getAppNameField().clear().type('New app name'); @@ -42,23 +51,19 @@ context('Designer', () => { }); it('is possible to load the policy editor tab', () => { + // This test only loads the tab and tests that it loads as expected. + // We should implement a separate test for the poloicy editor. policyEditorTab.getTab().click(); policyEditorTab.getHeader().should('be.visible'); policyEditorTab.getSecurityLevelSelect().should('be.visible'); }); - it('is possible to load the access control tab', () => { + it('is possible to update settings on the access control tab', () => { accessControlTab.getTab().click(); accessControlTab.getHeader().should('be.visible'); - accessControlTab.getBankruptcyParty().should('be.visible'); accessControlTab.getOrganisationParty().should('be.visible'); accessControlTab.getPersonParty().should('be.visible'); accessControlTab.getSubUnitParty().should('be.visible'); - }); - - it.only('is possible to update settings on the access control tab', () => { - accessControlTab.getTab().click(); - accessControlTab.getHeader().should('be.visible'); accessControlTab.getBankruptcyParty().should('be.visible').click(); accessControlTab.getBankruptcyPartyCheckbox().should('be.checked'); @@ -68,4 +73,18 @@ context('Designer', () => { accessControlTab.getTab().click(); accessControlTab.getBankruptcyPartyCheckbox().should('be.checked'); }); + + it('is possible to delete local changes', () => { + localChangesTab.getTab().click(); + localChangesTab.getHeader().should('be.visible'); + localChangesTab.getDownloadChangesLink().should('be.visible'); + localChangesTab.getDownloadAllLink().should('be.visible'); + localChangesTab.getDeleteChangesButton().should('be.visible').click(); + localChangesTab.getConfirmRepoNameField().type('test'); + localChangesTab.getConfirmDeleteButton().should('be.disabled'); + localChangesTab.getConfirmRepoNameField().clear(); + localChangesTab.getConfirmRepoNameField().type(`${Cypress.env('designerAppName')}`); + localChangesTab.getConfirmDeleteButton().should('be.enabled').click(); + cy.findByText(texts['overview.reset_repo_completed']).should('be.visible'); + }); }); diff --git a/frontend/testing/cypress/src/selectors/administrationTab.js b/frontend/testing/cypress/src/selectors/administrationTab.js index 46c6a2ed00a..3a68cb833c2 100644 --- a/frontend/testing/cypress/src/selectors/administrationTab.js +++ b/frontend/testing/cypress/src/selectors/administrationTab.js @@ -3,5 +3,5 @@ import * as texts from '@altinn-studio/language/src/nb.json'; export const administrationTab = { getAppNameField: () => cy.findByRole('textbox', { name: texts['settings_modal.about_tab_name_label'] }), - getHeader: () => cy.findByRole('heading', { name: texts['administration.administration'] }), + getHeader: () => cy.findByRole('heading', { name: texts['settings_modal.about_tab_heading'] }), }; diff --git a/frontend/testing/cypress/src/selectors/localChangesTab.js b/frontend/testing/cypress/src/selectors/localChangesTab.js new file mode 100644 index 00000000000..88cb7d01c54 --- /dev/null +++ b/frontend/testing/cypress/src/selectors/localChangesTab.js @@ -0,0 +1,23 @@ +import * as texts from '@altinn-studio/language/src/nb.json'; + +export const localChangesTab = { + getHeader: () => + cy.findByRole('heading', { name: texts['settings_modal.local_changes_tab_heading'] }), + getTab: () => cy.findByText(texts['settings_modal.local_changes_tab_heading']), + getDownloadChangesLink: () => + cy.findByRole('link', { + name: texts['settings_modal.local_changes_tab_download_only_changed_button'], + }), + getDownloadAllLink: () => + cy.findByRole('link', { name: texts['settings_modal.local_changes_tab_download_all_button'] }), + getDeleteChangesButton: () => + cy.findByRole('button', { name: texts['settings_modal.local_changes_tab_delete_button'] }), + getConfirmRepoNameField: () => + cy.findByRole('textbox', { + name: texts['settings_modal.local_changes_tab_delete_modal_textfield_label'], + }), + getConfirmDeleteButton: () => + cy.findByRole('button', { + name: texts['settings_modal.local_changes_tab_delete_modal_delete_button'], + }), +};