Skip to content

Commit

Permalink
Refactoring SapSystemDetails and SapSystemOverview and HostsOverview …
Browse files Browse the repository at this point in the history
…e2e tests
  • Loading branch information
CDimonaco committed Jan 4, 2023
1 parent 3f7a489 commit 29dfd90
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 39 deletions.
22 changes: 16 additions & 6 deletions test/e2e/cypress/integration/hosts_overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ const availableHosts1stPage = availableHosts.slice(0, 10);

context('Hosts Overview', () => {
before(() => {
cy.navigateToItem('Hosts');
cy.url().should('include', '/hosts');
cy.apiLogin().then(() => {
cy.navigateToItem('Hosts');
cy.url().should('include', '/hosts');
});
});

beforeEach(() => {
cy.restoreLocalStorage();
});

describe('Registered Hosts are shown in the list', () => {
Expand Down Expand Up @@ -135,7 +141,8 @@ context('Hosts Overview', () => {
describe('Health Detection', () => {
describe('Health Container shows the health overview of the deployed landscape', () => {
before(() => {
cy.visit('/hosts');
cy.navigateToItem('Hosts');
cy.url().should('include', '/hosts');
cy.task('startAgentHeartbeat', agents());
});

Expand All @@ -153,7 +160,8 @@ context('Hosts Overview', () => {
});
describe('Health is changed to critical when the heartbeat is not sent', () => {
before(() => {
cy.visit('/hosts');
cy.navigateToItem('Hosts');
cy.apiLogin();
cy.task('stopAgentsHeartbeat');
});
it('should show health status of the entire cluster of 27 hosts with critical health', () => {
Expand All @@ -173,7 +181,7 @@ context('Hosts Overview', () => {
const firstHost = availableHosts[0];

before(() => {
cy.visit('/hosts');
cy.navigateToItem('Hosts');
cy.task('startAgentHeartbeat', [firstHost.id]);
cy.get('[data-testid="filter-Health"]').click();
});
Expand All @@ -200,6 +208,7 @@ context('Hosts Overview', () => {

describe('SID', () => {
before(() => {
cy.navigateToItem('Hosts');
cy.get('[data-testid="filter-SID"]').click();
});

Expand Down Expand Up @@ -235,7 +244,7 @@ context('Hosts Overview', () => {

describe('Tags', () => {
before(() => {
cy.visit('/hosts');
cy.navigateToItem('Hosts');
cy.get('.tn-hostname').its('length').should('be.gt', 0);
cy.removeTagsFromView();
});
Expand Down Expand Up @@ -279,6 +288,7 @@ context('Hosts Overview', () => {
});

it('should extract tag1 and tag2 from query string and put in tag filter', () => {
cy.apiLogin();
cy.visit('/hosts?tags=tag1&tags=tag2');
cy.get('[data-testid="filter-Tags"]').contains('tag1, tag2');
});
Expand Down
26 changes: 22 additions & 4 deletions test/e2e/cypress/integration/sap_system_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import {

context('SAP system details', () => {
before(() => {
cy.apiLogin();
cy.visit(`/sap_systems/${selectedSystem.Id}`);
cy.url().should('include', `/sap_systems/${selectedSystem.Id}`);
cy.clearLocalStorageSnapshot();
cy.apiLogin().then(() => {
cy.saveLocalStorage();
cy.visit(`/sap_systems/${selectedSystem.Id}`);
cy.url().should('include', `/sap_systems/${selectedSystem.Id}`);
});
});

beforeEach(() => {
cy.restoreLocalStorage();
});

describe('SAP system details page is available', () => {
Expand All @@ -33,11 +40,13 @@ context('SAP system details', () => {

describe('The system layout shows all the running instances', () => {
before(() => {
cy.apiLogin();
cy.visit(`/sap_systems/${selectedSystem.Id}`);
cy.url().should('include', `/sap_systems/${selectedSystem.Id}`);
});

beforeEach(() => {
cy.restoreLocalStorage();
});

after(() => {
// Restore instance health
Expand Down Expand Up @@ -100,6 +109,15 @@ context('SAP system details', () => {
});

describe('The hosts table shows the attached hosts to this SAP system', () => {
before(() => {
cy.visit(`/sap_systems/${selectedSystem.Id}`);
cy.url().should('include', `/sap_systems/${selectedSystem.Id}`);
});

beforeEach(() => {
cy.restoreLocalStorage();
});

attachedHosts.forEach((host, index) => {
it(`should show ${host.Name} with the data`, () => {
cy.get('table.table-fixed')
Expand Down
37 changes: 34 additions & 3 deletions test/e2e/cypress/integration/sap_systems_overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ import {

context('SAP Systems Overview', () => {
before(() => {
cy.navigateToItem('SAP Systems');
cy.url().should('include', '/sap_systems');
cy.apiLogin().then(() => {
cy.navigateToItem('SAP Systems');
cy.url().should('include', '/sap_systems');
cy.saveLocalStorage();
});
});

beforeEach(() => {
cy.restoreLocalStorage();
});

describe('Registered SAP Systems should be available in the overview', () => {
Expand Down Expand Up @@ -41,6 +48,13 @@ context('SAP Systems Overview', () => {
});

describe('Links to the details page are the expected ones', () => {
before(() => {
cy.apiLogin().then(() => {
cy.navigateToItem('SAP Systems');
cy.url().should('include', '/sap_systems');
});
});

availableSAPSystems.forEach(({ sid: sid, id: id }) => {
it(`should have a link to the SAP System with id: ${id}`, () => {
cy.get('td').contains(sid).click();
Expand All @@ -51,6 +65,12 @@ context('SAP Systems Overview', () => {
});

describe('Attached databases are the expected ones', () => {
before(() => {
cy.apiLogin().then(() => {
cy.navigateToItem('SAP Systems');
cy.url().should('include', '/sap_systems');
});
});
availableSAPSystems.forEach(
({ sid: sid, attachedDatabase: attachedDatabase }) => {
it(`should show the expected attached database details`, () => {
Expand All @@ -77,6 +97,11 @@ context('SAP Systems Overview', () => {
});

describe('Instances are the expected ones', () => {
before(() => {
cy.navigateToItem('SAP Systems');
cy.url().should('include', '/sap_systems');
});

availableSAPSystems.forEach(({ instances: instances }, index) => {
it(`should show the expected instances details`, () => {
cy.get('table.table-fixed > tbody > tr')
Expand Down Expand Up @@ -198,10 +223,16 @@ context('SAP Systems Overview', () => {

describe('SAP Systems Tagging', () => {
before(() => {
cy.removeTagsFromView();
cy.apiLogin().then(() => {
cy.removeTagsFromView();
});
});

availableSAPSystems.forEach(({ sid, tag }) => {
before(() => {
cy.navigateToItem('SAP Systems');
cy.url().should('include', '/sap_systems');
});
describe(`Add tag '${tag}' to SAP System with sid: '${sid}'`, () => {
it(`should tag SAP System '${sid}'`, () => {
cy.addTagByColumnValue(sid, tag);
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const http = require('http');
let heartbeatsIntervals = [];

module.exports = (on, config) => {
require("cypress-localstorage-commands/plugin")(on, config);
require('cypress-localstorage-commands/plugin')(on, config);
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
Expand Down Expand Up @@ -57,4 +57,6 @@ module.exports = (on, config) => {
return null;
},
});

return config;
};
45 changes: 23 additions & 22 deletions test/e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,31 @@ Cypress.Commands.add('login', () => {
cy.url().should('include', '/');
});

const apiLogin = () => {
const apiLogin = () => {
const [username, password] = [
Cypress.env('login_user'),
Cypress.env('login_password'),
];
return cy.request({
method: 'POST',
url: '/api/session',
body: {
username,
password,
}
}).then((response) => {
const { access_token: accessToken } = response.body
return accessToken;
});
}
return cy
.request({
method: 'POST',
url: '/api/session',
body: {
username,
password,
},
})
.then((response) => {
const { access_token: accessToken } = response.body;
return accessToken;
});
};

Cypress.Commands.add('apiLogin', () => {
apiLogin().then((accessToken) => {
cy.setLocalStorage('access_token', accessToken)
cy.saveLocalStorage()
})
})
return apiLogin().then((accessToken) => {
cy.setLocalStorage('access_token', accessToken);
});
});

Cypress.Commands.add('acceptEula', () => {
apiLogin().then((accessToken) => {
Expand All @@ -76,7 +77,7 @@ Cypress.Commands.add('acceptEula', () => {
cy.get('button').contains('Accept').click();
}
});
})
});
});

Cypress.Commands.add('loadScenario', (scenario) => {
Expand Down Expand Up @@ -130,7 +131,7 @@ Cypress.Commands.add('selectChecks', (clusterId, checks) => {
bearer: accessToken,
},
});
})
});
});

Cypress.Commands.add('removeTagsFromView', () => {
Expand Down Expand Up @@ -191,7 +192,7 @@ Cypress.Commands.add('setMockRunnerExpectedResult', (result) => {
bearer: accessToken,
},
});
})
});
});

Cypress.Commands.add('requestChecksExecution', (clusterId) => {
Expand All @@ -214,5 +215,5 @@ Cypress.Commands.add('requestChecksExecution', (clusterId) => {
bearer: accessToken,
},
});
})
});
});
5 changes: 2 additions & 3 deletions test/e2e/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// https://on.cypress.io/configuration
// ***********************************************************

import "cypress-localstorage-commands"
import 'cypress-localstorage-commands';

// Import commands.js using ES2015 syntax:
import './commands';
Expand All @@ -27,6 +27,7 @@ const sessionCookie = '_trento_key';
before(() => {
cy.loadScenario('healthy-27-node-SAP-cluster');
cy.login();
cy.apiLogin();
cy.acceptEula();
});

Expand All @@ -35,7 +36,5 @@ after(() => {
});

beforeEach(() => {
// cy.login();
// cy.apiLogin();
cy.Cookies.preserveOnce(sessionCookie);
});

0 comments on commit 29dfd90

Please sign in to comment.