Skip to content
Snippets Groups Projects
Commit cf787550 authored by tzanmix's avatar tzanmix
Browse files

implemented logged user journeys

parent 32e973c0
No related branches found
No related tags found
1 merge request!22Draft: Resolve "Implement user journey tests"
This commit is part of merge request !22. Comments created here will be created in the context of that merge request.
import { defineConfig } from "cypress"; import { defineConfig } from "cypress";
//let appConfig = inject(AppService);
export default defineConfig({ export default defineConfig({
......
describe('logged user journeys', () => { describe('logged user journeys', () => {
//sign user in before each test
beforeEach(() => { beforeEach(() => {
cy.visit("http://localhost:4200/"); //cy.visit("http://localhost:4200/");
//sign in journey through services portal cy.visit(window.location.origin);
}); });
afterEach(() => {
//log user out after each test
cy.get('#navbarDropdown2').click();
cy.get(':nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)').click();
cy.location("pathname").should("equal", "/");
});
it('logs in through services', () => { it('logs in through services', () => {
cy.loginPath(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn', '/services'); cy.loginPath(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn', '/services');
//back on services marketplace after login //back on services marketplace after login
cy.location("pathname").should("equal", "/services/services_marketplace"); cy.location("pathname").should("equal", "/services/services_marketplace");
//check every 'Manage Services' dropdown item
cy.get(':nth-child(2) > #navbarDropdown').each(($link) => { cy.get(':nth-child(2) > #navbarDropdown').click();
const url = $link.prop('href'); let i=0;
console.log(url); cy.get('.show .dropdown-item').each(($el) => {
if (url) { i++;
cy.request(url).then((response) => { cy.wrap($el).click(); // Click the link
expect(response.status).to.eq(200); // Ensure link is not broken cy.get(':nth-child(1) > .cdk-column-actions > .btn').first().click();
});
}
cy.wrap($link).click(); // Click the link //does the dialog open?
cy.url().should('eq', url); // Ensure navigation happened correctly cy.get('mat-dialog-container').should('exist');
cy.go('back'); // Navigate back to check the next link cy.go('back');
cy.get(':nth-child(2) > #navbarDropdown').click();
if(i>1) {
return false;
}
}); });
//access the service specs dropdown
cy.get('#navbarDropdown1').click();
let j=0;
for(let i=1; i<=2; i++) {
cy.get(`.dropdown-submenu > .dropdown-menu > :nth-child(${i}) `).click();
cy.location("pathname").should("not.equal", "/services/services_marketplace");
cy.go('back');
cy.get(':nth-child(2) > #navbarDropdown').click();
cy.get('#navbarDropdown1').click();
}
//check the rest dropdown items
cy.get(':nth-child(4) > .dropdown-item').click();
cy.get('mat-dialog-container').should('exist');
cy.go('back');
cy.get(':nth-child(2) > #navbarDropdown').click();
//'Manage Entities' dropdown
cy.manageEntities(':nth-child(3) > #navbarDropdown', '.jumbotron-heading > .btn', 2, 2);
}); });
it('logs in through resources', () => { it('logs in through resources', () => {
cy.loginPath(':nth-child(3) > .container > .row > .order-md-1 > a > .btn', '/resources'); cy.loginPath(':nth-child(3) > .container > .row > .order-md-1 > a > .btn', '/resources');
cy.location("pathname").should("equal", "/resources/resource_catalogs");
cy.get('.text-md-right > .btn').click();
cy.get('mat-dialog-container').should('exist');
cy.go('back');
cy.get('#navbarDropdown').click();
cy.get('.show > :nth-child(2) > .dropdown-item').click();
cy.location("pathname").should("equal", "/resources/resource_categories");
cy.get('.text-md-right > .btn').click();
cy.location("pathname").should("equal", "/resources/resource_categories_update");
cy.go('back');
cy.get('#navbarDropdown').click();
cy.get('#navbarDropdown1').click();
for(let i=1; i<=2; i++) {
cy.get(`.dropdown-submenu > .dropdown-menu > :nth-child(${i}) `).click();
cy.location("pathname").should("not.equal", "/resources/resource_categories");
cy.go('back');
cy.get('#navbarDropdown').click();
cy.get('#navbarDropdown1').click();
}
//resource inventory
cy.get(':nth-child(5) > .dropdown-item').click();
cy.location("pathname").should("equal", "/resources/resource_inventory");
cy.get('#navbarDropdown').click();
//resource pools
cy.get(':nth-child(7) > .dropdown-item').click();
cy.location("pathname").should("equal", "/resources/resource_pools");
cy.get('#navbarDropdown').click();
//resource reservations
cy.get(':nth-child(8) > .dropdown-item').click();
cy.location("pathname").should("equal", "/resources/resource_reservations");
}); });
it('logs in through testing', () => { it('logs in through testing', () => {
cy.loginPath(':nth-child(5) > .container > .row > .order-md-1 > a > .btn', '/testing'); cy.loginPath(':nth-child(5) > .container > .row > .order-md-1 > a > .btn', '/testing');
cy.manageEntities(':nth-child(1) > #navbarDropdown', '.text-md-right > .btn', 3, 2);
cy.manageEntities(':nth-child(2) > #navbarDropdown', '.jumbotron-heading > .btn', 2, 2);
}); });
it('logs in through products', () => { it('logs in through products', () => {
cy.loginPath(':nth-child(6) > .container > .row > :nth-child(2) > a > .btn', '/products'); cy.loginPath(':nth-child(6) > .container > .row > :nth-child(2) > a > .btn', '/products');
cy.manageEntities(':nth-child(2) > #navbarDropdown', '.text-md-right > .btn', 2, 4);
cy.manageEntities(':nth-child(3) > #navbarDropdown', '.jumbotron-heading > .btn', 2, 2);
}); });
}) })
\ No newline at end of file
const baseUrl = Cypress.config('baseUrl'); // const baseUrl = Cypress.config('baseUrl');
describe('user journey', () => { describe('user journey', () => {
beforeEach(() => { beforeEach(() => {
cy.visit(baseUrl); //cy.visit(baseUrl);
cy.visit(window.location.origin);
}) })
context('user-not-logged-in', () => { context('user-not-logged-in', () => {
...@@ -48,7 +49,7 @@ describe('user journey', () => { ...@@ -48,7 +49,7 @@ describe('user journey', () => {
cy.navigateToProducts(':nth-child(5) > .nav-link'); cy.navigateToProducts(':nth-child(5) > .nav-link');
}) })
}); });
context.only('<who we are> links', () => { context('<who we are> links', () => {
it('checks ETSI SDG OpenSlice Link', () => { it('checks ETSI SDG OpenSlice Link', () => {
cy.get('.ng-star-inserted > :nth-child(1) > .text-white').click(); cy.get('.ng-star-inserted > :nth-child(1) > .text-white').click();
cy.origin('https://osl.etsi.org/', () => { cy.origin('https://osl.etsi.org/', () => {
......
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
declare namespace Cypress { declare namespace Cypress {
interface Chainable { interface Chainable {
navigateToServices(selector): Chainable<any>, navigateToServices(selector): Chainable<any>,
navigateToResources(selector): Chainable<any>, navigateToResources(selector): Chainable<any>,
navigateToTesting(selector): Chainable<any>, navigateToTesting(selector): Chainable<any>,
navigateToProducts(selector): Chainable<any>, navigateToProducts(selector): Chainable<any>,
authUser(): Chainable<any>, authUser(): Chainable<any>,
loginPath(selector, path): Chainable<any> loginPath(selector, path): Chainable<any>,
} manageEntities(selector, button, scndIndx, numOfItems): Chainable<any>
}
} }
Cypress.Commands.add('navigateToServices', (selector) => { Cypress.Commands.add('navigateToServices', (selector) => {
cy.get(selector).click(); cy.get(selector).click();
cy.location("pathname").should("equal", "/services"); cy.location("pathname").should("equal", "/services");
...@@ -52,7 +28,7 @@ Cypress.Commands.add('navigateToServices', (selector) => { ...@@ -52,7 +28,7 @@ Cypress.Commands.add('navigateToServices', (selector) => {
cy.get(':nth-child(2) > .nav-item > .nav-link').click(); cy.get(':nth-child(2) > .nav-item > .nav-link').click();
//sign in button should redirect to auth form //sign in button should redirect to auth form
cy.origin('http://portal.openslice.eu', () => { cy.origin('https://portal.openslice.eu', () => {
cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
}); });
...@@ -66,7 +42,7 @@ Cypress.Commands.add('navigateToResources', (selector) => { ...@@ -66,7 +42,7 @@ Cypress.Commands.add('navigateToResources', (selector) => {
//cy.get('nav-link').should('exist').click(); //cy.get('nav-link').should('exist').click();
//sign in button should redirect to auth form //sign in button should redirect to auth form
cy.origin('http://portal.openslice.eu', () => { cy.origin('https://portal.openslice.eu/', () => {
cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
}); });
...@@ -80,7 +56,7 @@ Cypress.Commands.add('navigateToTesting', (selector) => { ...@@ -80,7 +56,7 @@ Cypress.Commands.add('navigateToTesting', (selector) => {
//cy.get('nav-link').should('exist').click(); //cy.get('nav-link').should('exist').click();
//sign in button should redirect to auth form //sign in button should redirect to auth form
cy.origin('http://portal.openslice.eu', () => { cy.origin('https://portal.openslice.eu', () => {
cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
}); });
...@@ -101,7 +77,7 @@ Cypress.Commands.add('navigateToProducts', (selector) => { ...@@ -101,7 +77,7 @@ Cypress.Commands.add('navigateToProducts', (selector) => {
cy.get(':nth-child(2) > .nav-item > .nav-link').click(); cy.get(':nth-child(2) > .nav-item > .nav-link').click();
//sign in button should redirect to auth form //sign in button should redirect to auth form
cy.origin('http://portal.openslice.eu', () => { cy.origin('https://portal.openslice.eu', () => {
cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
}); });
...@@ -110,7 +86,7 @@ Cypress.Commands.add('navigateToProducts', (selector) => { ...@@ -110,7 +86,7 @@ Cypress.Commands.add('navigateToProducts', (selector) => {
Cypress.Commands.add('authUser', () => { Cypress.Commands.add('authUser', () => {
cy.get('.btn').should("contain", "Sign In").click(); cy.get('.btn').should("contain", "Sign In").click();
cy.origin('http://portal.openslice.eu', () => { cy.origin('https://portal.openslice.eu', () => {
cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
cy.get('#username').type('admin'); cy.get('#username').type('admin');
cy.get('#password').type('openslice'); cy.get('#password').type('openslice');
...@@ -124,4 +100,20 @@ Cypress.Commands.add('loginPath', (selector, path) => { ...@@ -124,4 +100,20 @@ Cypress.Commands.add('loginPath', (selector, path) => {
cy.get(selector).click(); cy.get(selector).click();
cy.location("pathname").should("equal", path); cy.location("pathname").should("equal", path);
cy.authUser(); cy.authUser();
})
Cypress.Commands.add('manageEntities', (selector, button, scndIndx, numOfItems) => {
for(let i=1; i<=numOfItems; i++) {
cy.get(selector).click();
if(i == 2 && scndIndx == 3){
cy.get(`.nav-item.show > .dropdown-menu > :nth-child(3) > .dropdown-item`).click();
cy.go('back');
}
else
cy.get(`.nav-item.show > .dropdown-menu > :nth-child(${i}) > .dropdown-item`).click();
cy.get(button).click();
cy.go('back');
}
}) })
\ No newline at end of file
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
// *********************************************************** // ***********************************************************
// Import commands.js using ES2015 syntax: // Import commands.js using ES2015 syntax:
import './commands' import './commands'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment