Skip to content

Testing: Recognition of Autocomplete Input #3886

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

Closed
GrazingScientist opened this issue Oct 16, 2024 · 5 comments · Fixed by #4001
Closed

Testing: Recognition of Autocomplete Input #3886

GrazingScientist opened this issue Oct 16, 2024 · 5 comments · Fixed by #4001
Assignees
Milestone

Comments

@GrazingScientist
Copy link
Contributor

GrazingScientist commented Oct 16, 2024

Description

Hi!

I found another non-working feature in the testing framework, when I want to test that the autocomplete is working.

The test below is failing, although it should not.

from nicegui import ui

def setup() -> None:
    @ui.page("/")
    def main() -> None:
        options = ['AutoComplete', 'NiceGUI', 'Awesome']
        ui.input(label='Text', placeholder='start typing', autocomplete=options)

async def test_validation(user):
    setup()

    await user.open("/")

    await user.should_not_see("AutoComplete")
    user.find("Text").type("Auto")
    await user.should_see("AutoComplete")

I hope, you can fix it. ❤️

@rodja
Copy link
Member

rodja commented Oct 17, 2024

Thanks for bringing up this example @GrazingScientist. I think it is a little bit more complicated. If you start your page with NiceGUI and type "Auto" in the browser, you must also press the "TAB" key to confirm the auto completion. So we would need to use user.find("Text").type("Auto").trigger("keydown.tab").

@GrazingScientist
Copy link
Contributor Author

GrazingScientist commented Oct 17, 2024

Hi @rodja ,

thanks for coming back so quickly. I eagerly tried your tip, but the result is the same. The test fails with:

AssertionError: expected to see at least one element with marker=AutoComplete or content=AutoComplete on the page

This is the code I used:

from nicegui import ui

def setup() -> None:
    @ui.page("/")
    def main() -> None:
        options = ["AutoComplete", "NiceGUI", "Awesome"]
        ui.input(label="Text", placeholder="start typing", autocomplete=options)

async def test_validation(user):
    setup()

    await user.open("/")

    await user.should_not_see("AutoComplete")
    user.find("Text").type("Auto").trigger("keydown.tab")
    await user.should_see("AutoComplete")

@rodja
Copy link
Member

rodja commented Oct 17, 2024

I'm sorry. This is not implemented yet. I just wanted to clarify the API. We are pretty busy at the moment. Would you like to try creating a pull request.

@GrazingScientist
Copy link
Contributor Author

I will try to dig into the code, if I have the time. Can you provide me a link to the code section, where I need to focus on?

@rodja
Copy link
Member

rodja commented Oct 17, 2024

I think you could try adding a special case for ui.input in the trigger loop over all elements:

for element in self.elements:

Similar to what we do for ui.link and ui.select in the click method:

https://github.com/zauberzeug/nicegui/blob/809290e3037a837fd231330c096da6409143f6ab/nicegui/testing/user_interaction.py#L63C17-L70C55

An workaround until we get this done might be to just get the element and check for the possible autocompletes by accessing the .props dict.

falkoschindler added a commit that referenced this issue Nov 22, 2024
This fixes the issue mentioned in #3886 .

The PR implements a workaround in the testing/user_interaction module by
checking if a trigger event is a "tab" event and then replacing the
current text value by the first element in the autocomplete list.

---------

Co-authored-by: Falko Schindler <[email protected]>
Co-authored-by: Falko Schindler <[email protected]>
@falkoschindler falkoschindler linked a pull request Jan 7, 2025 that will close this issue
@falkoschindler falkoschindler added this to the 2.7 milestone Jan 7, 2025
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 a pull request may close this issue.

3 participants