Skip to content

Commit 75e8152

Browse files
Fix mobile navigation broken by invalid JavaScript syntax (#21)
* Initial plan * Fix mobile navigation by removing invalid front matter and adding null checks Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
1 parent 002498b commit 75e8152

7 files changed

Lines changed: 199 additions & 19 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ vendor/
2222
# We use Node.js as our runtime, so we ignore node_modules
2323
node_modules
2424

25+
# Playwright test results and artifacts
26+
test-results/
27+
playwright-report/
28+
playwright/.cache/
29+
2530
# .DS_Store is a macOS-only metadata file about directories. Convention is to not commit them.
2631
# See: https://en.wikipedia.org/wiki/.DS_Store
2732
.DS_Store

_includes/js/custom.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
---
2-
---
1+

assets/js/just-the-docs.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,34 @@ function initNav() {
4242

4343
disableHeadStyleSheets();
4444

45-
jtd.addEvent(menuButton, 'click', function(e){
46-
e.preventDefault();
45+
if (menuButton) {
46+
jtd.addEvent(menuButton, 'click', function(e){
47+
e.preventDefault();
4748

48-
if (menuButton.classList.toggle('nav-open')) {
49-
siteNav.classList.add('nav-open');
50-
mainHeader.classList.add('nav-open');
51-
menuButton.ariaPressed = true;
52-
} else {
53-
siteNav.classList.remove('nav-open');
54-
mainHeader.classList.remove('nav-open');
55-
menuButton.ariaPressed = false;
56-
}
57-
});
49+
if (menuButton.classList.toggle('nav-open')) {
50+
siteNav.classList.add('nav-open');
51+
mainHeader.classList.add('nav-open');
52+
menuButton.ariaPressed = true;
53+
} else {
54+
siteNav.classList.remove('nav-open');
55+
mainHeader.classList.remove('nav-open');
56+
menuButton.ariaPressed = false;
57+
}
58+
});
59+
}
5860

5961
{%- if site.search_enabled != false and site.search.button %}
6062
const searchInput = document.getElementById('search-input');
6163
const searchButton = document.getElementById('search-button');
6264

63-
jtd.addEvent(searchButton, 'click', function(e){
64-
e.preventDefault();
65+
if (searchButton) {
66+
jtd.addEvent(searchButton, 'click', function(e){
67+
e.preventDefault();
6568

66-
mainHeader.classList.add('nav-open');
67-
searchInput.focus();
68-
});
69+
mainHeader.classList.add('nav-open');
70+
searchInput.focus();
71+
});
72+
}
6973
{%- endif %}
7074
}
7175

package-lock.json

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "docs-testing",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"test": "playwright test",
7+
"test:headed": "playwright test --headed"
8+
},
9+
"devDependencies": {
10+
"@playwright/test": "^1.48.0"
11+
}
12+
}

playwright.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { defineConfig, devices } = require('@playwright/test');
2+
3+
module.exports = defineConfig({
4+
testDir: './tests',
5+
fullyParallel: true,
6+
forbidOnly: !!process.env.CI,
7+
retries: process.env.CI ? 2 : 0,
8+
workers: process.env.CI ? 1 : undefined,
9+
reporter: 'html',
10+
use: {
11+
baseURL: 'http://localhost:4000',
12+
trace: 'on-first-retry',
13+
},
14+
15+
projects: [
16+
{
17+
name: 'Mobile Chrome',
18+
use: { ...devices['Pixel 5'] },
19+
},
20+
],
21+
22+
webServer: {
23+
command: 'bundle exec jekyll serve --port 4000',
24+
url: 'http://localhost:4000',
25+
reuseExistingServer: !process.env.CI,
26+
timeout: 120 * 1000,
27+
},
28+
});

tests/mobile-navigation.spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
test.describe('Mobile Navigation', () => {
4+
test('should toggle mobile menu when clicking menu button', async ({ page }) => {
5+
await page.goto('/');
6+
7+
// Verify we're in mobile view by checking if the menu button is visible
8+
const menuButton = page.locator('#menu-button');
9+
await expect(menuButton).toBeVisible();
10+
11+
// Initially, the navigation should be hidden (not have nav-open class)
12+
const siteNav = page.locator('#site-nav');
13+
await expect(siteNav).not.toHaveClass(/nav-open/);
14+
15+
// Click the menu button to open the navigation
16+
await menuButton.click();
17+
18+
// After clicking, navigation should have nav-open class
19+
await expect(siteNav).toHaveClass(/nav-open/);
20+
21+
// Menu button should also have nav-open class
22+
await expect(menuButton).toHaveClass(/nav-open/);
23+
24+
// Menu button aria-pressed should be true
25+
await expect(menuButton).toHaveAttribute('aria-pressed', 'true');
26+
27+
// Click again to close
28+
await menuButton.click();
29+
30+
// Navigation should no longer have nav-open class
31+
await expect(siteNav).not.toHaveClass(/nav-open/);
32+
await expect(menuButton).not.toHaveClass(/nav-open/);
33+
await expect(menuButton).toHaveAttribute('aria-pressed', 'false');
34+
});
35+
36+
test('should show navigation links when menu is open', async ({ page }) => {
37+
await page.goto('/');
38+
39+
const menuButton = page.locator('#menu-button');
40+
const siteNav = page.locator('#site-nav');
41+
42+
// Initially, navigation links might be hidden/not visible in mobile view
43+
// Click to open
44+
await menuButton.click();
45+
46+
// Wait for navigation to be open
47+
await expect(siteNav).toHaveClass(/nav-open/);
48+
49+
// Check that navigation links are accessible
50+
const navLinks = page.locator('#site-nav .nav-list-link');
51+
const count = await navLinks.count();
52+
expect(count).toBeGreaterThan(0);
53+
});
54+
});

0 commit comments

Comments
 (0)