Skip to content

Commit 0db6be5

Browse files
committed
more progress
1 parent f286d5d commit 0db6be5

File tree

24 files changed

+848
-14
lines changed

24 files changed

+848
-14
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform client-side routing', async ({
4+
page,
5+
}) => {
6+
await page.goto('/')
7+
let reloadCount = 0
8+
9+
// Listen for 'load' event which triggers on page reload
10+
page.on('load', () => {
11+
reloadCount++
12+
})
13+
14+
// Wait for the page to load
15+
await page.waitForSelector('a')
16+
17+
// Get the first link
18+
const firstLink = await page.locator('a').first()
19+
20+
// Get the href attribute of the first link
21+
const href = await firstLink.getAttribute('href')
22+
23+
// Click the first link
24+
await firstLink.click()
25+
26+
// Wait for the URL to change
27+
await page.waitForURL(`**${href}`)
28+
29+
// Verify the URL has updated
30+
expect(page.url()).toContain(href)
31+
32+
// Verify no reloads occurred
33+
expect(reloadCount).toBe(0)
34+
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform search', async ({ page }) => {
4+
await page.goto('/')
5+
await expect(page).toHaveTitle('Starship Deets')
6+
7+
// Check for the filter input
8+
const filterInput = page.getByPlaceholder('filter ships')
9+
await expect(filterInput).toBeVisible()
10+
11+
// Perform a search
12+
await filterInput.fill('hopper')
13+
await filterInput.press('Enter')
14+
15+
// Verify URL change with search params
16+
await expect(page).toHaveURL('/?search=hopper')
17+
18+
// Verify filtered results
19+
const shipLinks = page
20+
.getByRole('list')
21+
.first()
22+
.getByRole('listitem')
23+
.getByRole('link')
24+
for (const link of await shipLinks.all()) {
25+
await expect(link).toContainText('hopper', { ignoreCase: true })
26+
}
27+
28+
// Find and click on a ship in the filtered list
29+
const shipLink = shipLinks.first()
30+
const shipName = await shipLink.textContent()
31+
await shipLink.click()
32+
33+
// Verify URL change
34+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
35+
36+
// Verify ship detail view
37+
const shipTitle = page.getByRole('heading', { level: 2 })
38+
await expect(shipTitle).toHaveText(shipName)
39+
})

exercises/04.router/01.problem.router/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform client-side routing', async ({
4+
page,
5+
}) => {
6+
await page.goto('/')
7+
let reloadCount = 0
8+
9+
// Listen for 'load' event which triggers on page reload
10+
page.on('load', () => {
11+
reloadCount++
12+
})
13+
14+
// Wait for the page to load
15+
await page.waitForSelector('a')
16+
17+
// Get the first link
18+
const firstLink = await page.locator('a').first()
19+
20+
// Get the href attribute of the first link
21+
const href = await firstLink.getAttribute('href')
22+
23+
// Click the first link
24+
await firstLink.click()
25+
26+
// Wait for the URL to change
27+
await page.waitForURL(`**${href}`)
28+
29+
// Verify the URL has updated
30+
expect(page.url()).toContain(href)
31+
32+
// Verify no reloads occurred
33+
expect(reloadCount).toBe(0)
34+
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform search', async ({ page }) => {
4+
await page.goto('/')
5+
await expect(page).toHaveTitle('Starship Deets')
6+
7+
// Check for the filter input
8+
const filterInput = page.getByPlaceholder('filter ships')
9+
await expect(filterInput).toBeVisible()
10+
11+
// Perform a search
12+
await filterInput.fill('hopper')
13+
await filterInput.press('Enter')
14+
15+
// Verify URL change with search params
16+
await expect(page).toHaveURL('/?search=hopper')
17+
18+
// Verify filtered results
19+
const shipLinks = page
20+
.getByRole('list')
21+
.first()
22+
.getByRole('listitem')
23+
.getByRole('link')
24+
for (const link of await shipLinks.all()) {
25+
await expect(link).toContainText('hopper', { ignoreCase: true })
26+
}
27+
28+
// Find and click on a ship in the filtered list
29+
const shipLink = shipLinks.first()
30+
const shipName = await shipLink.textContent()
31+
await shipLink.click()
32+
33+
// Verify URL change
34+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
35+
36+
// Verify ship detail view
37+
const shipTitle = page.getByRole('heading', { level: 2 })
38+
await expect(shipTitle).toHaveText(shipName)
39+
})

exercises/04.router/01.solution.router/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform search', async ({ page }) => {
4+
await page.goto('/')
5+
await expect(page).toHaveTitle('Starship Deets')
6+
7+
// Check for the filter input
8+
const filterInput = page.getByPlaceholder('filter ships')
9+
await expect(filterInput).toBeVisible()
10+
11+
// Perform a search
12+
await filterInput.fill('hopper')
13+
await filterInput.press('Enter')
14+
15+
// Verify URL change with search params
16+
await expect(page).toHaveURL('/?search=hopper')
17+
18+
// Verify filtered results
19+
const shipLinks = page
20+
.getByRole('list')
21+
.first()
22+
.getByRole('listitem')
23+
.getByRole('link')
24+
for (const link of await shipLinks.all()) {
25+
await expect(link).toContainText('hopper', { ignoreCase: true })
26+
}
27+
28+
// Find and click on a ship in the filtered list
29+
const shipLink = shipLinks.first()
30+
const shipName = await shipLink.textContent()
31+
await shipLink.click()
32+
33+
// Verify URL change
34+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
35+
36+
// Verify ship detail view
37+
const shipTitle = page.getByRole('heading', { level: 2 })
38+
await expect(shipTitle).toHaveText(shipName)
39+
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform search', async ({ page }) => {
4+
await page.goto('/')
5+
await expect(page).toHaveTitle('Starship Deets')
6+
7+
// Check for the filter input
8+
const filterInput = page.getByPlaceholder('filter ships')
9+
await expect(filterInput).toBeVisible()
10+
11+
// Perform a search
12+
await filterInput.fill('hopper')
13+
await filterInput.press('Enter')
14+
15+
// Verify URL change with search params
16+
await expect(page).toHaveURL('/?search=hopper')
17+
18+
// Verify filtered results
19+
const shipLinks = page
20+
.getByRole('list')
21+
.first()
22+
.getByRole('listitem')
23+
.getByRole('link')
24+
for (const link of await shipLinks.all()) {
25+
await expect(link).toContainText('hopper', { ignoreCase: true })
26+
}
27+
28+
// Find and click on a ship in the filtered list
29+
const shipLink = shipLinks.first()
30+
const shipName = await shipLink.textContent()
31+
await shipLink.click()
32+
33+
// Verify URL change
34+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
35+
36+
// Verify ship detail view
37+
const shipTitle = page.getByRole('heading', { level: 2 })
38+
await expect(shipTitle).toHaveText(shipName)
39+
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform search', async ({ page }) => {
4+
await page.goto('/')
5+
await expect(page).toHaveTitle('Starship Deets')
6+
7+
// Check for the filter input
8+
const filterInput = page.getByPlaceholder('filter ships')
9+
await expect(filterInput).toBeVisible()
10+
11+
// Perform a search
12+
await filterInput.fill('hopper')
13+
await filterInput.press('Enter')
14+
15+
// Verify URL change with search params
16+
await expect(page).toHaveURL('/?search=hopper')
17+
18+
// Verify filtered results
19+
const shipLinks = page
20+
.getByRole('list')
21+
.first()
22+
.getByRole('listitem')
23+
.getByRole('link')
24+
for (const link of await shipLinks.all()) {
25+
await expect(link).toContainText('hopper', { ignoreCase: true })
26+
}
27+
28+
// Find and click on a ship in the filtered list
29+
const shipLink = shipLinks.first()
30+
const shipName = await shipLink.textContent()
31+
await shipLink.click()
32+
33+
// Verify URL change
34+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
35+
36+
// Verify ship detail view
37+
const shipTitle = page.getByRole('heading', { level: 2 })
38+
await expect(shipTitle).toHaveText(shipName)
39+
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('should display the home page and perform search', async ({ page }) => {
4+
await page.goto('/')
5+
await expect(page).toHaveTitle('Starship Deets')
6+
7+
// Check for the filter input
8+
const filterInput = page.getByPlaceholder('filter ships')
9+
await expect(filterInput).toBeVisible()
10+
11+
// Perform a search
12+
await filterInput.fill('hopper')
13+
await filterInput.press('Enter')
14+
15+
// Verify URL change with search params
16+
await expect(page).toHaveURL('/?search=hopper')
17+
18+
// Verify filtered results
19+
const shipLinks = page
20+
.getByRole('list')
21+
.first()
22+
.getByRole('listitem')
23+
.getByRole('link')
24+
for (const link of await shipLinks.all()) {
25+
await expect(link).toContainText('hopper', { ignoreCase: true })
26+
}
27+
28+
// Find and click on a ship in the filtered list
29+
const shipLink = shipLinks.first()
30+
const shipName = await shipLink.textContent()
31+
await shipLink.click()
32+
33+
// Verify URL change
34+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
35+
36+
// Verify ship detail view
37+
const shipTitle = page.getByRole('heading', { level: 2 })
38+
await expect(shipTitle).toHaveText(shipName)
39+
})

0 commit comments

Comments
 (0)