fix(form): restore description toggles after sign-in (#107)
Some checks are pending
Deploy / deploy (push) Waiting to run

* fix(form): restore description toggles after sign-in

* fix(form): reset expanded descriptions on re-auth
This commit is contained in:
Adam Moussa 2026-08-03 16:19:46 -04:00 • committed by GitHub
parent 139ea3b1d3
commit a69e6d0a7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 105 additions and 0 deletions

View file

@ -124,6 +124,7 @@ function handleCredentialResponse(response) {
document.getElementById("app").classList.remove("is-hidden");
const footer = document.getElementById("sticky-footer");
if (footer) footer.classList.remove("is-hidden");
refreshAllDescToggles();
document.getElementById("user-name").textContent = payload.name;
document.getElementById("user-email").textContent = payload.email;
if (payload.picture) {
@ -266,6 +267,13 @@ function scheduleDescToggle(card) {
});
}
function refreshAllDescToggles() {
document.querySelectorAll("#meals-list [data-meal-index]").forEach((card) => {
card.querySelector(".meal-desc")?.classList.remove("is-expanded");
scheduleDescToggle(card);
});
}
function updateMealCard(card, meal, i) {
const qty = quantities[i] || 0;
card.dataset.mealIndex = String(i);

View file

@ -927,6 +927,103 @@ class TestGenerateFormPlaywright:
class TestGenerateFormGooglePlaywright:
def test_desc_toggle_attaches_after_auth_reveal(self, tmp_path):
sync_api = pytest.importorskip("playwright.sync_api")
sync_playwright = sync_api.sync_playwright
out = tmp_path / "google-order-form.html"
out.write_text(_render_for_browser(google=True))
with sync_playwright() as p:
try:
browser = p.chromium.launch(headless=True)
except Exception as exc:
raise RuntimeError(
"Chromium is required for form Playwright tests. "
"Run: playwright install --with-deps chromium"
) from exc
try:
page = browser.new_page()
page.add_init_script(
"""window.google = {
accounts: {
id: {
initialize() {},
renderButton() {},
disableAutoSelect() {},
},
},
};"""
)
page.route(
"https://accounts.google.com/gsi/client",
lambda route: route.abort(),
)
_mock_form_routes(page)
page.goto(out.as_uri(), wait_until="domcontentloaded")
short_card = page.locator('[data-meal-index="0"]')
long_card = page.locator('[data-meal-index="1"]')
long_card.wait_for(state="attached")
page.evaluate(
"""() => new Promise((resolve) => {
requestAnimationFrame(() => requestAnimationFrame(resolve));
})"""
)
assert "is-hidden" in (
page.locator("#app").get_attribute("class") or ""
)
assert long_card.locator(".meal-desc-toggle").count() == 0
page.evaluate(
"(credential) => handleCredentialResponse({ credential })",
_google_credential(),
)
toggle = long_card.locator(".meal-desc-toggle")
toggle.wait_for(state="visible")
assert short_card.locator(".meal-desc-toggle").count() == 0
assert toggle.inner_text() == "More"
assert toggle.get_attribute("aria-expanded") == "false"
toggle.click()
assert toggle.inner_text() == "Less"
assert toggle.get_attribute("aria-expanded") == "true"
assert "is-expanded" in (
long_card.locator(".meal-desc").get_attribute("class") or ""
)
page.evaluate("signOut()")
assert "is-hidden" in (
page.locator("#app").get_attribute("class") or ""
)
page.evaluate(
"(credential) => handleCredentialResponse({ credential })",
_google_credential(),
)
page.wait_for_function(
"""() => {
const card = document.querySelector('[data-meal-index="1"]');
const desc = card?.querySelector('.meal-desc');
const toggle = card?.querySelector('.meal-desc-toggle');
return !desc?.classList.contains('is-expanded')
&& toggle?.textContent === 'More'
&& toggle?.getAttribute('aria-expanded') === 'false';
}"""
)
toggle = long_card.locator(".meal-desc-toggle")
toggle.click()
assert toggle.inner_text() == "Less"
assert toggle.get_attribute("aria-expanded") == "true"
toggle.click()
assert toggle.inner_text() == "More"
assert toggle.get_attribute("aria-expanded") == "false"
assert "is-expanded" not in (
long_card.locator(".meal-desc").get_attribute("class") or ""
)
finally:
browser.close()
@pytest.fixture(scope="class")
@classmethod
def signed_in_admin_page(cls, tmp_path_factory):