Skip to content

Commit

Permalink
feat: implement modules page
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Aug 1, 2024
1 parent 6c6e4c6 commit 2cbcbcc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,14 @@ export default async function CourseHomePage({params}: Props) {
const courseId = await getCourseId(params)
const detail = await getCourseDetail(courseId)

return <h1>{detail.targetLanguage.name}</h1>
return <><h1>{detail.targetLanguage.name}</h1>
<ul className="flex space-y-6 flex-col p-6">
{detail.modules.map((module) => (
<li key={module.slug}>
{module.title}
</li>
))}
</ul>

</>
}
4 changes: 3 additions & 1 deletion apps/librelingo-web/src/data/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ export async function getCourseId(
}

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

return {
targetLanguage: {
name: languageName,
},
modules,
}
}
23 changes: 23 additions & 0 deletions e2e-tests/course.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,26 @@ test('has the correct content', async ({ page }) => {
page.getByRole('heading', { name: 'Test Language' })
).toBeVisible()
})

test('has cards leading to module pages', async ({ page }) => {
const courseHomePagePattern = new RegExp(
`[^/]*/courses/[^/]+/modules/[^/]+`
)
await page.goto('/en/courses/test-1')

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

expect(cards.length).toBeGreaterThanOrEqual(1)
const urls = new Set()

for (const card of cards) {
const button = card.getByRole('link', { name: 'Learn' })
const url = await button.getAttribute('href')

expect(url).toMatch(courseHomePagePattern)
urls.add(url)
}

// each course has to have a unique url
expect(urls.size).toBeGreaterThanOrEqual(cards.length)
})
4 changes: 3 additions & 1 deletion e2e-tests/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ test('has the correct content', async ({ page }) => {
await expect(firstCard.getByRole('link', { name: 'Learn' })).toBeVisible()
})

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

Expand Down
1 change: 1 addition & 0 deletions src/librelingo_json_export/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_levels(words, phrases):
return calculate_number_of_levels(len(words), len(phrases))

return {
"slug": slugify(module.title),
"title": module.title,
"skills": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test__get_course_data_return_value():
},
"modules": [
{
"slug": "basics",
"title": "Basics",
"skills": [
{
Expand Down Expand Up @@ -67,7 +68,7 @@ def test__get_course_data_return_value():
},
],
},
{"title": "Phrases", "skills": []},
{"slug": "phrases", "title": "Phrases", "skills": []},
],
}

Expand All @@ -89,6 +90,7 @@ def test__get_course_data_return_value_2():
},
"modules": [
{
"slug": "animals",
"title": "Animals",
"skills": [
{
Expand Down Expand Up @@ -122,6 +124,7 @@ def test__get_course_data_return_value_with_introduction():
},
"modules": [
{
"slug": "animals",
"title": "Animals",
"skills": [
{
Expand Down

0 comments on commit 2cbcbcc

Please sign in to comment.