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

OverlayPanel: Panel stays hidden and inaccessible in jest / testing-library setup #14532

Closed
angelo-v opened this issue Jan 11, 2024 · 8 comments
Assignees
Labels
Status: Discussion Issue or pull request needs to be discussed by Core Team Status: Pending Review Issue or pull request is being reviewed by Core Team

Comments

@angelo-v
Copy link

angelo-v commented Jan 11, 2024

Describe the bug

We noticed this initially with the Dropdown component. In a jest test using testing library the options list does not show up when clicking in the Dropdown. We could reproduce it with a plain OverlayPanel, which has the same issue. When it should open it stays hidden with style "display:none" instead of showing up.

Test result:

Unable to find role="listbox"

But it is there:

<ul
  class="p-dropdown-items ng-star-inserted"
  id="pn_id_1_list"
  role="listbox"
>

The problem seems to be, that it is wrapped in a hidden overlay:

<div
  class="ng-tns-c3177733119-0 p-overlay p-component ng-star-inserted"
  [...]
  style="[...] display: none;[...]"
>

Environment

  • angular 17.0.8
  • primeng 17.3.1
  • jest 29.4.1
  • testing-library/angular 15.1.0
  • testing-library/jest-dom 6.2.0

Reproducer

No response

Angular version

17.0.8

PrimeNG version

17.3.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v20.10.0

Browser(s)

jsdom

Steps to reproduce the behavior

  1. Create a Cities component like in the basic example https://primeng.org/dropdown#basic
  2. Add a label "City" to it
  3. Write and execute a test like this
  it('can be opened', async () => {
    await render(CitiesComponent, {
      providers: [provideNoopAnimations()],
    });
    const select = screen.getByLabelText('City');
    await userEvent.click(select);
    expect(await screen.findByRole('listbox', {hidden: true})).toBeInTheDocument(); // this works
    expect(await screen.findByRole('listbox')).toBeInTheDocument(); // this fails
  });

Expected behavior

The overlay should be visible and the test should find the listbox

@angelo-v angelo-v added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 11, 2024
@mertsincan
Copy link
Member

Thanks a lot for the detail description! I set a milestone and we'll check this issue before the milestone is released.

@mertsincan mertsincan added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jan 16, 2024
@mertsincan mertsincan added this to the 17.4.0 milestone Jan 16, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.4.0, 17.5.0 Jan 24, 2024
@cetincakiroglu
Copy link
Contributor

Hi,

Could you please create a repo or stackblitz example so we can replicate and easily isolate the issue? By default, we're using karma and configuring a new test environment to replicate the issue is time-consuming since we're currently focused on passthrough and unstyled. Please tag me when the example is ready to investigate. Thanks a lot for reporting the issue.

Moving to 17.6.0 milestone until the example arrives.

@cetincakiroglu cetincakiroglu modified the milestones: 17.5.0, 17.6.0 Feb 1, 2024
@cetincakiroglu cetincakiroglu added the Resolution: Needs More Information More information about the issue is needed to find a correct solution label Feb 1, 2024
@cetincakiroglu cetincakiroglu self-assigned this Feb 1, 2024
@angelo-v
Copy link
Author

angelo-v commented Feb 7, 2024

Hi @cetincakiroglu here is the stackblitz example:

https://stackblitz.com/edit/stackblitz-starters-tvtf2l?file=README.md

It should be easily reproducable with that, but let me know if you have further questions.

@cetincakiroglu
Copy link
Contributor

Hi @angelo-v ,

Thank you for the example, we are trying to identify the source of the problem, and this requires some more time since it doesn't happen with karma. To better understand the issue and to continue investigating, I am moving it to the 17.7.0 milestone.

@cetincakiroglu cetincakiroglu removed the Resolution: Needs More Information More information about the issue is needed to find a correct solution label Feb 7, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.6.0, 17.7.0 Feb 7, 2024
@cetincakiroglu
Copy link
Contributor

cetincakiroglu commented Feb 14, 2024

Hi,

We're investigating the issue, we've downloaded your example and it throws many unrelated errors with the test case. I've tried to reproduce the test in Karma with similar steps to yours. Interestingly, it works with Karma. It's a long shot but you can add a slight delay of a few milliseconds to the place where you are trying to find an element with the "option" role in the test environment you are using. You may be trying to find the option at the exact moment you click, and the overlay is not visible at that moment.

    it('all options should be visible', () => {
        fixture.componentInstance.options = [
            { label: 'New York', value: 'NY' },
            { label: 'Rome', value: 'RM' },
            { label: 'London', value: 'LDN' },
            { label: 'Istanbul', value: 'IST' },
            { label: 'Paris', value: 'PRS' }
        ];
        fixture.detectChanges();

        const containerEl = fixture.debugElement.query(By.css('.p-dropdown')).nativeElement;
        containerEl.click();
        const items = fixture.debugElement.query(By.css('.p-dropdown-items'));
        expect(items.nativeElement.children.length).toEqual(5);
    });

Moving it to the next milestone while investigating the issue.

@cetincakiroglu cetincakiroglu modified the milestones: 17.7.0, 17.8.0 Feb 14, 2024
@cetincakiroglu cetincakiroglu added the Status: Discussion Issue or pull request needs to be discussed by Core Team label Feb 14, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.8.0, 17.9.0 Feb 23, 2024
@angelo-v
Copy link
Author

Thanks for investigating! What unrelated errors are you speaking of? Running the example in stackblitz does not give me any unrelated errors.

It's a long shot but you can add a slight delay of a few milliseconds to the place where you are trying to find an element with the "option" role

This is implicitly done by using testing-libray findBy* method. The last test waits for a full second for the element to appear, but it never does.

containerEl.click();
const items = fixture.debugElement.query(By.css('.p-dropdown-items'));
expect(items.nativeElement.children.length).toEqual(5);

Your test only checks wether the items can be found in the dom, it does not test, whether they are actually accessible (visible). The latter is not the case. As you can see in my second test case (expect(await screen.findByRole('option', { hidden: true })).toBeVisible()), the options can be found, but they are not visible.

As you can see in the DOM output, they are placed inside a hidden (display: none) overlay:

<div
          aria-modal="true"
          class="ng-trigger ng-trigger-animation ng-tns-c2474639176-0 p-overlaypanel p-component ng-star-inserted"
          ng-reflect-ng-class="p-overlaypanel p-component"
          role="dialog"
          style="z-index: 1002; visibility: visible; display: none; transform-origin: top; top: 0px; left: 0px; --overlayArrowLeft: 0px; transform: translateY(0); opacity: 1;"
        >

@cetincakiroglu
Copy link
Contributor

Hi,

Thanks for the feedback, we'll check this in the 17.10.0 again.

@cetincakiroglu cetincakiroglu modified the milestones: 17.9.0, 17.10.0, 17.11.0 Feb 29, 2024
@cetincakiroglu cetincakiroglu removed this from the 17.11.0 milestone Mar 14, 2024
@cetincakiroglu cetincakiroglu added this to the 17.Future milestone Mar 14, 2024
@mehmetcetin01140
Copy link
Contributor

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

@github-project-automation github-project-automation bot moved this to Done in PrimeNG Dec 16, 2024
@mehmetcetin01140 mehmetcetin01140 removed this from the 19.x milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Discussion Issue or pull request needs to be discussed by Core Team Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
None yet
Development

No branches or pull requests

4 participants