Repository navigation
Reject duplicate docs IDs #404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
228ffb8
Reject duplicate docs IDs (#396)
Alek99 3ce9b2d
Format duplicate-ID validator (#396)
Alek99 8509941
Validate IDs in prerendered docs HTML
Alek99 3b24b0f
Trim duplicate-ID validation
Alek99 b5e0ccf
Merge current main into duplicate docs ID branch
Darksinian 0827ae1
Test duplicate docs ID validation
FarhanAliRaza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """Focused tests for the post-build HTML route validator.""" | ||
|
|
||
| import importlib.util | ||
| import sys | ||
| from pathlib import Path | ||
| from types import ModuleType | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_duplicate_id_validator_covers_html_svg_and_diagnostics( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| """Accept unique IDs but reject an HTML/SVG collision with route context.""" | ||
| reflex_site_shared = ModuleType("reflex_site_shared") | ||
| reflex_docs = ModuleType("reflex_site_shared.docs") | ||
| reflex_docs.discover_docs = lambda _config: [] | ||
| xy_docs = ModuleType("xy_docs") | ||
| xy_config = ModuleType("xy_docs.config") | ||
| xy_config.DOCS_CONFIG = None | ||
| xy_config.DOCS_REDIRECTS = {} | ||
| monkeypatch.setitem(sys.modules, "reflex_site_shared", reflex_site_shared) | ||
| monkeypatch.setitem(sys.modules, "reflex_site_shared.docs", reflex_docs) | ||
| monkeypatch.setitem(sys.modules, "xy_docs", xy_docs) | ||
| monkeypatch.setitem(sys.modules, "xy_docs.config", xy_config) | ||
|
|
||
| validator_path = Path(__file__).resolve().parents[1] / "scripts" / "check_html_routes.py" | ||
| spec = importlib.util.spec_from_file_location("focused_check_html_routes", validator_path) | ||
| assert spec is not None and spec.loader is not None | ||
| validator = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(validator) | ||
|
|
||
| unique_source = '<main id="content"><svg id="chart"/><div id=""></div></main>' | ||
| assert validator.duplicate_html_ids(unique_source) == () | ||
|
|
||
| duplicate_source = '<main id="content"><svg><g id="shared"/></svg><section id="shared"/></main>' | ||
| html_path = tmp_path / "charts" / "scatter.html" | ||
| assert validator.duplicate_html_ids(duplicate_source) == ("shared",) | ||
|
|
||
| with pytest.raises( | ||
| RuntimeError, | ||
| match=r"duplicate element IDs \('shared',\).*?/charts/scatter/.*scatter\.html", | ||
| ): | ||
| validator.validate_unique_html_ids( | ||
| "/charts/scatter/", | ||
| html_path, | ||
| duplicate_source, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.