-
Notifications
You must be signed in to change notification settings - Fork 1
Fix - navigation.js TypeError without #site-navigation, and submenu caret never flipping #90
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
Open
rajatgautam755421
wants to merge
3
commits into
develop
Choose a base branch
from
fix/navigation-null-guard-and-caret
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
39a959c
Fix - navigation.js TypeError without #site-navigation, and submenu c…
rajatgautam755421 7f87364
Test - Guard the submenu caret flipping and navigation.js on pages wi…
rajatgautam755421 da5476f
Test - Assert navigation.js ran with #site-navigation already removed…
rajatgautam755421 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,88 @@ | ||
| import { test, expect } from "@playwright/test"; | ||
|
|
||
| /** | ||
| * @area mobile-menu | ||
| * @tier fresh | ||
| * @guards themegrill/accelerate-pro#101 | ||
| * @source themegrill/accelerate-pro#101 (reported by subin-shk) | ||
| * @why The sub-toggle handler in js/navigation.js toggled `.fa-caret-right`, | ||
| * which the icon never has (it is created as fa-caret-down), so the caret | ||
| * never changed. A submenu is added to the first menu item before the | ||
| * script runs, so this does not depend on the site's menu. Checks the | ||
| * glyph actually drawn, not just the classes. | ||
| */ | ||
| test("the submenu caret turns up when a mobile submenu opens and back down when it closes @mobile-menu @fresh", async ({ | ||
| page, | ||
| }) => { | ||
| // Registered before jQuery's ready handler, so the theme sees a real parent item. | ||
| await page.addInitScript(() => | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| const item = document.querySelector("#site-navigation ul li"); | ||
| if (!item) return; | ||
| item.classList.add("menu-item-has-children"); | ||
| item.insertAdjacentHTML("beforeend", '<ul class="sub-menu"><li><a href="#tgqa-child">Injected child</a></li></ul>'); | ||
| }), | ||
| ); | ||
| await page.setViewportSize({ width: 375, height: 812 }); | ||
| await page.goto("/"); | ||
|
|
||
| await page.locator("#site-navigation .menu-toggle").click(); | ||
| const toggle = page.locator("#site-navigation .sub-toggle").first(); | ||
| const icon = toggle.locator("i.fa"); | ||
| const submenu = toggle.locator("xpath=../ul").first(); | ||
| const glyph = () => icon.evaluate((el) => getComputedStyle(el, "::before").content.replace(/["']/g, "").codePointAt(0)?.toString(16)); | ||
|
|
||
| await expect(icon).toHaveClass(/\bfa-caret-down\b/); | ||
| expect(await glyph(), "closed: caret-down glyph").toBe("f0d7"); | ||
|
|
||
| await toggle.click(); | ||
| await expect(submenu).toBeVisible(); | ||
| await expect(icon).toHaveClass(/\bfa-caret-up\b/); | ||
| await expect(icon).not.toHaveClass(/\bfa-caret-down\b/); | ||
| expect(await glyph(), "open: caret-up glyph").toBe("f0d8"); | ||
|
|
||
| await toggle.click(); | ||
| await expect(submenu).toBeHidden(); | ||
| await expect(icon).toHaveClass(/\bfa-caret-down\b/); | ||
| await expect(icon).not.toHaveClass(/\bfa-caret-up\b/); | ||
| expect(await glyph(), "closed again: caret-down glyph").toBe("f0d7"); | ||
| }); | ||
|
|
||
| /** | ||
| * @area mobile-menu | ||
| * @tier fresh | ||
| * @guards themegrill/accelerate-pro#53 | ||
| * @source themegrill/accelerate-pro#53; themegrill/radiate-pro#107 (same fix, same spec) | ||
| * @why The touch-submenu handler in js/navigation.js called | ||
| * container.querySelectorAll() with no null check, so any page without | ||
| * #site-navigation threw "Cannot read properties of null". On a real site | ||
| * that is the Legacy Widget preview on Appearance > Widgets; here the nav | ||
| * is removed while the page parses, before the footer script runs. | ||
| */ | ||
| test("a page without the primary navigation throws no script error @mobile-menu @fresh", async ({ page }) => { | ||
| const errors: string[] = []; | ||
| page.on("pageerror", (e) => errors.push(e.message)); | ||
| await page.addInitScript(() => { | ||
| const original = Document.prototype.getElementById; | ||
| // The observer uses the unwrapped lookup, so only the page's own lookups are recorded below. | ||
| new MutationObserver(() => original.call(document, "site-navigation")?.remove()).observe(document, { | ||
| childList: true, | ||
| subtree: true, | ||
| }); | ||
| // Record what each lookup of the nav returned, so the test proves the script ran with it already gone. | ||
| const lookups: boolean[] = []; | ||
| (window as unknown as { tgqaNavLookups: boolean[] }).tgqaNavLookups = lookups; | ||
| Document.prototype.getElementById = function (id: string) { | ||
| const found = original.call(this, id); | ||
| if ("site-navigation" === id) lookups.push(null === found); | ||
| return found; | ||
| }; | ||
| }); | ||
|
|
||
| await page.goto("/"); | ||
| await page.waitForLoadState("networkidle"); | ||
| const lookups = await page.evaluate(() => (window as unknown as { tgqaNavLookups: boolean[] }).tgqaNavLookups); | ||
| expect(lookups.length, "navigation.js never looked up #site-navigation").toBeGreaterThan(0); | ||
| expect(lookups.every(Boolean), "#site-navigation still existed when the script looked it up").toBe(true); | ||
| expect(errors, "script errors on a page without #site-navigation").toEqual([]); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked — not reproducible, so leaving the parsing out.
getComputedStyle(el, '::before').contentreturns the resolved string, not the stylesheet's escape: forfa-caret-downit is the U+F0D7 character itself, andglyph()readsf0d7in Chromium, Firefox and WebKit (tested all three; none return\f0d7). The spec also fails ondevelopand passes with the fix, which could not happen if it always read5c.