Skip to content

Conversation

@KawtharAlakri
Copy link
Contributor

@KawtharAlakri KawtharAlakri commented Aug 27, 2024

What is this feature?

Test for the New Select (Combobox)

Why do we need this feature?

Avoid bugs and regression

Who is this feature for?

Developers

Which issue(s) does this PR fix?:

Fixes some points in #92396
Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@CLAassistant
Copy link

CLAassistant commented Aug 27, 2024

CLA assistant check
All committers have signed the CLA.

@grafana-pr-automation grafana-pr-automation bot added area/frontend pr/external This PR is from external contributor labels Aug 27, 2024
@tskarhed tskarhed self-assigned this Aug 27, 2024
@tskarhed
Copy link
Contributor

The issue can be solved by explicitly setting indexAttributeName: 'data-index' in Combobox.tsx.

  const virtualizerOptions = {
    count: items.length,
    getScrollElement: () => floatingRef.current,
    estimateSize,
    overscan: 4,
    indexAttributeName: 'data-index',
  };

@KawtharAlakri
Copy link
Contributor Author

The issue can be solved by explicitly setting indexAttributeName: 'data-index' in Combobox.tsx.

  const virtualizerOptions = {
    count: items.length,
    getScrollElement: () => floatingRef.current,
    estimateSize,
    overscan: 4,
    indexAttributeName: 'data-index',
  };

I tried this in combination with the mocking, issue remained.

@tskarhed
Copy link
Contributor

The issue can be solved by explicitly setting indexAttributeName: 'data-index' in Combobox.tsx.

  const virtualizerOptions = {
    count: items.length,
    getScrollElement: () => floatingRef.current,
    estimateSize,
    overscan: 4,
    indexAttributeName: 'data-index',
  };

I tried this in combination with the mocking, issue remained.

Interesting. That's the only change I did to the current state of the pull request, and now there is only one failing test:

 FAIL  packages/grafana-ui/src/components/Combobox/Combobox.test.tsx
  ● Combobox › should allow selecting a value by clicking directly

    expect(jest.fn()).toHaveBeenCalled()

    Expected number of calls: >= 1
    Received number of calls:    0

      43 |         const item = await screen.findByRole('option', { name: 'Option 1' });
      44 |         userEvent.click(item);
    > 45 |         expect(onChangeHandler).toHaveBeenCalled();
         |                                 ^
      46 |     });
      47 |
      48 |     it('selects value by using keyboard only', async () => {

      at packages/grafana-ui/src/components/Combobox/Combobox.test.tsx:45:33
      at fulfilled (node_modules/tslib/tslib.js:166:62)

But no error like the previous one.

@KawtharAlakri
Copy link
Contributor Author

The issue can be solved by explicitly setting indexAttributeName: 'data-index' in Combobox.tsx.

  const virtualizerOptions = {
    count: items.length,
    getScrollElement: () => floatingRef.current,
    estimateSize,
    overscan: 4,
    indexAttributeName: 'data-index',
  };

I tried this in combination with the mocking, issue remained.

Interesting. That's the only change I did to the current state of the pull request, and now there is only one failing test:

 FAIL  packages/grafana-ui/src/components/Combobox/Combobox.test.tsx
  ● Combobox › should allow selecting a value by clicking directly

    expect(jest.fn()).toHaveBeenCalled()

    Expected number of calls: >= 1
    Received number of calls:    0

      43 |         const item = await screen.findByRole('option', { name: 'Option 1' });
      44 |         userEvent.click(item);
    > 45 |         expect(onChangeHandler).toHaveBeenCalled();
         |                                 ^
      46 |     });
      47 |
      48 |     it('selects value by using keyboard only', async () => {

      at packages/grafana-ui/src/components/Combobox/Combobox.test.tsx:45:33
      at fulfilled (node_modules/tslib/tslib.js:166:62)

But no error like the previous one.

Is it exactly like this ?
image

@tskarhed
Copy link
Contributor

I am sorry @KawtharAlakri , I had accidentally added the changes on top of another branch (#92284) I was working on. Disregard what I mentioned previously. Also, it should've been indexAttribute, I have no idea why that worked for me. I have now merged it into main, maybe you can merge main into your branch?

@KawtharAlakri
Copy link
Contributor Author

@tskarhed I couldn't fix the test case where clicking on item should select it, clicking is not triggering the onChange function, so I commented and updated other test cases. This PR is ready to be reviewed.

@KawtharAlakri KawtharAlakri marked this pull request as ready for review August 28, 2024 08:16
@KawtharAlakri KawtharAlakri requested a review from a team as a code owner August 28, 2024 08:16
@KawtharAlakri KawtharAlakri requested review from L-M-K-B and tskarhed and removed request for a team August 28, 2024 08:16
@github-actions github-actions bot added this to the 11.3.x milestone Aug 28, 2024
@tskarhed tskarhed added the no-changelog Skip including change in changelog/release notes label Aug 28, 2024
Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

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

Looks good in general! Apply the changes mentioned below. Also, please

  • Sign the Contributor License Agreement above
  • Format the file by running npx prettier packages/grafana-ui/src/components/Combobox/Combobox.test.tsx --write

@tskarhed
Copy link
Contributor

Thank you! Could you also sign the Contributor License Agreement?

@KawtharAlakri
Copy link
Contributor Author

Thank you! Could you also sign the Contributor License Agreement?

Done

Copy link
Contributor

@tskarhed tskarhed left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! It is really appreciated 😄

@tskarhed tskarhed merged commit bd974bd into grafana:main Aug 29, 2024
irenerl24 pushed a commit that referenced this pull request Oct 9, 2024
* init commit

* New Select test cases

* click + scroll and click test cases

* code format

* code format
@joshhunt joshhunt modified the milestones: 11.3.x, 11.3.0 Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/frontend no-changelog Skip including change in changelog/release notes pr/external This PR is from external contributor

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants