Skip to content

Commit f286d5d

Browse files
committed
finish tests for exercise 3
1 parent 1f637e2 commit f286d5d

File tree

34 files changed

+216
-52
lines changed

34 files changed

+216
-52
lines changed
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/03.client-components/01.problem.loader/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

exercises/03.client-components/01.problem.loader/ui/edit-text.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function EditableText({ id, shipId, initialValue = '' }) {
6464
: h(
6565
'button',
6666
{
67-
'aria-label': 'Ship Name',
6867
ref: buttonRef,
6968
type: 'button',
7069
style: {
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/03.client-components/01.solution.loader/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

exercises/03.client-components/01.solution.loader/ui/edit-text.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function EditableText({ id, shipId, initialValue = '' }) {
6464
: h(
6565
'button',
6666
{
67-
'aria-label': 'Ship Name',
6867
ref: buttonRef,
6968
type: 'button',
7069
style: {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { test, expect } from '@playwright/test'
2+
import { searchShips } from '../db/ship-api.js'
3+
4+
test('should display the home page and perform search', async ({ page }) => {
5+
const {
6+
ships: [ship],
7+
} = await searchShips({ search: 'hopper' })
8+
const newName = `${ship.name} 🚀`
9+
await page.goto(`/${ship.id}`)
10+
11+
// Wait for the loading state to disappear
12+
await page.waitForSelector('h2:has-text("Loading...")', { state: 'detached' })
13+
14+
// Ensure the ship name is visible
15+
await expect(page.getByRole('heading', { name: ship.name })).toBeVisible()
16+
// Find and click the edit button
17+
await page.getByRole('button', { name: ship.name }).click()
18+
19+
// Check if the input is focused
20+
await expect(page.getByRole('textbox', { name: 'Ship Name' })).toBeFocused()
21+
22+
// Change the value of the input
23+
await page.getByRole('textbox', { name: 'Ship Name' }).fill(newName)
24+
25+
// Press Enter
26+
await page.keyboard.press('Enter')
27+
28+
// Check if the button is back
29+
await expect(page.getByRole('button', { name: newName })).toBeVisible()
30+
})
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/03.client-components/02.problem.module-resolution/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

exercises/03.client-components/02.problem.module-resolution/ui/edit-text.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function EditableText({ id, shipId, initialValue = '' }) {
6464
: h(
6565
'button',
6666
{
67-
'aria-label': 'Ship Name',
6867
ref: buttonRef,
6968
type: 'button',
7069
style: {

0 commit comments

Comments
 (0)