Skip to content

Commit ad6ad6b

Browse files
committed
test: lessons in root and part
1 parent 65386de commit ad6ad6b

File tree

17 files changed

+165
-7
lines changed

17 files changed

+165
-7
lines changed

e2e/configs/lessons-in-part.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import tutorialkit from '@tutorialkit/astro';
2+
import { defineConfig } from 'astro/config';
3+
4+
export default defineConfig({
5+
devToolbar: { enabled: false },
6+
server: { port: 4332 },
7+
outDir: './dist-lessons-in-part',
8+
integrations: [tutorialkit()],
9+
srcDir: './src-custom/lessons-in-part',
10+
});

e2e/configs/lessons-in-root.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import tutorialkit from '@tutorialkit/astro';
2+
import { defineConfig } from 'astro/config';
3+
4+
export default defineConfig({
5+
devToolbar: { enabled: false },
6+
server: { port: 4331 },
7+
outDir: './dist-lessons-in-root',
8+
integrations: [tutorialkit()],
9+
srcDir: './src-custom/lessons-in-root',
10+
});

e2e/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"preview": "astro build && astro preview",
88
"dev:override-components": "astro dev --config ./configs/override-components.ts",
99
"preview:override-components": "astro build --config ./configs/override-components.ts && astro preview --config ./configs/override-components.ts",
10+
"dev:lessons-in-root": "astro dev --config ./configs/lessons-in-root.ts",
11+
"preview:lessons-in-root": "astro build --config ./configs/lessons-in-root.ts && astro preview --config ./configs/lessons-in-root.ts",
12+
"dev:lessons-in-part": "astro dev --config ./configs/lessons-in-part.ts",
13+
"preview:lessons-in-part": "astro build --config ./configs/lessons-in-part.ts && astro preview --config ./configs/lessons-in-part.ts",
1014
"test": "playwright test",
1115
"test:ui": "pnpm run test --ui"
1216
},

e2e/playwright.config.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,59 @@
11
import { defineConfig } from '@playwright/test';
22

3+
const serverOptions = {
4+
reuseExistingServer: !process.env.CI,
5+
stdout: 'ignore',
6+
stderr: 'pipe',
7+
} as const;
8+
39
export default defineConfig({
410
projects: [
511
{
612
name: 'Default',
713
testMatch: 'test/*.test.ts',
8-
testIgnore: 'test/*.override-components.test.ts',
14+
testIgnore: [
15+
'test/*.override-components.test.ts',
16+
'test/*.lessons-in-part.test.ts',
17+
'test/*.lessons-in-root.test.ts',
18+
],
919
use: { baseURL: 'http://localhost:4329' },
1020
},
1121
{
1222
name: 'Override Components',
1323
testMatch: 'test/*.override-components.test.ts',
1424
use: { baseURL: 'http://localhost:4330' },
1525
},
26+
{
27+
name: 'Lessons in root',
28+
testMatch: 'test/*.lessons-in-root.test.ts',
29+
use: { baseURL: 'http://localhost:4331' },
30+
},
31+
{
32+
name: 'Lessons in part',
33+
testMatch: 'test/*.lessons-in-part.test.ts',
34+
use: { baseURL: 'http://localhost:4332' },
35+
},
1636
],
1737
webServer: [
1838
{
1939
command: 'pnpm preview',
2040
url: 'http://localhost:4329',
21-
reuseExistingServer: !process.env.CI,
22-
stdout: 'ignore',
23-
stderr: 'pipe',
41+
...serverOptions,
2442
},
2543
{
2644
command: 'pnpm preview:override-components',
2745
url: 'http://localhost:4330',
28-
reuseExistingServer: !process.env.CI,
29-
stdout: 'ignore',
30-
stderr: 'pipe',
46+
...serverOptions,
47+
},
48+
{
49+
command: 'pnpm preview:lessons-in-root',
50+
url: 'http://localhost:4331',
51+
...serverOptions,
52+
},
53+
{
54+
command: 'pnpm preview:lessons-in-part',
55+
url: 'http://localhost:4332',
56+
...serverOptions,
3157
},
3258
],
3359
expect: {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { contentSchema } from '@tutorialkit/types';
2+
import { defineCollection } from 'astro:content';
3+
4+
const tutorial = defineCollection({
5+
type: 'content',
6+
schema: contentSchema,
7+
});
8+
9+
export const collections = { tutorial };
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: tutorial
3+
mainCommand: ''
4+
prepareCommands: []
5+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: lesson
3+
title: Lesson one
4+
---
5+
6+
# Lessons in part test - Lesson one
7+
8+
Lesson in part without chapter
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: lesson
3+
title: Lesson two
4+
---
5+
6+
# Lessons in part test - Lesson two
7+
8+
Lesson in part without chapter
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: part
3+
title: 'Part one'
4+
---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path="../../.astro/types.d.ts" />
2+
/// <reference types="@tutorialkit/astro/types" />
3+
/// <reference types="astro/client" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { contentSchema } from '@tutorialkit/types';
2+
import { defineCollection } from 'astro:content';
3+
4+
const tutorial = defineCollection({
5+
type: 'content',
6+
schema: contentSchema,
7+
});
8+
9+
export const collections = { tutorial };
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: lesson
3+
title: Lesson one
4+
---
5+
6+
# Lessons in root test - Lesson one
7+
8+
Lesson in root without part
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: lesson
3+
title: Lesson two
4+
---
5+
6+
# Lessons in root test - Lesson two
7+
8+
Lesson in root without part
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: tutorial
3+
mainCommand: ''
4+
prepareCommands: []
5+
---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path="../../.astro/types.d.ts" />
2+
/// <reference types="@tutorialkit/astro/types" />
3+
/// <reference types="astro/client" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('user can navigate between lessons using breadcrumbs', async ({ page }) => {
4+
await page.goto('/part-one/lesson-one');
5+
6+
await expect(page.getByRole('heading', { level: 1, name: 'Lessons in part test - Lesson one' })).toBeVisible();
7+
await expect(page.getByText('Lesson in part without chapter')).toBeVisible();
8+
9+
// navigation select can take a while to hydrate on page load, click until responsive
10+
await expect(async () => {
11+
const button = page.getByRole('button', { name: 'Part one / Lesson one' });
12+
await button.click();
13+
await expect(page.locator('[data-state="open"]', { has: button })).toBeVisible({ timeout: 50 });
14+
}).toPass();
15+
16+
await page.getByRole('navigation').getByRole('link', { name: 'Lesson two' }).click();
17+
18+
await expect(page.getByRole('heading', { level: 1, name: 'Lessons in part test - Lesson two' })).toBeVisible();
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('user can navigate between lessons using breadcrumbs', async ({ page }) => {
4+
await page.goto('/lesson-one');
5+
6+
await expect(page.getByRole('heading', { level: 1, name: 'Lessons in root test - Lesson one' })).toBeVisible();
7+
await expect(page.getByText('Lesson in root without part')).toBeVisible();
8+
9+
// navigation select can take a while to hydrate on page load, click until responsive
10+
await expect(async () => {
11+
const button = page.getByRole('button', { name: 'Lesson one' });
12+
await button.click();
13+
await expect(page.locator('[data-state="open"]', { has: button })).toBeVisible({ timeout: 50 });
14+
}).toPass();
15+
16+
await page.getByRole('navigation').getByRole('link', { name: 'Lesson two' }).click();
17+
18+
await expect(page.getByRole('heading', { level: 1, name: 'Lessons in root test - Lesson two' })).toBeVisible();
19+
});

0 commit comments

Comments
 (0)