Skip to content

Commit 6c6e4c6

Browse files
committed
feat: implement page heading on modules page
1 parent 49c04b3 commit 6c6e4c6

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { listAvailableCourses } from "@/data/course"
1+
import { getCourseDetail, getCourseId, listAvailableCourses } from "@/data/course"
22

33
export async function generateStaticParams() {
44
const courses = await listAvailableCourses()
@@ -9,6 +9,16 @@ export async function generateStaticParams() {
99
}))
1010
}
1111

12-
export default function CourseHomePage() {
13-
return <h1>Hello world</h1>
12+
type Props = {
13+
params: {
14+
sourceLanguageCode: string
15+
targetLanguageCode: string
16+
}
17+
}
18+
19+
export default async function CourseHomePage({params}: Props) {
20+
const courseId = await getCourseId(params)
21+
const detail = await getCourseDetail(courseId)
22+
23+
return <h1>{detail.targetLanguage.name}</h1>
1424
}

Diff for: apps/librelingo-web/src/data/course.ts

+36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
'use server'
2+
13
import path from 'node:path'
24
import courseConfig from '@/courses/config.json'
35
import fs from 'node:fs'
6+
import { notFound } from 'next/navigation'
7+
8+
export type CourseIdentityDescription = {
9+
sourceLanguageCode: string
10+
targetLanguageCode: string
11+
}
412

513
export type Course = {
614
id: string
@@ -59,3 +67,31 @@ export async function listAvailableCourses(): Promise<Course[]> {
5967
})
6068
)
6169
}
70+
71+
export async function getCourseId(
72+
parameters: CourseIdentityDescription
73+
): Promise<string> {
74+
const availableCourses = await listAvailableCourses()
75+
76+
const course = availableCourses.find(
77+
(item) =>
78+
item.uiLanguage === parameters.sourceLanguageCode &&
79+
item.languageCode === parameters.targetLanguageCode
80+
)
81+
82+
if (course === undefined) {
83+
notFound()
84+
}
85+
86+
return course.id
87+
}
88+
89+
export async function getCourseDetail(courseId: string) {
90+
const { languageName } = await getCourseMetadataByJsonPath(courseId)
91+
92+
return {
93+
targetLanguage: {
94+
name: languageName,
95+
},
96+
}
97+
}

Diff for: e2e-tests/course.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('has the correct content', async ({ page }) => {
4+
await page.goto('/en/courses/test-1')
5+
6+
await expect(
7+
page.getByRole('heading', { name: 'Test Language' })
8+
).toBeVisible()
9+
})

Diff for: e2e-tests/home.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { test, expect } from '@playwright/test'
22

3-
const baseURL = 'http://localhost:3000/'
4-
53
test('has the correct content', async ({ page }) => {
6-
await page.goto(baseURL)
4+
await page.goto('/')
75

86
const firstCard = page.getByRole('listitem').first()
97

@@ -14,7 +12,7 @@ test('has the correct content', async ({ page }) => {
1412

1513
test('all card buttons lead to URLs matching the pattern', async ({ page }) => {
1614
const courseHomePagePattern = new RegExp(`[^/]*/courses/[^/]+`)
17-
await page.goto(baseURL)
15+
await page.goto('/')
1816

1917
const cards = await page.getByRole('listitem').all()
2018

Diff for: playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default defineConfig({
2424
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2525
use: {
2626
/* Base URL to use in actions like `await page.goto('/')`. */
27-
// baseURL: 'http://127.0.0.1:3000',
27+
baseURL: 'http://127.0.0.1:3000',
2828

2929
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3030
trace: 'on-first-retry',

0 commit comments

Comments
 (0)