Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(#3398): Add control flow syntax to icon bar and improved e2e tests #3399

Merged
merged 3 commits into from
Jan 7, 2025

Conversation

tenthe
Copy link
Contributor

@tenthe tenthe commented Jan 3, 2025

Purpose

This PR introduces the following improvements:

  1. Refactoring the Icon Bar Component:

    • Migrated the icon bar component to leverage Angular's control flow syntax (@for and @if) for enhanced readability and maintainability.
    • Updated the iconbar.component.html to include dynamic data-cy attributes for improved test targeting.
  2. Enhanced End-to-End Tests:

    • Replaced the generic validateAmountOfNavigationIcons method with specific assertions for individual navigation icons (e.g., pipelinesIsDisplayed).
    • Introduced a new NavigationUtils utility to manage navigation icon assertions in a modular and reusable way.

Remarks

PR introduces (a) breaking change(s): no

PR introduces (a) deprecation(s): no

@tenthe tenthe linked an issue Jan 3, 2025 that may be closed by this pull request
@github-actions github-actions bot added dependencies Pull requests that update a dependency file ui Anything that affects the UI testing Relates to any kind of test (unit test, integration, or E2E test). labels Jan 3, 2025
} else if (testRole == UserRole.ROLE_ASSET_ADMIN) {
GeneralUtils.validateAmountOfNavigationIcons(3);
NavigationUtils.assetManagementIsDisplayed();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, during the test for the ROLE_ASSET, all navigation icons could be visible (including those that shouldn't be), and the test would still pass, even though a user with the Asset-role shouldn't see all the icons, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I thought of that, but then we would always need a block like this:

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

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

// Validate that only the specified modules are displayed
NavigationUtils.validateActiveModules([
    NavigationUtils.PIPELINES,
    NavigationUtils.CONNECT,
    NavigationUtils.DASHBOARD,
    NavigationUtils.CONFIGURATION,
]);

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks great! I believe this approach makes it easier to verify that the user roles behave as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marcelfrueh, I have changed the code accordingly. Please take a look at this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@tenthe tenthe merged commit b86750a into dev Jan 7, 2025
22 checks passed
@tenthe tenthe deleted the 3398-migrate-iconbar-component-to-control-flow-syntax branch January 7, 2025 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file testing Relates to any kind of test (unit test, integration, or E2E test). ui Anything that affects the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate IconBar Component to Control Flow Syntax
2 participants