Skip to content

EDU-122: Blueprints - Hero - React Gen 2 #4021

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

Merged
merged 6 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
51 changes: 51 additions & 0 deletions packages/sdks-tests/src/snippet-tests/blueprints-hero.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect } from '@playwright/test';
import { test } from '../helpers/index.js';

test.describe('Hero Section', () => {
test.beforeEach(async ({ page, packageName }) => {
test.skip(
[
'react-native-74',
'react-native-76-fabric',
'solid',
'solid-start',
'qwik-city',
'react-sdk-next-pages',
'remix',
'hydrogen',
'react-sdk-next-14-app',
'react-sdk-next-15-app',
'nextjs-sdk-next-app',
'vue',
'nuxt',
'svelte',
'sveltekit',
'angular-16',
'angular-16-ssr',
'angular-19-ssr',
'gen1-react',
'gen1-remix',
'gen1-next14-pages',
'gen1-next15-app',
].includes(packageName)
);
await page.goto('/marketing-event');
});

test('should display the hero section with title and call-to-action', async ({ page }) => {
await page.waitForLoadState('networkidle');

const heading = page.getByText('Find the best shoes in town');
await expect(heading).toBeVisible();

const ctaButton = page.getByRole('button', { name: 'Buy now' });
await expect(ctaButton).toBeVisible();
await expect(ctaButton).toBeEnabled();
});

test('should display hero image', async ({ page }) => {
const productImage = page.getByRole('presentation');
await expect(productImage).toBeVisible();
await expect(productImage).toHaveAttribute('src', /.+/);
});
});
5 changes: 5 additions & 0 deletions packages/sdks/snippets/react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import AnnouncementBar from './routes/AnnouncementBar.tsx';
import BlogArticle from './routes/blueprints/BlogArticle.tsx';
import Hero from './routes/blueprints/Hero.tsx';
import ProductDetails from './routes/blueprints/ProductDetails.tsx';
import ProductEditorial from './routes/blueprints/ProductEditorial.tsx';
import AdvancedChildRoute from './routes/custom-components/advanced-child.tsx';
Expand Down Expand Up @@ -49,6 +50,10 @@ const router = createBrowserRouter([
path: '/products/:id',
element: <ProductEditorial />,
},
{
path: '/marketing-event',
element: <Hero />,
},
{
path: '/*',
element: <IntegratingPages />,
Expand Down
31 changes: 31 additions & 0 deletions packages/sdks/snippets/react/src/routes/blueprints/Hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { BuilderContent, Content, fetchOneEntry } from '@builder.io/sdk-react';
import { useEffect, useState } from 'react';

const BUILDER_API_KEY = 'ee9f13b4981e489a9a1209887695ef2b';
const MODEL_NAME = 'collection-hero';

export default function ProductHero() {
const [productHero, setProductHero] = useState<BuilderContent | null>(null);

useEffect(() => {
fetchOneEntry({
model: MODEL_NAME,
apiKey: BUILDER_API_KEY,
userAttributes: { urlPath: window.location.pathname },
}).then((data) => {
setProductHero(data);
});
}, []);

return (
<>
{productHero && (
<Content
content={productHero}
model={MODEL_NAME}
apiKey={BUILDER_API_KEY}
/>
)}
</>
);
}
Loading