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

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


The following commit(s) were added to 
refs/heads/3956-create-e2e-test-to-validate-permissions-for-charts by this push:
     new 5c74be9fdc refactor(#3956): Add e2e test for charts
5c74be9fdc is described below

commit 5c74be9fdc3fd61da4573aafa654f53a6ae629c0
Author: Philipp Zehnder <[email protected]>
AuthorDate: Mon Nov 24 16:26:59 2025 +0100

    refactor(#3956): Add e2e test for charts
---
 .../utils/dataExplorer/DataExplorerUtils.ts        |  39 +++++-
 .../userManagement/testUserRoleCharts.spec.ts      | 156 +++++++++++++++++++++
 .../data-explorer-overview-table.component.html    |   6 +-
 ui/src/app/data-explorer/data-explorer.routes.ts   |   2 +-
 4 files changed, 197 insertions(+), 6 deletions(-)

diff --git a/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts 
b/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts
index 341a9153a9..752816d319 100644
--- a/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts
+++ b/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts
@@ -38,6 +38,29 @@ export class DataExplorerUtils {
         cy.visit('#/dashboard');
     }
 
+    public static checkAmountOfCharts(amount: number) {
+        DataExplorerUtils.goToDatalake();
+
+        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 {
+            ConnectBtns.moreOptions().should('have.length', amount);
+        }
+    }
+
+    public static checkChartCanBeEdited(chartName: string) {
+        GeneralUtils.openMenuForRow(chartName);
+        DataExplorerBtns.editDataViewButton(chartName).should('exist');
+    }
+
+    public static checkChartCanNotBeEdited(chartName: string) {
+        GeneralUtils.openMenuForRow(chartName);
+        DataExplorerBtns.editDataViewButton(chartName).should('not.exist');
+    }
+
     public static initDataLakeTests() {
         cy.initStreamPipesTest();
         DataExplorerUtils.loadRandomDataSetIntoDataLake();
@@ -95,14 +118,18 @@ export class DataExplorerUtils {
         dataViewName: string,
         dataSet: string,
         widgetType: string,
+        ignoreTimeSelection = false,
     ) {
         DataExplorerUtils.goToDatalake();
         DataExplorerUtils.createAndEditDataView();
 
-        DataExplorerUtils.selectTimeRange(
-            new Date(2020, 10, 20, 22, 44),
-            DataExplorerUtils.getFutureDate(),
-        );
+        if (!ignoreTimeSelection) {
+            DataExplorerUtils.selectTimeRange(
+                new Date(2020, 10, 20, 22, 44),
+                DataExplorerUtils.getFutureDate(),
+            );
+        }
+
         // DataExplorerUtils.addNewWidget();
         DataExplorerUtils.selectDataSet(dataSet);
         DataExplorerUtils.dataConfigSelectAllFields();
@@ -115,6 +142,7 @@ export class DataExplorerUtils {
 
         cy.wait(1000);
     }
+
     public static addAssetsToDashboard(assetNameList) {
         cy.dataCy('sp-show-dashboard-asset-checkbox')
             .find('input[type="checkbox"]')
@@ -140,6 +168,7 @@ export class DataExplorerUtils {
         // Configure data view
         cy.dataCy('data-view-name').type(name);
     }
+
     public static createDashboardWithLinkedAssets(
         dataView,
         name,
@@ -165,11 +194,13 @@ export class DataExplorerUtils {
     public static addDataViewAndTableWidget(
         dataViewName: string,
         dataSet: string,
+        ignoreTimeSelection = false,
     ) {
         this.addDataViewAndWidget(
             dataViewName,
             dataSet,
             DataExplorerWidget.TABLE,
+            ignoreTimeSelection,
         );
     }
 
diff --git a/ui/cypress/tests/userManagement/testUserRoleCharts.spec.ts 
b/ui/cypress/tests/userManagement/testUserRoleCharts.spec.ts
new file mode 100644
index 0000000000..cceb05fcad
--- /dev/null
+++ b/ui/cypress/tests/userManagement/testUserRoleCharts.spec.ts
@@ -0,0 +1,156 @@
+import { UserRole } from '../../../src/app/_enums/user-role.enum';
+import { UserUtils } from '../../support/utils/UserUtils';
+import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
+import { User } from '../../support/model/User';
+import { DataExplorerUtils } from 
'../../support/utils/dataExplorer/DataExplorerUtils';
+import { PermissionUtils } from '../../support/utils/user/PermissionUtils';
+
+describe('Test User Roles for Charts', () => {
+    const chartName = 'test-chart';
+    let chartUser1: User;
+    let chartAdmin1: User;
+    let chartAdmin2: User;
+
+    beforeEach('Setup Test', () => {
+        cy.initStreamPipesTest();
+
+        chartUser1 = UserUtils.createUser(
+            'chartUser1',
+            UserRole.ROLE_DATA_EXPLORER_USER,
+        );
+
+        chartAdmin1 = UserUtils.createUser(
+            'chartAdmin1',
+            UserRole.ROLE_DATA_EXPLORER_ADMIN,
+            UserRole.ROLE_CONNECT_ADMIN,
+            UserRole.ROLE_PIPELINE_ADMIN,
+        );
+
+        chartAdmin2 = UserUtils.createUser(
+            'chartAdmin2',
+            UserRole.ROLE_DATA_EXPLORER_ADMIN,
+        );
+    });
+
+    it('Chart is not shared with other users', () => {
+        setup();
+
+        // check admin
+        assertChartIsVisibleAndEditableCanChangePermissions(
+            UserUtils.adminUser,
+        );
+
+        // check other users
+        assertChartIsNotVisible(chartAdmin2);
+    });
+
+    it('Make chart public', () => {
+        setup();
+
+        PermissionUtils.markElementAsPublic(chartName);
+
+        assertChartIsVisibleAndEditableCanChangePermissions(
+            UserUtils.adminUser,
+        );
+
+        assertChartIsVisibleButNotEditable(chartUser1);
+
+        assertChartIsVisibleAndEditableCannotChangePermissions(chartAdmin2);
+    });
+
+    it('Share chart with other user and change ownership', () => {
+        setup();
+
+        PermissionUtils.authorizeUser(chartName, chartAdmin2.email);
+
+        assertChartIsVisibleAndEditableCanChangePermissions(
+            UserUtils.adminUser,
+        );
+
+        assertChartIsVisibleAndEditableCannotChangePermissions(chartAdmin2);
+
+        assertChartIsNotVisible(chartUser1);
+
+        UserUtils.switchUser(chartAdmin1);
+        DataExplorerUtils.goToDatalake();
+        PermissionUtils.changeOwnership(chartName, chartAdmin2.email);
+
+        assertChartIsNotVisible(chartAdmin1);
+
+        assertChartIsVisibleAndEditableCanChangePermissions(
+            UserUtils.adminUser,
+        );
+
+        assertChartIsVisibleAndEditableCanChangePermissions(chartAdmin2);
+
+        assertChartIsNotVisible(chartUser1);
+    });
+
+    it('Chart is shared with group for user 2', () => {
+        const chartAdminGroup = 'chart_admin_group';
+        UserUtils.createGroup(
+            chartAdminGroup,
+            UserRole.ROLE_DATA_EXPLORER_ADMIN,
+        );
+        UserUtils.addGroupToUser(chartAdminGroup, chartAdmin2.name);
+
+        setup();
+
+        PermissionUtils.authorizeGroup(chartName, chartAdminGroup);
+
+        assertChartIsVisibleAndEditableCanChangePermissions(
+            UserUtils.adminUser,
+        );
+
+        assertChartIsNotVisible(chartUser1);
+
+        assertChartIsVisibleAndEditableCannotChangePermissions(chartAdmin2);
+    });
+
+    function setup() {
+        UserUtils.switchUser(chartAdmin1);
+        ConnectUtils.addMachineDataSimulator('simulator', true);
+        DataExplorerUtils.addDataViewAndTableWidget(
+            chartName,
+            'simulator',
+            true,
+        );
+        DataExplorerUtils.saveDataViewConfiguration();
+        DataExplorerUtils.goToDatalake();
+    }
+
+    function assertChartIsVisibleAndEditableCanChangePermissions(user: User) {
+        UserUtils.switchUser(user);
+        DataExplorerUtils.goToDatalake();
+        DataExplorerUtils.checkAmountOfCharts(1);
+        DataExplorerUtils.checkChartCanBeEdited(chartName);
+
+        PermissionUtils.validateUserCanChangePermissions(chartName);
+    }
+
+    function assertChartIsVisibleAndEditableCannotChangePermissions(
+        user: User,
+    ) {
+        UserUtils.switchUser(user);
+        DataExplorerUtils.goToDatalake();
+        DataExplorerUtils.checkAmountOfCharts(1);
+        DataExplorerUtils.checkChartCanBeEdited(chartName);
+
+        PermissionUtils.validateUserCanNotChangePermissions(chartName);
+    }
+
+    function assertChartIsVisibleButNotEditable(user: User) {
+        UserUtils.switchUser(user);
+        DataExplorerUtils.goToDatalake();
+        DataExplorerUtils.checkAmountOfCharts(1);
+        DataExplorerUtils.checkChartCanNotBeEdited(chartName);
+
+        PermissionUtils.validateUserCanNotChangePermissions(chartName);
+    }
+
+    function assertChartIsNotVisible(user: User) {
+        UserUtils.switchUser(user);
+        DataExplorerUtils.goToDatalake();
+        DataExplorerUtils.checkAmountOfCharts(0);
+    }
+});
diff --git 
a/ui/src/app/data-explorer/components/overview/data-explorer-overview-table/data-explorer-overview-table.component.html
 
b/ui/src/app/data-explorer/components/overview/data-explorer-overview-table/data-explorer-overview-table.component.html
index 4c5b75954b..8d4048be29 100644
--- 
a/ui/src/app/data-explorer/components/overview/data-explorer-overview-table/data-explorer-overview-table.component.html
+++ 
b/ui/src/app/data-explorer/components/overview/data-explorer-overview-table/data-explorer-overview-table.component.html
@@ -103,7 +103,11 @@
                         <span>{{ 'Edit chart' | translate }}</span>
                     </button>
                 }
-                <button mat-menu-item (click)="showPermissionsDialog(element)">
+                <button
+                    data-cy="open-manage-permissions"
+                    mat-menu-item
+                    (click)="showPermissionsDialog(element)"
+                >
                     <mat-icon>share</mat-icon>
                     <span>{{ 'Manage permissions' | translate }}</span>
                 </button>
diff --git a/ui/src/app/data-explorer/data-explorer.routes.ts 
b/ui/src/app/data-explorer/data-explorer.routes.ts
index 6552edfd7a..4d4f08dc86 100644
--- a/ui/src/app/data-explorer/data-explorer.routes.ts
+++ b/ui/src/app/data-explorer/data-explorer.routes.ts
@@ -20,7 +20,7 @@ import { SpBreadcrumbItem } from '@streampipes/shared-ui';
 
 export class SpDataExplorerRoutes {
     static BASE: SpBreadcrumbItem = {
-        label: 'Data Explorer',
+        label: 'Charts',
         link: ['dataexplorer'],
     };
 }

Reply via email to