From 51795c7c28d7a85231e85fe9af8607de2815f59b Mon Sep 17 00:00:00 2001 From: Sviatlana Stsiapanava <152482600+sviatlana-stsiapanava@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:32:29 +0500 Subject: [PATCH] Stabilize test cases (#4637) --- .../e2e/settings/tenant/location-setup.cy.js | 52 ++++++++++++++++--- .../settings/tenant/service-points-view.cy.js | 45 ++++++++++++++-- cypress/e2e/settings/tenant/tenant-view.cy.js | 52 +++++++++++++++---- .../tenant/locations/locationEditForm.js | 1 + 4 files changed, 130 insertions(+), 20 deletions(-) diff --git a/cypress/e2e/settings/tenant/location-setup.cy.js b/cypress/e2e/settings/tenant/location-setup.cy.js index aff0139603..f4ee06ace6 100644 --- a/cypress/e2e/settings/tenant/location-setup.cy.js +++ b/cypress/e2e/settings/tenant/location-setup.cy.js @@ -1,8 +1,13 @@ +import uuid from 'uuid'; import { Permissions } from '../../../support/dictionary'; import { Locations, ServicePoints } from '../../../support/fragments/settings/tenant'; import TenantPane, { TENANTS } from '../../../support/fragments/settings/tenant/tenantPane'; import TopMenuNavigation from '../../../support/fragments/topMenuNavigation'; import Users from '../../../support/fragments/users/users'; +import Campuses from '../../../support/fragments/settings/tenant/location-setup/campuses'; +import Institutions from '../../../support/fragments/settings/tenant/location-setup/institutions'; +import Libraries from '../../../support/fragments/settings/tenant/location-setup/libraries'; +import getRandomPostfix from '../../../support/utils/stringTools'; describe('Settings: Tenant', () => { const testData = { @@ -15,12 +20,43 @@ describe('Settings: Tenant', () => { cy.createTempUser([Permissions.settingsTenantViewLocation.gui]).then((userProperties) => { testData.user = userProperties; cy.getAdminToken().then(() => { - ServicePoints.createViaApi(testData.servicePoint); - const { institution, location } = Locations.getDefaultLocation({ - servicePointId: testData.servicePoint.id, + testData.institution = Institutions.getDefaultInstitution({ + id: uuid(), + name: `1_autotest_institution_${getRandomPostfix()}`, + }); + testData.campus = Campuses.getDefaultCampuse({ + id: uuid(), + name: `1_autotest_campuse_${getRandomPostfix()}`, + institutionId: testData.institution.id, }); - testData.institution = institution; - testData.location = location; + testData.library = Libraries.getDefaultLibrary({ + id: uuid(), + name: `1_autotest_library_${getRandomPostfix()}`, + campusId: testData.campus.id, + }); + testData.location = { + id: uuid(), + isActive: true, + institutionId: testData.institution.id, + institutionName: testData.institution.name, + campusId: testData.campus.id, + campusName: testData.campus.name, + libraryId: testData.library.id, + libraryName: testData.library.name, + servicePointIds: [testData.servicePoint.id], + name: `1_autotest_location_name_${getRandomPostfix()}`, + code: `1_autotest_location_code_${getRandomPostfix()}`, + discoveryDisplayName: `1_autotest_name_${getRandomPostfix()}`, + primaryServicePoint: testData.servicePoint.id, + }; + + Institutions.createViaApi(testData.institution).then(() => { + Campuses.createViaApi(testData.campus).then(() => { + Libraries.createViaApi(testData.library); + }); + }); + + ServicePoints.createViaApi(testData.servicePoint); Locations.createViaApi(testData.location); }); @@ -44,12 +80,12 @@ describe('Settings: Tenant', () => { () => { cy.intercept('/location-units/institutions*', { locinsts: [testData.institution] }); // Select "Institutions" option on the "Location setup" subsection - const Institutions = TenantPane.selectTenant(TENANTS.INSTITUTIONS); + TenantPane.selectTenant(TENANTS.INSTITUTIONS); Institutions.checkNoActionButtons(); // Select "Campuses" option on the "Location setup" subsection // Select any existing institution from the "Select institution" dropdown - const Campuses = TenantPane.selectTenant(TENANTS.CAMPUSES); + TenantPane.selectTenant(TENANTS.CAMPUSES); Campuses.selectOption('Institution', { name: testData.location.institutionName, id: testData.location.institutionId, @@ -58,7 +94,7 @@ describe('Settings: Tenant', () => { // Select "Libraries" option on the "Location setup" subsection // Select any existing institution from the "Select institution" dropdown - const Libraries = TenantPane.selectTenant(TENANTS.LIBRARIES); + TenantPane.selectTenant(TENANTS.LIBRARIES); Libraries.selectOption('Institution', { name: testData.location.institutionName, id: testData.location.institutionId, diff --git a/cypress/e2e/settings/tenant/service-points-view.cy.js b/cypress/e2e/settings/tenant/service-points-view.cy.js index 1171d153f2..37f99a597f 100644 --- a/cypress/e2e/settings/tenant/service-points-view.cy.js +++ b/cypress/e2e/settings/tenant/service-points-view.cy.js @@ -12,7 +12,9 @@ import NewLocation from '../../../support/fragments/settings/tenant/locations/ne import ServicePoints from '../../../support/fragments/settings/tenant/servicePoints/servicePoints'; import SettingsMenu from '../../../support/fragments/settingsMenu'; import Users from '../../../support/fragments/users/users'; -import TopMenu from '../../../support/fragments/topMenu'; +import TopMenuNavigation from '../../../support/fragments/topMenuNavigation'; +import getRandomPostfix from '../../../support/utils/stringTools'; +import { APPLICATION_NAMES } from '../../../support/constants'; describe('Settings: Tenant', () => { const testData = { @@ -27,7 +29,44 @@ describe('Settings: Tenant', () => { ServicePoints.createViaApi(servicePoint); }); - const location = NewLocation.getDefaultLocation(testData.servicePoints[0].id); + const location = { + id: uuid(), + isActive: true, + institutionId: uuid(), + institutionName: `1_autotest_institution_${getRandomPostfix()}`, + campusId: uuid(), + campusName: `1_autotest_campuse_${getRandomPostfix()}`, + libraryId: uuid(), + libraryName: `1_autotest_library_${getRandomPostfix()}`, + servicePointIds: [testData.servicePoints[0].id], + name: `1_autotest_location_name_${getRandomPostfix()}`, + code: `1_autotest_location_code_${getRandomPostfix()}`, + discoveryDisplayName: `1_autotest_name_${getRandomPostfix()}`, + primaryServicePoint: testData.servicePoints[0].id, + }; + + Institutions.createViaApi( + Institutions.getDefaultInstitution({ + id: location.institutionId, + name: location.institutionName, + }), + ).then(() => { + Campuses.createViaApi( + Campuses.getDefaultCampuse({ + id: location.campusId, + name: location.campusName, + institutionId: location.institutionId, + }), + ).then(() => { + Libraries.createViaApi( + Libraries.getDefaultLibrary({ + id: location.libraryId, + name: location.libraryName, + campusId: location.campusId, + }), + ); + }); + }); [...Array(3).keys()].forEach((index) => { testData.locations.push({ @@ -45,7 +84,7 @@ describe('Settings: Tenant', () => { cy.login(testData.user.username, testData.user.password); cy.wait(2000); - cy.visit(TopMenu.settingsPath); + TopMenuNavigation.navigateToApp(APPLICATION_NAMES.SETTINGS); Locations.goToLocationsTab(); }); }); diff --git a/cypress/e2e/settings/tenant/tenant-view.cy.js b/cypress/e2e/settings/tenant/tenant-view.cy.js index 3ec76d85ab..95cb0110c4 100644 --- a/cypress/e2e/settings/tenant/tenant-view.cy.js +++ b/cypress/e2e/settings/tenant/tenant-view.cy.js @@ -1,8 +1,13 @@ +import uuid from 'uuid'; import { Permissions } from '../../../support/dictionary'; import { Locations, ServicePoints } from '../../../support/fragments/settings/tenant'; import TenantPane, { TENANTS } from '../../../support/fragments/settings/tenant/tenantPane'; import TopMenuNavigation from '../../../support/fragments/topMenuNavigation'; import Users from '../../../support/fragments/users/users'; +import Campuses from '../../../support/fragments/settings/tenant/location-setup/campuses'; +import Institutions from '../../../support/fragments/settings/tenant/location-setup/institutions'; +import Libraries from '../../../support/fragments/settings/tenant/location-setup/libraries'; +import getRandomPostfix from '../../../support/utils/stringTools'; describe('Settings: Tenant', () => { const testData = { @@ -11,11 +16,42 @@ describe('Settings: Tenant', () => { before('Create test data', () => { cy.getAdminToken(); ServicePoints.createViaApi(testData.servicePoint); - const { institution, location } = Locations.getDefaultLocation({ - servicePointId: testData.servicePoint.id, + + testData.institution = Institutions.getDefaultInstitution({ + id: uuid(), + name: `1_autotest_institution_${getRandomPostfix()}`, + }); + testData.campus = Campuses.getDefaultCampuse({ + id: uuid(), + name: `1_autotest_campuse_${getRandomPostfix()}`, + institutionId: testData.institution.id, + }); + testData.library = Libraries.getDefaultLibrary({ + id: uuid(), + name: `1_autotest_library_${getRandomPostfix()}`, + campusId: testData.campus.id, + }); + testData.location = { + id: uuid(), + isActive: true, + institutionId: testData.institution.id, + institutionName: testData.institution.name, + campusId: testData.campus.id, + campusName: testData.campus.name, + libraryId: testData.library.id, + libraryName: testData.library.name, + servicePointIds: [testData.servicePoint.id], + name: `1_autotest_location_name_${getRandomPostfix()}`, + code: `1_autotest_location_code_${getRandomPostfix()}`, + discoveryDisplayName: `1_autotest_name_${getRandomPostfix()}`, + primaryServicePoint: testData.servicePoint.id, + }; + + Institutions.createViaApi(testData.institution).then(() => { + Campuses.createViaApi(testData.campus).then(() => { + Libraries.createViaApi(testData.library); + }); }); - testData.institution = institution; - testData.location = location; Locations.createViaApi(testData.location); cy.createTempUser([Permissions.settingsTenantView.gui]).then((userProperties) => { testData.user = userProperties; @@ -39,15 +75,13 @@ describe('Settings: Tenant', () => { { tags: ['extendedPath', 'firebird', 'C409487'] }, () => { cy.intercept('/location-units/institutions*', { locinsts: [testData.institution] }); - // reload is needed because sometimes Location setup section is not displayed - cy.reload(); // Select "Institutions" option on the "Location setup" subsection - const Institutions = TenantPane.selectTenant(TENANTS.INSTITUTIONS); + TenantPane.selectTenant(TENANTS.INSTITUTIONS); Institutions.checkNoActionButtons(); // Select "Campuses" option on the "Location setup" subsection // Select any existing institution from the "Select institution" dropdown - const Campuses = TenantPane.selectTenant(TENANTS.CAMPUSES); + TenantPane.selectTenant(TENANTS.CAMPUSES); Campuses.selectOption('Institution', { name: testData.location.institutionName, id: testData.location.institutionId, @@ -56,7 +90,7 @@ describe('Settings: Tenant', () => { // Select "Libraries" option on the "Location setup" subsection // Select any existing institution from the "Select institution" dropdown - const Libraries = TenantPane.selectTenant(TENANTS.LIBRARIES); + TenantPane.selectTenant(TENANTS.LIBRARIES); Libraries.selectOption('Institution', { name: testData.location.institutionName, id: testData.location.institutionId, diff --git a/cypress/support/fragments/settings/tenant/locations/locationEditForm.js b/cypress/support/fragments/settings/tenant/locations/locationEditForm.js index fd9e019b38..b32081fee3 100644 --- a/cypress/support/fragments/settings/tenant/locations/locationEditForm.js +++ b/cypress/support/fragments/settings/tenant/locations/locationEditForm.js @@ -13,6 +13,7 @@ const saveButton = editFormRoot.find(Button('Save & close')); export default { waitLoading() { cy.expect(editFormRoot.exists()); + cy.wait(1000); }, fillLocationForm({ servicePoint }) { this.waitLoading();