Skip to content

Commit db9ea50

Browse files
committed
test: custom metadata
1 parent 01adc8a commit db9ea50

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
import { getCollection } from 'astro:content';
3+
const collection = await getCollection('tutorial');
4+
5+
const lesson = collection.find((c) => c.data.type === 'lesson' && c.slug.startsWith(Astro.params.slug!))!;
6+
const { custom } = lesson.data;
7+
---
8+
9+
<h2>Custom metadata</h2>
10+
11+
<pre>{JSON.stringify(custom, null,2)}</pre>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
type: lesson
3+
title: Custom
4+
terminal:
5+
panels: terminal
6+
custom:
7+
custom-message: 'Hello world'
8+
numeric-field: 5173
9+
---
10+
11+
import CustomMetaData from "@components/CustomMetadata.astro"
12+
13+
# Metadata test - Custom
14+
15+
<CustomMetaData />
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: chapter
3+
title: Metadata
4+
---

e2e/test/metadata.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const BASE_URL = '/tests/metadata';
4+
5+
test('developer can pass custom metadata to lesson', async ({ page }) => {
6+
await page.goto(`${BASE_URL}/custom`);
7+
await expect(page.getByRole('heading', { level: 1, name: 'Metadata test - Custom' })).toBeVisible();
8+
9+
await expect(page.getByRole('heading', { level: 2, name: 'Custom metadata' })).toBeVisible();
10+
11+
await expect(page.getByText('"custom-message": "Hello world"')).toBeVisible();
12+
await expect(page.getByText('"numeric-field": 5173')).toBeVisible();
13+
});

0 commit comments

Comments
 (0)