This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch 2843-nhance-user-handling-in-cypress-tests
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/2843-nhance-user-handling-in-cypress-tests by this push:
     new cc6c766d39 refactor(#2843): Move switch user to user utils class
cc6c766d39 is described below

commit cc6c766d39d35e7e3a92f08b6af6a67ab47c63ad
Author: Philipp Zehnder <[email protected]>
AuthorDate: Thu May 9 13:58:56 2024 +0200

    refactor(#2843): Move switch user to user utils class
---
 ui/cypress/support/e2e.ts                          |  2 --
 ui/cypress/support/general/switchUser.ts           | 40 ----------------------
 ui/cypress/support/utils/UserUtils.ts              | 11 +++++-
 ui/cypress/support/utils/connect/ConnectUtils.ts   |  2 +-
 ...> deleteAdapterWithMultipleUsers.smoke.spec.ts} | 12 +++----
 .../userManagement/addUserAdmin.smoke.spec.ts      |  4 +--
 .../userManagement/testGroupManagement.spec.ts     |  6 ++--
 .../userManagement/testUserRoleConnect.spec.ts     |  2 +-
 .../userManagement/testUserRolePipeline.spec.ts    |  4 +--
 .../testVariousUserRoles.smoke.spec.ts             |  4 +--
 10 files changed, 27 insertions(+), 60 deletions(-)

diff --git a/ui/cypress/support/e2e.ts b/ui/cypress/support/e2e.ts
index 561b34f7c0..c37c43ac26 100644
--- a/ui/cypress/support/e2e.ts
+++ b/ui/cypress/support/e2e.ts
@@ -19,7 +19,6 @@
 import { login } from './general/login';
 import { logout } from './general/logout';
 import { dataCy } from './general/dataCy';
-import { switchUser } from './general/switchUser';
 // tslint:disable-next-line:no-implicit-dependencies
 import 'cypress-file-upload';
 import { resetStreamPipes } from './general/resetStreamPipes';
@@ -29,7 +28,6 @@ import { removeDownloadDirectory } from 
'./general/removeDownloadDirectory';
 // General commands
 Cypress.Commands.add('login', login);
 Cypress.Commands.add('logout', logout);
-Cypress.Commands.add('switchUser', switchUser);
 Cypress.Commands.add('dataCy', dataCy);
 Cypress.Commands.add('resetStreamPipes', resetStreamPipes);
 Cypress.Commands.add('initStreamPipesTest', initStreamPipesTest);
diff --git a/ui/cypress/support/general/switchUser.ts 
b/ui/cypress/support/general/switchUser.ts
deleted file mode 100644
index bb8612ac9f..0000000000
--- a/ui/cypress/support/general/switchUser.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import { User } from '../model/User';
-
-declare global {
-    namespace Cypress {
-        interface Chainable {
-            /**
-             * Logout and login as new user
-             * @example cy.switchUser();
-             */
-            switchUser: typeof switchUser;
-        }
-    }
-}
-
-export const switchUser = (user: User) => {
-    cy.logout();
-    cy.visit('#/login');
-    cy.dataCy('login-email').type(user.email);
-    cy.dataCy('login-password').type(user.password);
-    cy.dataCy('login-button').click();
-    cy.wait(1000);
-};
diff --git a/ui/cypress/support/utils/UserUtils.ts 
b/ui/cypress/support/utils/UserUtils.ts
index 9db82d6410..964b35f1da 100644
--- a/ui/cypress/support/utils/UserUtils.ts
+++ b/ui/cypress/support/utils/UserUtils.ts
@@ -27,7 +27,7 @@ export class UserUtils {
         .addRole(UserRole.ROLE_ADMIN)
         .build();
 
-    public static adapterAndPipelineAdminUser = UserBuilder.create(
+    public static userWithAdapterAndPipelineAdminRights = UserBuilder.create(
         '[email protected]',
     )
         .setName('anpadmin')
@@ -62,6 +62,15 @@ export class UserUtils {
         cy.dataCy('sp-element-edit-user-save').click();
     }
 
+    public static switchUser(user: User) {
+        cy.logout();
+        cy.visit('#/login');
+        cy.dataCy('login-email').type(user.email);
+        cy.dataCy('login-password').type(user.password);
+        cy.dataCy('login-button').click();
+        cy.wait(1000);
+    };
+
     public static deleteUser(user: User) {
         this.goToUserConfiguration();
 
diff --git a/ui/cypress/support/utils/connect/ConnectUtils.ts 
b/ui/cypress/support/utils/connect/ConnectUtils.ts
index 5a8a77a57c..9e0d11ba41 100644
--- a/ui/cypress/support/utils/connect/ConnectUtils.ts
+++ b/ui/cypress/support/utils/connect/ConnectUtils.ts
@@ -223,7 +223,7 @@ export class ConnectUtils {
             'be.visible',
         );
         if (switchUserCheck) {
-            cy.switchUser(UserUtils.adapterAndPipelineAdminUser);
+            
UserUtils.switchUser(UserUtils.userWithAdapterAndPipelineAdminRights);
         }
         this.checkAdapterAndAssociatedPipelinesDeleted();
     }
diff --git a/ui/cypress/tests/adapter/enhancedDeleteAdapter.smoke.spec.ts 
b/ui/cypress/tests/adapter/deleteAdapterWithMultipleUsers.smoke.spec.ts
similarity index 89%
rename from ui/cypress/tests/adapter/enhancedDeleteAdapter.smoke.spec.ts
rename to ui/cypress/tests/adapter/deleteAdapterWithMultipleUsers.smoke.spec.ts
index 6bb2cc3c59..6583712b94 100644
--- a/ui/cypress/tests/adapter/enhancedDeleteAdapter.smoke.spec.ts
+++ b/ui/cypress/tests/adapter/deleteAdapterWithMultipleUsers.smoke.spec.ts
@@ -49,17 +49,17 @@ describe('Test Enhanced Adapter Deletion', () => {
     // In the beginning, create the non-admin user
     before(() => {
         cy.initStreamPipesTest();
-        UserUtils.addUser(UserUtils.adapterAndPipelineAdminUser);
+        UserUtils.addUser(UserUtils.userWithAdapterAndPipelineAdminRights);
         cy.logout();
     });
 
     beforeEach('Setup Test', () => {
         cy.visit('#/login');
         cy.dataCy('login-email').type(
-            UserUtils.adapterAndPipelineAdminUser.email,
+            UserUtils.userWithAdapterAndPipelineAdminRights.email,
         );
         cy.dataCy('login-password').type(
-            UserUtils.adapterAndPipelineAdminUser.password,
+            UserUtils.userWithAdapterAndPipelineAdminRights.password,
         );
         cy.dataCy('login-button').click();
         cy.wait(1000);
@@ -78,18 +78,18 @@ describe('Test Enhanced Adapter Deletion', () => {
         PipelineUtils.addPipeline(pipelineInput);
         PipelineUtils.addPipeline(pipelineInput);
         // Then let the admin delete them
-        cy.switchUser(UserUtils.adminUser);
+        UserUtils.switchUser(UserUtils.adminUser);
         ConnectUtils.deleteAdapterAndAssociatedPipelines(true);
     });
 
     it('Test Delete Adapter and Associated Pipelines Permission Denied', () => 
{
         // Let the admin create the adapter and the pipeline
-        cy.switchUser(UserUtils.adminUser);
+        UserUtils.switchUser(UserUtils.adminUser);
         ConnectUtils.testAdapter(adapterInput);
         PipelineUtils.addPipeline(pipelineInput);
         PipelineUtils.addPipeline(pipelineInput);
         // Then the user shouldn't be able to delete them
-        cy.switchUser(UserUtils.adapterAndPipelineAdminUser);
+        UserUtils.switchUser(UserUtils.userWithAdapterAndPipelineAdminRights);
         ConnectUtils.deleteAdapterAndAssociatedPipelinesPermissionDenied();
     });
 });
diff --git a/ui/cypress/tests/userManagement/addUserAdmin.smoke.spec.ts 
b/ui/cypress/tests/userManagement/addUserAdmin.smoke.spec.ts
index be962555c4..91d5c788e2 100644
--- a/ui/cypress/tests/userManagement/addUserAdmin.smoke.spec.ts
+++ b/ui/cypress/tests/userManagement/addUserAdmin.smoke.spec.ts
@@ -50,12 +50,12 @@ describe('Test User Management', () => {
         );
 
         // Login as user
-        cy.switchUser(user);
+        UserUtils.switchUser(user);
 
         UserUtils.goToUserConfiguration();
         cy.dataCy('close-tutorial-button').click();
 
-        cy.switchUser(UserUtils.adminUser);
+        UserUtils.switchUser(UserUtils.adminUser);
         UserUtils.goToUserConfiguration();
 
         UserUtils.deleteUser(user);
diff --git a/ui/cypress/tests/userManagement/testGroupManagement.spec.ts 
b/ui/cypress/tests/userManagement/testGroupManagement.spec.ts
index 1df9d793bf..86e78d4f79 100644
--- a/ui/cypress/tests/userManagement/testGroupManagement.spec.ts
+++ b/ui/cypress/tests/userManagement/testGroupManagement.spec.ts
@@ -100,7 +100,7 @@ describe('Test Group Management for Pipelines', () => {
         cy.dataCy('sp-element-edit-user-save').click();
 
         // Login as first user which belongs to user group with pipeline admin 
role
-        cy.switchUser(user);
+        UserUtils.switchUser(user);
 
         cy.dataCy('navigation-icon', { timeout: 10000 }).should(
             'have.length',
@@ -119,7 +119,7 @@ describe('Test Group Management for Pipelines', () => {
         );
 
         // Login as user2
-        cy.switchUser(user2);
+        UserUtils.switchUser(user2);
 
         cy.dataCy('navigation-icon', { timeout: 10000 }).should(
             'have.length',
@@ -134,7 +134,7 @@ describe('Test Group Management for Pipelines', () => {
         );
 
         // Log in as admin and delete users
-        cy.switchUser(UserUtils.adminUser);
+        UserUtils.switchUser(UserUtils.adminUser);
         UserUtils.deleteUser(user);
         UserUtils.deleteUser(user2);
 
diff --git a/ui/cypress/tests/userManagement/testUserRoleConnect.spec.ts 
b/ui/cypress/tests/userManagement/testUserRoleConnect.spec.ts
index ce7f66a3cc..5b0dace368 100644
--- a/ui/cypress/tests/userManagement/testUserRoleConnect.spec.ts
+++ b/ui/cypress/tests/userManagement/testUserRoleConnect.spec.ts
@@ -37,7 +37,7 @@ describe('Test User Roles for Connect', () => {
         UserUtils.addUser(connect_admin);
 
         // Login as user and check if connect is visible to user
-        cy.switchUser(connect_admin);
+        UserUtils.switchUser(connect_admin);
 
         cy.dataCy('navigation-icon', { timeout: 10000 }).should(
             'have.length',
diff --git a/ui/cypress/tests/userManagement/testUserRolePipeline.spec.ts 
b/ui/cypress/tests/userManagement/testUserRolePipeline.spec.ts
index 9da4a9dab7..6d4a9b9cb7 100644
--- a/ui/cypress/tests/userManagement/testUserRolePipeline.spec.ts
+++ b/ui/cypress/tests/userManagement/testUserRolePipeline.spec.ts
@@ -79,7 +79,7 @@ describe('Test User Roles for Pipelines', () => {
         cy.dataCy('sp-element-edit-user-save').click();
 
         // Login as user and check if pipeline is visible to user
-        cy.switchUser(user);
+        UserUtils.switchUser(user);
 
         cy.dataCy('navigation-icon', { timeout: 10000 }).should(
             'have.length',
@@ -97,7 +97,7 @@ describe('Test User Roles for Pipelines', () => {
         );
 
         // Delete user
-        cy.switchUser(UserUtils.adminUser);
+        UserUtils.switchUser(UserUtils.adminUser);
         UserUtils.deleteUser(user);
     });
 });
diff --git a/ui/cypress/tests/userManagement/testVariousUserRoles.smoke.spec.ts 
b/ui/cypress/tests/userManagement/testVariousUserRoles.smoke.spec.ts
index d64bfef8d7..7f0049b87f 100644
--- a/ui/cypress/tests/userManagement/testVariousUserRoles.smoke.spec.ts
+++ b/ui/cypress/tests/userManagement/testVariousUserRoles.smoke.spec.ts
@@ -64,7 +64,7 @@ for (var i = 0; i < testedRoles.length; i++) {
             );
 
             // Login as user
-            cy.switchUser(user);
+            UserUtils.switchUser(user);
 
             // Check if every role displays correct navigation menu
             if (testRole == UserRole.ROLE_PIPELINE_ADMIN) {
@@ -95,7 +95,7 @@ for (var i = 0; i < testedRoles.length; i++) {
             }
 
             // Login as admin and delete user
-            cy.switchUser(UserUtils.adminUser);
+            UserUtils.switchUser(UserUtils.adminUser);
             UserUtils.deleteUser(user);
         });
     });

Reply via email to