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

Add data-test to picker item remove button #273

Closed
mnezh opened this issue Nov 3, 2020 · 7 comments · Fixed by #2271
Closed

Add data-test to picker item remove button #273

mnezh opened this issue Nov 3, 2020 · 7 comments · Fixed by #2271
Labels
feature Feature request good first issue Contributions welcome! test Related to testing ui Related to UI

Comments

@mnezh
Copy link
Contributor

mnezh commented Nov 3, 2020

Q SDK Version, OS
0.8.0, 0.8.2 @ OS X

Actual behavior
Prior to 0.8.0 release the following code used to produce a DOM element with data-test="country" property:
ui.picker(name='country', label='Region', values=selected_country, max_choices=1, choices=city_choices)
After 0.8.0, there's no DOM element with data-test="country", which breaks e2e cypress tests

Expected behavior
If UI element has name property defined, it should be translated to DOM element with data-test property with the same value to enable cypress testing

Steps To Reproduce

  1. create an app with ui.picker(name='country', ....)
  2. run with wave 0.8.x
  3. inspect the DOM of the generated UI
@mnezh mnezh added the bug Bug in code label Nov 3, 2020
@mnezh
Copy link
Contributor Author

mnezh commented Nov 3, 2020

oh, what has changed is that this element is not present in DOM until the parent div is clicked:
<input autocapitalize="off" autocomplete="off" aria-autocomplete="both" spellcheck="false" data-test="country" class="ms-BasePicker-input input-56" aria-controls=" " role="textbox" data-lpignore="true" value="" tabindex="0">

@mturoci mturoci self-assigned this Nov 4, 2020
@mturoci
Copy link
Collaborator

mturoci commented Nov 4, 2020

After a bit of investigation, we came to a conclusion that the problem is that q-peak picker has a default value set and max_choices also to 1. This removes HTML input element (containing data-test attr) which results in failed test. After removing the default item with X button, the HTML input gets rendered correctly as expected.

This means we need to provide a mechanism to allow selecting the remove button for picker items to improve testability.

@mturoci mturoci added test Related to testing ui Related to UI and removed bug Bug in code labels Nov 4, 2020
@mturoci mturoci changed the title DOM elements missing data-test properties generated from UI element name properties Add data-test to picker item remove button Nov 4, 2020
@mturoci mturoci added the feature Feature request label Nov 4, 2020
@mturoci mturoci added the good first issue Contributions welcome! label Sep 12, 2022
@mturoci mturoci removed their assignment Sep 26, 2022
@vipinnation
Copy link

I would like to work on this issue

@mnezh
Copy link
Contributor Author

mnezh commented Jan 3, 2024

@mturoci is it still an issue?

@mturoci
Copy link
Collaborator

mturoci commented Jan 4, 2024

Go ahead @vipinnation!

@mnezh it's nice to have I would say.

@dbranley
Copy link
Contributor

Hello Wave, I am new to the project and would like to start contributing!

I think that I have a solution for this issue about the data_test attribute for picker when the max_choices threshold is met. In the Fluent documentation for TagPicker, I found removeButtonIconProps, which allow us to add a data_test attribute to the remove button. So I used this to add a new attribute that includes the picker name prefixed with remove_.

The code I added to ui/src/picker.tsx looks like this:

removeButtonIconProps={{ ...removeButtonIconProps, 'data-test' : 'remove_'+m.name } as Fluent.IIconProps}

I added a couple new test cases to picker.test.tsx. I also created a new Cypress test to confirm the remove button can be retrieved with the new attribute and then clicked to remove the selected item. Here is a snipit from that test:

def test_picker(cy):
    cy.visit('/demo')
    cy.locate('picker').type('Ham').type('{enter}')
    cy.locate('picker').should('not.exist')
    cy.locate('remove_picker').first().click()
    cy.locate('picker').should('exist').type('Beans').type('{enter}')
    cy.locate('picker').should('not.exist')

I have a branch in my fork of the project and will be submitting a PR in a bit. Please let me know if you think this is fine or if I'm overlooking something. Thanks!

@mturoci
Copy link
Collaborator

mturoci commented Feb 20, 2024

Hi @dbranley! Feel free to make a PR. Will have a look and let you know if anything else is needed. Your description sounds reasonable so should be good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request good first issue Contributions welcome! test Related to testing ui Related to UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants