Skip to content
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

feat: implement page heading on modules page #3391

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { listAvailableCourses } from "@/data/course"
import { getCourseDetail, getCourseId, listAvailableCourses } from "@/data/course"

export async function generateStaticParams() {
const courses = await listAvailableCourses()
Expand All @@ -9,6 +9,16 @@ export async function generateStaticParams() {
}))
}

export default function CourseHomePage() {
return <h1>Hello world</h1>
type Props = {
params: {
sourceLanguageCode: string
targetLanguageCode: string
}
}

export default async function CourseHomePage({params}: Props) {
const courseId = await getCourseId(params)
const detail = await getCourseDetail(courseId)

return <h1>{detail.targetLanguage.name}</h1>
}
36 changes: 36 additions & 0 deletions apps/librelingo-web/src/data/course.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use server'

import path from 'node:path'
import courseConfig from '@/courses/config.json'
import fs from 'node:fs'
import { notFound } from 'next/navigation'

export type CourseIdentityDescription = {
sourceLanguageCode: string
targetLanguageCode: string
}

export type Course = {
id: string
Expand Down Expand Up @@ -59,3 +67,31 @@ export async function listAvailableCourses(): Promise<Course[]> {
})
)
}

export async function getCourseId(
parameters: CourseIdentityDescription
): Promise<string> {
const availableCourses = await listAvailableCourses()

const course = availableCourses.find(
(item) =>
item.uiLanguage === parameters.sourceLanguageCode &&
item.languageCode === parameters.targetLanguageCode
)

if (course === undefined) {
notFound()
}

return course.id
}

export async function getCourseDetail(courseId: string) {
const { languageName } = await getCourseMetadataByJsonPath(courseId)

return {
targetLanguage: {
name: languageName,
},
}
}
9 changes: 9 additions & 0 deletions e2e-tests/course.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from '@playwright/test'

test('has the correct content', async ({ page }) => {
await page.goto('/en/courses/test-1')

await expect(
page.getByRole('heading', { name: 'Test Language' })
).toBeVisible()
})
6 changes: 2 additions & 4 deletions e2e-tests/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { test, expect } from '@playwright/test'

const baseURL = 'http://localhost:3000/'

test('has the correct content', async ({ page }) => {
await page.goto(baseURL)
await page.goto('/')

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
baseURL: 'http://127.0.0.1:3000',

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