Skip to content

Commit fef85fd

Browse files
itsjustrileyclaude
andcommitted
test(recipes): add third-party-api recipe e2e tests
Add end-to-end tests for the third-party-api recipe which demonstrates integrating external GraphQL APIs (Rick & Morty) with Oxygen's caching. Tests verify: - Characters section renders with heading and description - Character list populates from the live API - Existing homepage sections (featured collection, recommended products) are preserved alongside the third-party content Rebased from PR #3549 onto main, deferring all conflicts to main's already-evolved infrastructure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b4462f4 commit fef85fd

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {test, expect, setRecipeFixture} from '../../fixtures';
2+
3+
setRecipeFixture({
4+
recipeName: 'third-party-api',
5+
storeKey: 'hydrogenPreviewStorefront',
6+
});
7+
8+
/**
9+
* Validates the Third-party API recipe, which demonstrates integrating
10+
* external GraphQL APIs with Oxygen's caching system.
11+
*
12+
* The recipe adds a Rick & Morty characters section to the homepage that
13+
* displays data fetched server-side from rickandmortyapi.com GraphQL API in the loader.
14+
*
15+
* ⚠️ Note: These tests depend on rickandmortyapi.com being available.
16+
* If the external API is down, slow, or rate-limited, tests may fail.
17+
* This is expected behavior as the recipe is designed to call this live API.
18+
*/
19+
20+
const RECIPE_HEADING_TEXT = 'Rick & Morty Characters (Third-Party API Example)';
21+
22+
// The skeleton queries the most recently updated collection, which may change over time.
23+
// If this collection is removed or renamed in hydrogenPreviewStorefront, update this constant.
24+
const KNOWN_FEATURED_COLLECTION = {
25+
title: 'Hats and Accessories',
26+
} as const;
27+
28+
test.describe('Third-party API Recipe', () => {
29+
test.beforeEach(async ({page}) => {
30+
await page.goto('/');
31+
});
32+
33+
test('displays Rick and Morty characters section with heading', async ({
34+
page,
35+
}) => {
36+
const heading = page.getByRole('heading', {
37+
name: RECIPE_HEADING_TEXT,
38+
});
39+
await expect(heading).toBeVisible();
40+
41+
const description = page.getByText(
42+
/This data is fetched from rickandmortyapi\.com GraphQL API/i,
43+
);
44+
await expect(description).toBeVisible();
45+
});
46+
47+
test('renders character list from third-party API', async ({page}) => {
48+
const recipeHeading = page.getByRole('heading', {
49+
name: RECIPE_HEADING_TEXT,
50+
});
51+
const recipeSection = page.locator('section').filter({has: recipeHeading});
52+
const characterList = recipeSection.getByRole('list');
53+
54+
await expect(recipeSection).toBeVisible();
55+
await expect(characterList).toHaveCount(1);
56+
await expect(characterList).toBeVisible();
57+
58+
const characters = characterList.getByRole('listitem');
59+
await expect(characters.first()).toBeVisible();
60+
await expect(characters.nth(1)).toBeVisible();
61+
await expect.poll(() => characters.count()).toBeGreaterThan(1);
62+
await expect(characters.first()).not.toHaveText(/^\s*$/);
63+
await expect(characters.first()).toContainText(/[A-Za-z]/);
64+
});
65+
66+
test('preserves existing homepage sections alongside third-party content', async ({
67+
page,
68+
}) => {
69+
const featuredCollectionHeading = page.getByRole('heading', {
70+
level: 1,
71+
name: KNOWN_FEATURED_COLLECTION.title,
72+
});
73+
await expect(featuredCollectionHeading).toBeVisible();
74+
75+
const recommendedProductsSection = page.getByRole('region', {
76+
name: 'Recommended Products',
77+
});
78+
await expect(recommendedProductsSection).toBeVisible();
79+
80+
const recommendedProductLinks =
81+
recommendedProductsSection.getByRole('link');
82+
await expect(recommendedProductLinks.first()).toBeVisible();
83+
await expect.poll(() => recommendedProductLinks.count()).toBeGreaterThan(0);
84+
});
85+
});

0 commit comments

Comments
 (0)