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

HTML report filter not working properly #1725

Closed
RichardsonWTR opened this issue Dec 29, 2023 · 2 comments · Fixed by #1776
Closed

HTML report filter not working properly #1725

RichardsonWTR opened this issue Dec 29, 2023 · 2 comments · Fixed by #1776
Labels
bug Something isn't working html

Comments

@RichardsonWTR
Copy link

Describe the bug
The filter on the coverage resets its state when I go to the previous page.

To Reproduce
Python 3.8.10
coverage.py v7.0.1 in my code, and the live example as linked below in the v7.4.0

  1. Go to the example page, as indicated here:
  2. See the number of lines, 10 lines (counting the "total").
  3. Type something in the filter on the top right end of the page, e.g., utils. The results will be filtered and there are now only 4 lines (counting the "total").
  4. Click in a file, e.g., cogapp/utils.py
  5. Go back to the previous page (click ALT + left)
  6. See that the text is still on the filter, on the top right of the page, but the results is not filtered.

Expected behavior
When I go back to the previous page, the results must be filtered.

Additional context

When the code below runs, the filter text is still empty.

    // Trigger change event on setup, to force filter on page refresh
    // (filter value may still be present).
    document.getElementById("filter").dispatchEvent(new Event("input"));

Location

Hotfix

Whithout thinking too much, this is a solution that I came up with: appending a new keyboard event after a timeout period. It's not the ideal, but it's working.

This is my script to see the coverage results:

coverage html  && \
    echo 'window.addEventListener("load",(function(){setTimeout((function(){const t=document.getElementById("filter");t&&t.dispatchEvent(new Event("input"))}),5)}));' >> htmlcov/coverage_html.js && \
    xdg-open 'http://localhost:8000' && \
    python -m http.server -d htmlcov
@RichardsonWTR RichardsonWTR added bug Something isn't working needs triage labels Dec 29, 2023
@nedbat
Copy link
Owner

nedbat commented Dec 29, 2023

I so what you mean in Chrome. Firefox works as you expect. I'm sure there's something that can fix it well. Also, returning to the index page by clicking the ^ index link on the file page brings you to the index page with the filter empty and nothing filtered. It should also keep the filter I think.

@nedbat nedbat added html and removed needs triage labels Dec 29, 2023
@RichardsonWTR
Copy link
Author

Well noted. In Firefox it works as expected. When I go to the previous page the results flash just like my hotfix solution, but it works.
And yes, I detected this bug in Chrome.
Besides, I agree that clicking on ^ index should keep the filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working html
Projects
None yet
2 participants