tenthe commented on code in PR #3399:
URL: https://github.com/apache/streampipes/pull/3399#discussion_r1901893907
##########
ui/cypress/tests/userManagement/testVariousUserRoles.smoke.spec.ts:
##########
@@ -66,15 +73,15 @@ for (var i = 0; i < testedRoles.length; i++) {
// Check if every role displays correct navigation menu
if (testRole == UserRole.ROLE_PIPELINE_ADMIN) {
- GeneralUtils.validateAmountOfNavigationIcons(4);
+ NavigationUtils.pipelinesIsDisplayed();
} else if (testRole == UserRole.ROLE_DASHBOARD_ADMIN) {
- GeneralUtils.validateAmountOfNavigationIcons(4);
+ NavigationUtils.dashboardIsDisplayed();
} else if (testRole == UserRole.ROLE_DATA_EXPLORER_ADMIN) {
- GeneralUtils.validateAmountOfNavigationIcons(4);
+ NavigationUtils.dataExplorerIsDisplayed();
} else if (testRole == UserRole.ROLE_CONNECT_ADMIN) {
- GeneralUtils.validateAmountOfNavigationIcons(3);
+ NavigationUtils.connectIsDisplayed();
} else if (testRole == UserRole.ROLE_ASSET_ADMIN) {
- GeneralUtils.validateAmountOfNavigationIcons(3);
+ NavigationUtils.assetManagementIsDisplayed();
Review Comment:
Yes, you are right. I thought of that, but then we would always need a block
like this:
```typescript
NavigationUtils.pipelinesIsDisplayed();
NavigationUtils.connectIsDisplayed();
NavigationUtils.dashboardIsDisplayed();
NavigationUtils.dataExplorerIsDisplayed();
NavigationUtils.assetManagementNotDisplayed();
NavigationUtils.configurationIsDisplayed();
```
This is quite hard to read and understand.
I could change the API of `NavigationUtils` to take a list of strings
representing all the modules that should be displayed. This way, we can
validate that only the specified modules are shown. Additionally, I could add
all the module names as static variables to the class to make the API easier to
use.
### Updated API Code
```typescript
export class NavigationUtils {
// Static variables for module names
public static readonly PIPELINES = 'pipelines';
public static readonly CONNECT = 'connect';
public static readonly DASHBOARD = 'dashboard';
public static readonly DATA_EXPLORER = 'dataexplorer';
public static readonly ASSET_MANAGEMENT = 'assets';
public static readonly CONFIGURATION = 'configuration';
/**
* Validates that only the specified navigation icons are displayed.
* @param displayedModules List of module names that should be visible.
*/
public static validateActiveModules(displayedModules: string[]) {
const allModules = [
NavigationUtils.PIPELINES,
NavigationUtils.CONNECT,
NavigationUtils.DASHBOARD,
NavigationUtils.DATA_EXPLORER,
NavigationUtils.ASSET_MANAGEMENT,
NavigationUtils.CONFIGURATION,
];
allModules.forEach((module) => {
const shouldBeDisplayed = displayedModules.includes(module);
this.validateNavigationIcon(module, shouldBeDisplayed);
});
}
/**
* Validates the visibility of a navigation icon.
* @param icon The icon identifier.
* @param shown Whether the icon should be shown.
*/
private static validateNavigationIcon(icon: string, shown: boolean) {
const expectedLength = shown ? 1 : 0;
cy.dataCy(`navigation-icon-${icon}`, { timeout: 10000 }).should(
'have.length',
expectedLength,
);
}
}
```
### Usage Example
```typescript
// Validate that only the specified modules are displayed
NavigationUtils.validateActiveModules([
NavigationUtils.PIPELINES,
NavigationUtils.CONNECT,
NavigationUtils.DASHBOARD,
NavigationUtils.CONFIGURATION,
]);
```
What do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]