-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
179 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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,8 @@ | ||
--- | ||
pageType: custom | ||
--- | ||
|
||
<div id="pageA">contentA</div> | ||
|
||
<div id="pageB">A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF A LOT OF CONTENT A LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF CONTENT A LOT OF A LOT OF CONTENT A LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENTA LOT OF CONTENT</div> | ||
<div id="pageC">contentC</div> |
This file contains 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,16 @@ | ||
{ | ||
"name": "@rspress-fixture/rspress-nav-with-hash", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "rspress dev", | ||
"build": "rspress build", | ||
"preview": "rspress preview" | ||
}, | ||
"dependencies": { | ||
"rspress": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.11.17" | ||
} | ||
} |
This file contains 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,29 @@ | ||
import * as path from 'node:path'; | ||
import { defineConfig } from 'rspress/config'; | ||
|
||
export default defineConfig({ | ||
root: path.join(__dirname, 'doc'), | ||
route: { | ||
cleanUrls: true, | ||
}, | ||
themeConfig: { | ||
hideNavbar: 'auto', | ||
nav: [ | ||
{ | ||
text: 'PageA', | ||
link: '#pageA', | ||
position: 'right', | ||
}, | ||
{ | ||
text: 'PageB', | ||
link: '#pageB', | ||
position: 'right', | ||
}, | ||
{ | ||
text: 'PageC', | ||
link: '#pageC', | ||
position: 'right', | ||
}, | ||
], | ||
}, | ||
}); |
This file contains 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,29 @@ | ||
import * as path from 'node:path'; | ||
import { defineConfig } from 'rspress/config'; | ||
|
||
export default defineConfig({ | ||
root: path.join(__dirname, 'doc'), | ||
route: { | ||
cleanUrls: true, | ||
}, | ||
themeConfig: { | ||
hideNavbar: 'never', | ||
nav: [ | ||
{ | ||
text: 'PageA', | ||
link: '#pageA', | ||
position: 'right', | ||
}, | ||
{ | ||
text: 'PageB', | ||
link: '#pageB', | ||
position: 'right', | ||
}, | ||
{ | ||
text: 'PageC', | ||
link: '#pageC', | ||
position: 'right', | ||
}, | ||
], | ||
}, | ||
}); |
This file contains 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 @@ | ||
{} |
This file contains 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,80 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import path from 'node:path'; | ||
import { getPort, killProcess, runDevCommand } from '../utils/runCommands'; | ||
|
||
const fixtureDir = path.resolve(__dirname, '../fixtures'); | ||
|
||
test.describe('basic test', async () => { | ||
let appPort; | ||
let app; | ||
async function launchApp(configFile: string) { | ||
const appDir = path.join(fixtureDir, 'hide-nav-bar'); | ||
appPort = await getPort(); | ||
app = await runDevCommand(appDir, appPort, configFile); | ||
} | ||
|
||
test.afterAll(async () => { | ||
if (app) { | ||
await killProcess(app); | ||
} | ||
}); | ||
|
||
test('Navigate with an hash as link', async ({ page }) => { | ||
await launchApp('./rspress.config.ts'); | ||
await page.goto(`http://localhost:${appPort}/`); | ||
|
||
await page.locator('.rspress-nav-menu a').first().click(); | ||
expect(page.url()).toContain('index#pageA'); | ||
|
||
await page.locator('.rspress-nav-menu a').nth(1).click(); | ||
expect(page.url()).toContain('index#pageB'); | ||
}); | ||
|
||
test('Close the hamburger menu when clicking on an item in mobile view', async ({ | ||
page, | ||
}) => { | ||
await launchApp('./rspress.config.ts'); | ||
await page.setViewportSize({ width: 375, height: 812 }); | ||
|
||
await page.goto(`http://localhost:${appPort}/`); | ||
|
||
await page.locator('.rspress-mobile-hamburger').click(); | ||
await expect(page.locator('.rspress-nav-screen')).toBeVisible(); | ||
|
||
await page.getByRole('link', { name: 'PageC' }).click(); | ||
await expect(page.locator('.rspress-nav-screen')).not.toBeVisible(); | ||
}); | ||
|
||
test('Navbar should be visible on mobile when we scroll down with hideNavbar to never', async ({ | ||
page, | ||
}) => { | ||
await launchApp('./rspress.config.ts'); | ||
await page.setViewportSize({ width: 375, height: 812 }); | ||
|
||
await page.goto(`http://localhost:${appPort}/`); | ||
|
||
await page.evaluate(() => { | ||
window.scrollBy(0, 800); | ||
}); | ||
|
||
// Allow to check if the rspress-nav is in the viewport | ||
// toBeVisible() doesn't work here because it check the visibility and the display property | ||
const isInViewport = await page.evaluate(sel => { | ||
const element = document.querySelector(sel); | ||
|
||
if (!element) return false; | ||
|
||
const rect = element.getBoundingClientRect(); | ||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
rect.bottom <= | ||
(window.innerHeight || document.documentElement.clientHeight) && | ||
rect.right <= | ||
(window.innerWidth || document.documentElement.clientWidth) | ||
); | ||
}, '.rspress-nav'); | ||
|
||
expect(isInViewport).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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 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 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