Repository navigation
Fix XY docs anchors and match the current marketing banner #538
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
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,96 @@ | ||
| """Production contracts for the announcement shared with reflex-marketing.""" | ||
|
|
||
| import os | ||
|
|
||
| import pytest | ||
| from xy_docs.announcement import ANNOUNCEMENT_RELEASE | ||
|
|
||
|
|
||
| def test_production_announcement_matches_marketing_and_persists_dismissal() -> None: | ||
| """Check responsive artwork, storage, reloads, and hidden-header geometry.""" | ||
| base_url = os.environ.get("XY_DOCS_BASE_URL") | ||
| if base_url is None: | ||
| pytest.skip("XY_DOCS_BASE_URL is only set for the production-DOM check") | ||
|
|
||
| from playwright.sync_api import expect, sync_playwright | ||
|
|
||
| with sync_playwright() as playwright: | ||
| browser = playwright.chromium.launch() | ||
| context = browser.new_context() | ||
| context.add_init_script( | ||
| """if (!localStorage.getItem('reflex_announcement_dismissed_release')) { | ||
| localStorage.setItem('reflex_announcement_dismissed_release', 'xy-in-reflex-build-v1'); | ||
| }""" | ||
| ) | ||
| page = context.new_page() | ||
| for width in (1440, 1280, 1279, 960, 390, 320): | ||
| page.set_viewport_size({"width": width, "height": 900}) | ||
| page.goto(base_url, wait_until="networkidle") | ||
| banner = page.locator("[data-announcement]") | ||
| expect(banner).to_be_visible() | ||
| expect(banner.locator(".docs-announcement-glass > span")).to_have_count(5) | ||
| link = banner.locator("a") | ||
| expect(link).to_have_accessible_name( | ||
| "New: Build vs. Buy for Internal Software — Read more (opens in a new tab)" | ||
| ) | ||
| expect(link).to_have_attribute( | ||
| "href", "https://reflex.dev/blog/build-vs-buy-internal-software/" | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||
| ) | ||
| expect(link).to_have_attribute("target", "_blank") | ||
| assert {"noopener", "noreferrer"} <= set((link.get_attribute("rel") or "").split()) | ||
| assert page.locator(".docs-nav-frame").bounding_box()["height"] == ( | ||
| 108 if width > 960 else 104 | ||
| ) | ||
| message = banner.locator(".announcement-shimmer").bounding_box() | ||
| assert 0 <= message["x"] < message["x"] + message["width"] <= width | ||
| cta = banner.get_by_text("Read more", exact=True) | ||
| assert cta.is_visible() == (width > 640) | ||
| assert not banner.locator("a svg").is_visible() | ||
| header = page.locator(".docs-navbar-header") | ||
| expect(header).to_have_css("border-top-left-radius", "24px") | ||
| expect(header).to_have_css("border-top-right-radius", "24px") | ||
| if width < 1280: | ||
| menu = page.locator(".docs-navbar-menu > summary") | ||
| menu.click() | ||
| expect(header).to_have_css("border-top-left-radius", "0px") | ||
| expect(header).to_have_css("border-top-right-radius", "0px") | ||
| menu.click() | ||
| expect(header).to_have_css("border-top-left-radius", "24px") | ||
| expect(header).to_have_css("border-top-right-radius", "24px") | ||
| for color_mode in ("light", "dark"): | ||
| page.emulate_media(color_scheme=color_mode, reduced_motion="reduce") | ||
| assert banner.evaluate("el => getComputedStyle(el).color") == "rgb(0, 0, 0)" | ||
| assert ( | ||
| banner.locator(".docs-announcement-glass").evaluate( | ||
| "el => getComputedStyle(el).animationName" | ||
| ) | ||
| == "none" | ||
| ) | ||
|
|
||
| # A second open tab receives marketing's same-origin storage event. | ||
| other = context.new_page() | ||
| other.goto(base_url, wait_until="networkidle") | ||
| page.get_by_role("button", name="Dismiss announcement").click() | ||
| for current in (page, other): | ||
| expect(current.locator("[data-announcement]")).to_be_hidden() | ||
| expect(current.locator(".docs-nav-frame")).to_have_css("height", "64px") | ||
| assert ( | ||
| page.evaluate("localStorage.getItem('reflex_announcement_dismissed_release')") | ||
| == ANNOUNCEMENT_RELEASE | ||
| ) | ||
| page.reload(wait_until="networkidle") | ||
| expect(page.locator("[data-announcement]")).to_be_hidden() | ||
| expect(page.locator(".docs-nav-frame")).to_have_css("height", "64px") | ||
| context.close() | ||
|
|
||
| blocked = browser.new_context() | ||
| blocked.add_init_script( | ||
| "Object.defineProperty(window, 'localStorage', {get() {throw new Error('blocked')}})" | ||
| ) | ||
| page = blocked.new_page() | ||
| page.goto(base_url, wait_until="networkidle") | ||
| expect(page.locator("[data-announcement]")).to_be_visible() | ||
| page.get_by_role("button", name="Dismiss announcement").click() | ||
| expect(page.locator("[data-announcement]")).to_be_hidden() | ||
| expect(page.locator(".docs-nav-frame")).to_have_css("height", "64px") | ||
| browser.close() | ||
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,63 @@ | ||
| """Marketing presentation and persistence around the shared announcement.""" | ||
|
|
||
| import json | ||
|
|
||
| import reflex as rx | ||
|
|
||
| # Match reflex-marketing so dismissals carry across the same-origin sites. | ||
| ANNOUNCEMENT_RELEASE = "build-vs-buy-internal-software-v1" | ||
| ANNOUNCEMENT_TITLE = "Build vs. Buy for Internal Software" | ||
| ANNOUNCEMENT_URL = "https://reflex.dev/blog/build-vs-buy-internal-software/" | ||
|
|
||
|
|
||
| def match_marketing_announcement(component: rx.Component) -> None: | ||
| """Adapt shared markup to reflex-marketing without copying its banner body.""" | ||
| if "data-announcement" in component.custom_attrs: | ||
| link, dismiss = component.children | ||
| link.href = rx.Var.create(ANNOUNCEMENT_URL) | ||
| link.custom_attrs["aria-label"] = ( | ||
| f"New: {ANNOUNCEMENT_TITLE} — Read more (opens in a new tab)" | ||
| ) | ||
| link.children = link.children[:1] | ||
| link.children[0].children[0].custom_attrs["aria-hidden"] = True | ||
| message = link.children[0].children[1] | ||
| message.children = rx.fragment(ANNOUNCEMENT_TITLE).children | ||
| message.custom_attrs["data-shimmer-text"] = ANNOUNCEMENT_TITLE | ||
| dismiss.custom_attrs["data-announcement-dismiss"] = "" | ||
| component.children.insert( | ||
| 0, | ||
| rx.el.div( | ||
| *[rx.el.span() for _ in range(5)], | ||
| class_name="docs-announcement-glass", | ||
| aria_hidden=True, | ||
| ), | ||
| ) | ||
| return | ||
| for child in component.children: | ||
| match_marketing_announcement(child) | ||
|
|
||
|
|
||
| def announcement_visibility_script() -> str: | ||
| """Restore marketing's release-scoped dismissal before the page paints.""" | ||
| return """(() => { | ||
| const release = __RELEASE__; | ||
| const key = 'reflex_announcement_dismissed_release'; | ||
| const sync = () => { | ||
| let dismissed = false; | ||
| try { dismissed = localStorage.getItem(key) === release; } catch (_) {} | ||
| if (dismissed) document.documentElement.dataset.announcementDismissed = 'true'; | ||
| else delete document.documentElement.dataset.announcementDismissed; | ||
| }; | ||
| sync(); | ||
| if (window.__xyAnnouncementVisibilityInstalled) return; | ||
| window.__xyAnnouncementVisibilityInstalled = true; | ||
| document.addEventListener('click', (event) => { | ||
| if (!(event.target instanceof Element) || | ||
| !event.target.closest('.docs-nav-frame [data-announcement-dismiss]')) return; | ||
| try { localStorage.setItem(key, release); } catch (_) {} | ||
| document.documentElement.dataset.announcementDismissed = 'true'; | ||
| }, true); | ||
| window.addEventListener('storage', (event) => { | ||
| if (event.key === key || event.key === null) sync(); | ||
| }); | ||
| })();""".replace("__RELEASE__", json.dumps(ANNOUNCEMENT_RELEASE)) |
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.
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.