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

chore(e2e): add e2e tests for global header #2412

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ciiay
Copy link
Contributor

@ciiay ciiay commented Feb 18, 2025

Description

Update e2e tests for global header.

Changes including:

  1. enabled global-header plugin in "showcase-rabc" and "showcase" test values
  2. added support field to the default configMap app-config-rhdh.yaml
  3. enabled notifications plugins to as it's a default component in global header
  4. added appConfig field to upstream.backstage config in order to test notification unread amount badge
  5. replaced openSidebar("Settings") with a new uiHelper function goToSettingsPage()`
  6. added default-global-header.spec.ts
  7. replaced openSidebar("Create...") with new clickLinkByAriaLabel("Create...")
  8. updated getByPlaceholder("Search") to getByPlaceholder("Search", { exact: true }) so that it only specify the filter search element from main content
  9. added a few new uiHelper functions

Which issue(s) does this PR fix

PR acceptance criteria

Please make sure that the following steps are complete:

  • GitHub Actions are completed and successful
  • Unit Tests are updated and passing
  • E2E Tests are updated and passing
  • Documentation is updated if necessary (requirement for new features)
  • Add a screenshot if the change is UX/UI related

How to test changes / Special notes to the reviewer

Copy link

openshift-ci bot commented Feb 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign subhashkhileri for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ciiay
Copy link
Contributor Author

ciiay commented Feb 19, 2025

/test e2e-tests

@ciiay ciiay force-pushed the rhidp-5474-e2e-test-for-global-header branch from 741341b to b49056d Compare February 19, 2025 16:17
@ciiay ciiay changed the title [WIP]fix(global-header): add e2e tests for global header fix(global-header): add e2e tests for global header Feb 19, 2025
@ciiay ciiay changed the title fix(global-header): add e2e tests for global header chore(e2e): add e2e tests for global header Feb 19, 2025
@ciiay ciiay force-pushed the rhidp-5474-e2e-test-for-global-header branch from 845f5a7 to 99f4cbf Compare February 19, 2025 23:36
@ciiay ciiay force-pushed the rhidp-5474-e2e-test-for-global-header branch from 6f6fd76 to 8dfbd1b Compare February 20, 2025 13:41
@ciiay
Copy link
Contributor Author

ciiay commented Feb 20, 2025

/test e2e-tests

Signed-off-by: Yi Cai <[email protected]>
@@ -445,7 +445,8 @@ for (const version of ["RHBK"]) {
expect(statusBefore).toBe(403);

// logout
await uiHelper.openSidebar("Settings");
await uiHelper.clickByDataTestId("KeyboardArrowDownOutlinedIcon");
Copy link
Member

Choose a reason for hiding this comment

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

what if there are multiple Icon on sidebar? instead can we click based on the nav item like setting?

"[data-testid='KeyboardArrowDownOutlinedIcon']",
);
await profileDropdown.click();
expect(await uiHelper.isLinkVisible("Settings")).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(await uiHelper.isLinkVisible("Settings")).toBeTruthy();
await uiHelper.verifyLink("Settings");

similarly can we replace all expect(await isLinkVisible.()) as above?

@@ -95,6 +95,26 @@ export class UIhelper {
await this.page.locator(`a`).filter({ hasText: linkText }).first().click();
}

async clickLinkByAriaLabel(ariaLabel: string) {
await this.page.locator(`div[aria-label='${ariaLabel}'] a`).first().click();
Copy link
Member

@subhashkhileri subhashkhileri Feb 24, 2025

Choose a reason for hiding this comment

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

you can update the existing clickLink() method to handle this locator.


async goToSettingsPage() {
await expect(this.page.locator("nav[id='global-header']")).toBeVisible();
await this.clickByDataTestId("KeyboardArrowDownOutlinedIcon");
Copy link
Member

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

We should find the item by the label, not the icon

await link.dispatchEvent("click");
}

async clickPbyText(text: string) {
Copy link
Member

Choose a reason for hiding this comment

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

lets not create methods for tags, you can directly use this await this.page.locator(p).getByText(text).first().click(); in test instead of putting here.

@@ -150,11 +170,21 @@ export class UIhelper {
return await this.isElementVisible(locator, timeout);
}

async isSearchBarVisible(): Promise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

you may directly use expect(await this.isElementVisible(locator)).toBeTruthy(); in test instead of new method in uihelper.

Idea is to have generic methods in uihelper while keeping it small. if you still want you can move it to respective pages under e2e-tests/playwright/support/pages and the locators to e2e-tests/playwright/support/pageObjects

async isLinkVisible(text: string): Promise<boolean> {
const locator = `a:has-text("${text}")`;
return await this.isElementVisible(locator);
}

async isLinkVisibleByLabel(label: string): Promise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

instead of new method you may update verifyLink() to handle this.

await this.page.locator(`div[aria-label='${ariaLabel}'] a`).first().click();
}

async clickLinkByHref(href: string) {
Copy link
Member

Choose a reason for hiding this comment

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

you can update the existing clickLink() method to handle this

async clickLinkByHref(href: string) {
const link = this.page.locator(`a[href="${href}"]`);
await link.waitFor({ state: "visible" });
await link.dispatchEvent("click");
Copy link
Member

@subhashkhileri subhashkhileri Feb 24, 2025

Choose a reason for hiding this comment

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

Suggested change
await link.dispatchEvent("click");
await link.click({force:true});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants