-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathhome.spec.ts
More file actions
34 lines (25 loc) · 1.01 KB
/
home.spec.ts
File metadata and controls
34 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { test, expect } from '@playwright/test'
test('has the correct content', async ({ page }) => {
await page.goto('/')
const firstCard = page.getByRole('listitem').first()
await expect(page).toHaveTitle('LibreLingo')
await expect(firstCard.getByRole('heading')).toBeVisible()
await expect(firstCard.getByRole('link', { name: 'Learn' })).toBeVisible()
})
test('has cards for each course leading to the course page', async ({
page,
}) => {
const courseHomePagePattern = new RegExp(`[^/]*/courses/[^/]+`)
await page.goto('/')
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)
})