Skip to content
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

fix: window unexpected href when feature link is not configured #1329

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions e2e/fixtures/page-type-home/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ hero:
text: E2E case subTitle
tagline: E2E case tagline
actions:
- text: Action 1
link: /action-1
- text: Action 2
link: /action-2
theme: brand
- text: External
link: https://example.com/
theme: alt
- text: Action 1
link: /action-1
- text: Action 2
link: /action-2
theme: brand
- text: External
link: https://example.com/
theme: alt
image:
src: /brand.png
alt: E2E case brand image
Expand All @@ -21,5 +21,13 @@ hero:
- /[email protected] 2x
sizes:
- '((min-width: 50em) and (max-width: 60em)) 50em'
- "(max-width: 30em) 20em"
- '(max-width: 30em) 20em'
features:
- title: Blazing fast build speed
details: The core compilation module is based on the Rust front-end toolchain, providing a more ultimate development experience.
icon: 🏃🏻‍♀️
- title: Support for MDX content writing
details: MDX is a powerful way to write content, allowing you to use React components in Markdown.
icon: 📦
link: https://example.com/
---
13 changes: 13 additions & 0 deletions e2e/tests/page-type-home.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ test.describe('home pageType', async () => {

// todo: add tests for hero actions
});

test('Features', async ({ page }) => {
await page.goto(`http://localhost:${appPort}`);
const features = await page.$$('.rspress-home-feature-card');
expect(features).toHaveLength(2);

const url1 = page.url();
await features[0].click();
expect(page.url()).toBe(url1);

await features[1].click();
expect(page.url()).toBe('https://example.com/');
});
});
10 changes: 7 additions & 3 deletions packages/theme-default/src/components/HomeFeature/index.tsx
Timeless0911 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ export function HomeFeature({
<div className="overflow-hidden m-auto flex flex-wrap max-w-6xl">
{features?.map(feature => {
const { icon, title, details, link: rawLink } = feature;
const link = isExternalUrl(rawLink)
? rawLink
: normalizeHrefInRuntime(withBase(rawLink, routePath));

let link = rawLink;
if (rawLink) {
link = isExternalUrl(rawLink)
? rawLink
: normalizeHrefInRuntime(withBase(rawLink, routePath));
}

return (
<div
Expand Down