From 32e973c084d3fb654cf1d34468a7c2c12bfe221f Mon Sep 17 00:00:00 2001
From: tzanmix <tzanmix@gmail.com>
Date: Thu, 6 Feb 2025 14:54:25 +0200
Subject: [PATCH] more-custom-commands

---
 cypress.config.ts                         |  3 +--
 cypress/e2e/user-journeys-logged-in.cy.ts | 23 ++++++++++-------------
 cypress/support/commands.ts               | 23 ++++++++++++++++++++++-
 3 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/cypress.config.ts b/cypress.config.ts
index e5f31b4..f7caec4 100644
--- a/cypress.config.ts
+++ b/cypress.config.ts
@@ -1,6 +1,4 @@
-import { inject } from "@angular/core";
 import { defineConfig } from "cypress";
-import { AppService } from "src/app/shared/services/app.service";
 
 //let appConfig = inject(AppService);
 
@@ -12,5 +10,6 @@ export default defineConfig({
       // implement node event listeners here
     },
     baseUrl: "http://localhost:4200/",
+    pageLoadTimeout: 8000
   },
 });
diff --git a/cypress/e2e/user-journeys-logged-in.cy.ts b/cypress/e2e/user-journeys-logged-in.cy.ts
index 41c11a1..bb55643 100644
--- a/cypress/e2e/user-journeys-logged-in.cy.ts
+++ b/cypress/e2e/user-journeys-logged-in.cy.ts
@@ -7,19 +7,7 @@ describe('logged user journeys', () => {
         
     });
     it('logs in through services', () => {
-        cy.get(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn').click();
-        //cy.get(':nth-child(1) > .nav-link').click()
-        cy.location("pathname").should("equal", "/services");
-        // cy.get('.btn').should("contain", "Sign In").click();
-
-        cy.origin('http://portal.openslice.eu', () => {
-            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");
+        cy.loginPath(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn', '/services');
         //back on services marketplace after login
         cy.location("pathname").should("equal", "/services/services_marketplace");
         
@@ -38,4 +26,13 @@ describe('logged user journeys', () => {
         });
         
     });
+    it('logs in through resources', () => {
+      cy.loginPath(':nth-child(3) > .container > .row > .order-md-1 > a > .btn', '/resources');
+    });
+    it('logs in through testing', () => {
+      cy.loginPath(':nth-child(5) > .container > .row > .order-md-1 > a > .btn', '/testing');
+    });
+    it('logs in through products', () => {
+      cy.loginPath(':nth-child(6) > .container > .row > :nth-child(2) > a > .btn', '/products');
+    });
 })
\ No newline at end of file
diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts
index 96d68ef..13b0a91 100644
--- a/cypress/support/commands.ts
+++ b/cypress/support/commands.ts
@@ -31,7 +31,9 @@ interface Chainable {
     navigateToServices(selector): Chainable<any>,
     navigateToResources(selector): Chainable<any>,
     navigateToTesting(selector): Chainable<any>,
-    navigateToProducts(selector): Chainable<any>   
+    navigateToProducts(selector): Chainable<any>,
+    authUser(): Chainable<any>,
+    loginPath(selector, path): Chainable<any>
   }
 }
 
@@ -103,4 +105,23 @@ Cypress.Commands.add('navigateToProducts', (selector) => {
     cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
 
     });
+});
+
+Cypress.Commands.add('authUser', () => {
+    cy.get('.btn').should("contain", "Sign In").click();
+
+    cy.origin('http://portal.openslice.eu', () => {
+        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();
+    cy.location("pathname").should("equal", path);
+    cy.authUser();
 })
\ No newline at end of file
-- 
GitLab