Skip to content
Snippets Groups Projects
commands.ts 5.65 KiB
Newer Older
tzanmix's avatar
tzanmix committed
declare namespace Cypress  {
   
    interface Chainable {
        navigateToServices(selector): Chainable<any>,
        navigateToResources(selector): Chainable<any>,
        navigateToTesting(selector): Chainable<any>,
        navigateToProducts(selector): Chainable<any>,
        authUser(): Chainable<any>,
        loginPath(selector, path): Chainable<any>,
tzanmix's avatar
tzanmix committed
        manageEntities(selector, button, scndIndx, numOfItems): Chainable<any>,
        checkProtectedRoutes(): Chainable<any>
tzanmix's avatar
tzanmix committed
const protectedRoutes = ['/services/service_catalogs', '/services/service_categories',
    '/services/service_specs', '/services/service_spec_update',
    '/services/list_nsds', '/services/list_tests',
    '/services/service_orders', '/services/service_inventory',
    '/services/organizations', '/services/individuals',
    '/services/alarms', '/services/action_specs',
    '/services/action_rules', '/services/service_order_checkout',
    '/services/individual_update/myuser', '/resources/resource_catalogs',
    '/resources/resource_categories', '/resources/resource_specs',
    '/resources/resource_spec_update', '/resources/resource_inventory',
    '/resources/resource_pools', '/resources/resource_reservations',
    '/resources/individual_update/myuser', '/testing/service_test_specs',
    '/testing/service_tests', '/testing/organizations', '/testing/individuals',
    '/testing/individual_update/myuser', '/products/product_catalogs',
    '/products/product_categories', '/products/product_offerings',
    '/products/product_specs', '/products/organizations', '/products/individuals',
    '/products/individual_update/myuser'
];
tzanmix's avatar
tzanmix committed
Cypress.Commands.add('navigateToServices', (selector) => {
    cy.get(selector).click();
    cy.location("pathname").should("equal", "/services");
    cy.get('.btn').should("contain", "Sign In");
    cy.get(':nth-child(2) > .nav-item > .nav-link').should("exist");

    //service marketplace button should exist and should redirect to /services_marketplace
    cy.get('.mr-auto > .nav-item > .nav-link').click();
    cy.get('.jumbotron > h5.ng-tns-c147-1').should("contain", "Browse available services and sign in to order");
    cy.get('.catalog-tree-header').should("exist");

    //sign in button should exist
    cy.get(':nth-child(2) > .nav-item > .nav-link').click();

    //sign in button should redirect to auth form
    cy.origin('https://portal.openslice.eu', () => {
tzanmix's avatar
tzanmix committed
    cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

    });
});

Cypress.Commands.add('navigateToResources', (selector) => {
    cy.get(selector).click();
    cy.location("pathname").should("equal", "/resources");
      //sign in button should exist
      cy.get('.btn').should('exist').click();
      //cy.get('nav-link').should('exist').click();

      //sign in button should redirect to auth form
      cy.origin('https://portal.openslice.eu/', () => {
tzanmix's avatar
tzanmix committed
        cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

      });
})

Cypress.Commands.add('navigateToTesting', (selector) => {
    cy.get(selector).click();
    cy.location("pathname").should("equal", "/testing");
    //sign in button should exist
    cy.get('.btn').should('exist').click();
    //cy.get('nav-link').should('exist').click();

    //sign in button should redirect to auth form
    cy.origin('https://portal.openslice.eu', () => {
tzanmix's avatar
tzanmix committed
    cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

    });
});

Cypress.Commands.add('navigateToProducts', (selector) => {
    cy.get(selector).click();
    cy.location("pathname").should("equal", "/products");
    cy.get('.btn').should("contain", "Sign In");
    cy.get(':nth-child(2) > .nav-item > .nav-link').should("exist");

    //marketplace button should exist and should redirect to products/marketplace
    cy.get('.mr-auto > .nav-item > .nav-link').click();
    cy.get('.catalog-tree-header').should("exist");
    cy.get('.mb-0').should("contain", "Product Catalog Explorer");

    //sign in button should exist
    cy.get(':nth-child(2) > .nav-item > .nav-link').click();

    //sign in button should redirect to auth form
    cy.origin('https://portal.openslice.eu', () => {
tzanmix's avatar
tzanmix committed
    cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

    });
tzanmix's avatar
tzanmix committed
});

Cypress.Commands.add('authUser', () => {
    cy.get('.btn').should("contain", "Sign In").click();

    cy.origin('https://portal.openslice.eu', () => {
tzanmix's avatar
tzanmix committed
        cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
        cy.get('#username').type('admin');
        cy.get('#password').type('openslice');
        cy.get('#kc-login').click();
    });
    //redirect page
    cy.location("pathname").should("equal", "/redirect");
});

Cypress.Commands.add('loginPath', (selector, path) => {
    cy.get(selector).click();
tzanmix's avatar
tzanmix committed
    cy.intercept(path);
tzanmix's avatar
tzanmix committed
    cy.location("pathname").should("equal", path);
    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');
    }
tzanmix's avatar
tzanmix committed
})

Cypress.Commands.add('checkProtectedRoutes', () => {
    for(let route of protectedRoutes) {
        cy.intercept(route);
        cy.log(route);
        cy.visit(route);
        cy.location("pathname").should("equal", "/");
    }
tzanmix's avatar
tzanmix committed
})