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

zehnder pushed a commit to branch add-e2e-test-for-asset-permissions
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit 3051a10d69553336c4b8b840a0375c3d3995f5e5
Author: Philipp Zehnder <[email protected]>
AuthorDate: Tue Nov 25 13:45:22 2025 +0100

    feat: Add e2e test for asset roles
---
 ui/cypress/support/utils/asset/AssetUtils.ts       |  23 +++-
 .../assetManagement/generalAssetTest.smoke.spec.ts |   2 -
 .../dataExplorer/addAssetsToDataView.smoke.spec.ts |   3 -
 .../userManagement/testUserRoleAssets.spec.ts      | 146 +++++++++++++++++++++
 .../asset-overview/asset-overview.component.html   |   5 +-
 5 files changed, 169 insertions(+), 10 deletions(-)

diff --git a/ui/cypress/support/utils/asset/AssetUtils.ts 
b/ui/cypress/support/utils/asset/AssetUtils.ts
index bbed4c184a..b40211b4c4 100644
--- a/ui/cypress/support/utils/asset/AssetUtils.ts
+++ b/ui/cypress/support/utils/asset/AssetUtils.ts
@@ -23,7 +23,7 @@ import { GeneralUtils } from '../GeneralUtils';
 export class AssetUtils {
     public static goToAssets() {
         cy.visit('#/assets/overview');
-        cy.dataCy('create-new-asset-button').should('be.visible');
+        cy.dataCy('asset-title').should('be.visible');
     }
 
     public static goBackToOverview() {
@@ -58,7 +58,16 @@ export class AssetUtils {
     }
 
     public static checkAmountOfAssets(amount: number) {
-        cy.dataCy('assets-table').should('have.length', amount);
+        AssetUtils.goToAssets();
+
+        if (amount === 0) {
+            // The wait is needed because the default value is the 
no-table-entries element.
+            // It must be waited till the data is loaded. Once a better 
solution is found, this can be removed.
+            cy.wait(1000);
+            cy.dataCy('no-table-entries').should('be.visible');
+        } else {
+            cy.dataCy('assets-table').should('have.length', amount);
+        }
     }
 
     public static checkAmountOfLinkedResources(amount: number) {
@@ -67,6 +76,16 @@ export class AssetUtils {
             .should('have.length', amount);
     }
 
+    public static checkAssetCanBeEdited(assetName: string) {
+        GeneralUtils.openMenuForRow(assetName);
+        AssetBtns.editAssetBtn(assetName).should('exist');
+    }
+
+    public static checkAssetCanNotBeEdited(assetName: string) {
+        GeneralUtils.openMenuForRow(assetName);
+        AssetBtns.editAssetBtn(assetName).should('not.exist');
+    }
+
     public static checkAmountOfAssetsGreaterThan(amount: number) {
         cy.dataCy('assets-table', { timeout: 10000 }).should(
             'have.length.greaterThan',
diff --git a/ui/cypress/tests/assetManagement/generalAssetTest.smoke.spec.ts 
b/ui/cypress/tests/assetManagement/generalAssetTest.smoke.spec.ts
index f19bb1d79a..82d6467a0f 100644
--- a/ui/cypress/tests/assetManagement/generalAssetTest.smoke.spec.ts
+++ b/ui/cypress/tests/assetManagement/generalAssetTest.smoke.spec.ts
@@ -32,7 +32,6 @@ describe('Creates a new adapter, add to assets', () => {
 
         // // Leave and navigate back to Assets
         DashboardUtils.goToDashboard();
-        AssetUtils.goToAssets();
         AssetUtils.checkAmountOfAssets(1);
 
         // Check that everything was stored correctly
@@ -41,7 +40,6 @@ describe('Creates a new adapter, add to assets', () => {
         AssetUtils.checkAmountOfLinkedResources(2);
 
         // Check that deletion of asset works
-        AssetUtils.goToAssets();
         AssetUtils.checkAmountOfAssets(1);
         AssetUtils.deleteAsset(assetName);
         AssetUtils.checkAmountOfAssets(0);
diff --git a/ui/cypress/tests/dataExplorer/addAssetsToDataView.smoke.spec.ts 
b/ui/cypress/tests/dataExplorer/addAssetsToDataView.smoke.spec.ts
index 30b407d8b7..4c8637a846 100644
--- a/ui/cypress/tests/dataExplorer/addAssetsToDataView.smoke.spec.ts
+++ b/ui/cypress/tests/dataExplorer/addAssetsToDataView.smoke.spec.ts
@@ -34,7 +34,6 @@ describe('Creates a new adapter with a linked asset', () => {
 
     it('Add Assets during Chart generation', () => {
         DataExplorerUtils.createDataViewWithAssets([assetName1, assetName2]);
-        AssetUtils.goToAssets();
         AssetUtils.checkAmountOfAssets(3);
         //Test
         AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName1, 1);
@@ -43,7 +42,6 @@ describe('Creates a new adapter with a linked asset', () => {
 
     it('Edit Assets during Chart generation', () => {
         DataExplorerUtils.createDataViewWithAssets([assetName1, assetName2]);
-        AssetUtils.goToAssets();
         AssetUtils.checkAmountOfAssets(3);
         //Test
         AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName1, 1);
@@ -58,7 +56,6 @@ describe('Creates a new adapter with a linked asset', () => {
         //Neceassary for Background Task to finish
         cy.wait(500);
 
-        AssetUtils.goToAssets();
         AssetUtils.checkAmountOfAssets(3);
         AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName2, 1);
         AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName3, 1);
diff --git a/ui/cypress/tests/userManagement/testUserRoleAssets.spec.ts 
b/ui/cypress/tests/userManagement/testUserRoleAssets.spec.ts
new file mode 100644
index 0000000000..ede70029fc
--- /dev/null
+++ b/ui/cypress/tests/userManagement/testUserRoleAssets.spec.ts
@@ -0,0 +1,146 @@
+/*
+ * 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 { UserRole } from '../../../src/app/_enums/user-role.enum';
+import { UserUtils } from '../../support/utils/UserUtils';
+import { User } from '../../support/model/User';
+import { AssetUtils } from '../../support/utils/asset/AssetUtils';
+import { PermissionUtils } from '../../support/utils/user/PermissionUtils';
+
+describe('Test User Roles for Dashboards', () => {
+    const assetName = 'test-asset';
+    let assetUser1: User;
+    let assetAdmin1: User;
+    let assetAdmin2: User;
+
+    beforeEach('Setup Test', () => {
+        cy.initStreamPipesTest();
+
+        assetUser1 = UserUtils.createUser(
+            'assetUser1',
+            UserRole.ROLE_ASSET_USER,
+        );
+
+        assetAdmin1 = UserUtils.createUser(
+            'assetAdmin1',
+            UserRole.ROLE_ASSET_ADMIN,
+        );
+
+        assetAdmin2 = UserUtils.createUser(
+            'assetAdmin2',
+            UserRole.ROLE_ASSET_ADMIN,
+        );
+    });
+
+    it('Asset is not shared with other users', () => {
+        setup();
+
+        // check admin
+        assetIsVisibleAndEditableCanChangePermissions(UserUtils.adminUser);
+
+        // check other users
+        assetIsNotVisible(assetAdmin2);
+    });
+
+    it('Make asset public', () => {
+        setup();
+
+        PermissionUtils.markElementAsPublic(assetName);
+
+        assetIsVisibleAndEditableCanChangePermissions(UserUtils.adminUser);
+
+        assetIsVisibleButNotEditable(assetUser1);
+
+        assetIsVisibleAndEditableCannotChangePermissions(assetAdmin2);
+    });
+
+    it('Share asset with other user and change ownership', () => {
+        setup();
+
+        PermissionUtils.authorizeUser(assetName, assetAdmin2.email);
+
+        assetIsVisibleAndEditableCanChangePermissions(UserUtils.adminUser);
+
+        assetIsVisibleAndEditableCannotChangePermissions(assetAdmin2);
+
+        assetIsNotVisible(assetUser1);
+
+        UserUtils.switchUser(assetAdmin1);
+        AssetUtils.goToAssets();
+        PermissionUtils.changeOwnership(assetName, assetAdmin2.email);
+
+        assetIsNotVisible(assetAdmin1);
+
+        assetIsVisibleAndEditableCanChangePermissions(UserUtils.adminUser);
+
+        assetIsVisibleAndEditableCanChangePermissions(assetAdmin2);
+
+        assetIsNotVisible(assetUser1);
+    });
+
+    it('Asset is shared with group for user 2', () => {
+        const assetAdminGroup = 'asset_admin_group';
+        UserUtils.createGroup(assetAdminGroup, UserRole.ROLE_ASSET_ADMIN);
+        UserUtils.addGroupToUser(assetAdminGroup, assetAdmin2.name);
+
+        setup();
+
+        PermissionUtils.authorizeGroup(assetName, assetAdminGroup);
+
+        assetIsVisibleAndEditableCanChangePermissions(UserUtils.adminUser);
+
+        assetIsNotVisible(assetUser1);
+
+        assetIsVisibleAndEditableCannotChangePermissions(assetAdmin2);
+    });
+
+    function setup() {
+        UserUtils.switchUser(assetAdmin1);
+        AssetUtils.goToAssets();
+        AssetUtils.addAndSaveAsset(assetName);
+    }
+
+    function assetIsVisibleAndEditableCanChangePermissions(user: User) {
+        UserUtils.switchUser(user);
+        AssetUtils.checkAmountOfAssets(1);
+        AssetUtils.checkAssetCanBeEdited(assetName);
+
+        PermissionUtils.validateUserCanChangePermissions(assetName);
+    }
+
+    function assetIsVisibleAndEditableCannotChangePermissions(user: User) {
+        UserUtils.switchUser(user);
+        AssetUtils.checkAmountOfAssets(1);
+        AssetUtils.checkAssetCanBeEdited(assetName);
+
+        PermissionUtils.validateUserCanNotChangePermissions(assetName);
+    }
+
+    function assetIsVisibleButNotEditable(user: User) {
+        UserUtils.switchUser(user);
+        AssetUtils.checkAmountOfAssets(1);
+        AssetUtils.checkAssetCanNotBeEdited(assetName);
+
+        PermissionUtils.validateUserCanNotChangePermissions(assetName);
+    }
+
+    function assetIsNotVisible(user: User) {
+        UserUtils.switchUser(user);
+        AssetUtils.checkAmountOfAssets(0);
+    }
+});
diff --git 
a/ui/src/app/assets/components/asset-overview/asset-overview.component.html 
b/ui/src/app/assets/components/asset-overview/asset-overview.component.html
index e3841f1ee5..06711cff8e 100644
--- a/ui/src/app/assets/components/asset-overview/asset-overview.component.html
+++ b/ui/src/app/assets/components/asset-overview/asset-overview.component.html
@@ -48,6 +48,7 @@
     <div fxFlex="100" fxLayout="column">
         <sp-basic-header-title-component
             title="Assets"
+            data-cy="asset-title"
         ></sp-basic-header-title-component>
         <div fxFlex="100" fxLayout="row" fxLayoutAlign="center start">
             <div fxFlex="100" fxLayout="column">
@@ -106,9 +107,7 @@
                         </button>
                         <button
                             mat-menu-item
-                            [attr.data-cy]="
-                                'manage-dashboard-permissions-' + element.name
-                            "
+                            data-cy="open-manage-permissions"
                             (click)="openPermissionsDialog(element)"
                         >
                             <mat-icon>share</mat-icon>

Reply via email to