-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
home.spec.ts
72 lines (50 loc) · 2.21 KB
/
home.spec.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { test } from '@japa/runner'
test.group('E2E', (group) => {
group.tap((t) => t.skip(!!process.env.CI, 'skipping on CI for now since it is timing out'))
test('see homepage', async ({ visit }) => {
const page = await visit('/')
await page.waitForSelector('.hero')
await page.assertTextContains('body', 'Discover the best')
})
test('display packages', async ({ visit }) => {
const page = await visit('/')
await page.waitForSelector('.card')
await page.assertElementsCount('.card', 9)
})
test('clicking on a card open the package page', async ({ visit }) => {
const page = await visit('/')
await page.waitForSelector('.card')
const firstPackageName = page.getByTestId('package-name').first()
const packageName = await firstPackageName.textContent()
await firstPackageName.click()
await page.waitForURL(`/packages/${packageName}`)
await page.assertTextContains('body', packageName!)
})
test('can sort packages by stars', async ({ assert, visit }) => {
const page = await visit('/')
await page.waitForSelector('.card')
const sortByButton = page.getByTestId('sort-by')
await sortByButton.click()
await sortByButton
.locator('ul')
.getByRole('option')
.filter({ hasText: /stars/ })
.first()
.click()
const allPackageStars = await page.$$('[data-testid="package-stars"]')
const stars = await Promise.all(allPackageStars.map((el) => el.textContent()))
const sortedStars = [...stars].sort((a, b) => Number(b) - Number(a))
assert.deepEqual(stars, sortedStars)
assert.deepEqual(stars.length, 9)
})
test('can filter packages by category', async ({ assert, visit }) => {
const page = await visit('/')
const categoryButton = page.getByTestId('category-button').first()
const categoryLabel = await categoryButton.getByTestId('category-label').first().textContent()
await categoryButton.click()
const allPackagesCategories = await page.$$('[data-testid="package-category"]')
const categories = await Promise.all(allPackagesCategories.map((el) => el.textContent()))
const uniqueCategories = [...new Set(categories)]
assert.deepEqual(uniqueCategories, [categoryLabel])
})
})