Skip to content

Commit 1f637e2

Browse files
committed
exercise 2 tests done
1 parent ff6c08f commit 1f637e2

File tree

8 files changed

+316
-24
lines changed

8 files changed

+316
-24
lines changed
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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)
739
})
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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)
739
})
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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)
739
})
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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)
739
})
Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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+
// Wait for the loading placeholders to disappear
12+
await page.waitForSelector('li a:has-text("... loading")', {
13+
state: 'detached',
14+
})
15+
16+
// Verify that the list is populated with actual ship names
17+
const shipList = page.getByRole('list').first()
18+
await expect(shipList.getByRole('link').first()).not.toHaveText('... loading')
19+
20+
// Perform a search
21+
await filterInput.fill('hopper')
22+
await filterInput.press('Enter')
23+
24+
// Verify URL change with search params
25+
await expect(page).toHaveURL('/?search=hopper')
26+
27+
// Check for loading indicators after search
28+
await expect(
29+
page.locator('li a:has-text("... loading")').first(),
30+
).toBeVisible()
31+
// Wait for the loading placeholders to disappear
32+
await page.waitForSelector('li a:has-text("... loading")', {
33+
state: 'detached',
34+
})
35+
36+
// Verify filtered results
37+
const shipLinks = page
38+
.getByRole('list')
39+
.first()
40+
.getByRole('listitem')
41+
.getByRole('link')
42+
for (const link of await shipLinks.all()) {
43+
await expect(link).toContainText('hopper', { ignoreCase: true })
44+
}
45+
46+
// Find and click on a ship in the filtered list
47+
const shipLink = shipLinks.first()
48+
const shipName = await shipLink.textContent()
49+
await shipLink.click()
50+
51+
// Verify URL change
52+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
53+
54+
// Verify ship detail view
55+
const shipTitle = page.getByRole('heading', { level: 2 })
56+
await expect(shipTitle).toHaveText(shipName)
757
})
Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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+
// Wait for the loading placeholders to disappear
12+
await page.waitForSelector('li a:has-text("... loading")', {
13+
state: 'detached',
14+
})
15+
16+
// Verify that the list is populated with actual ship names
17+
const shipList = page.getByRole('list').first()
18+
await expect(shipList.getByRole('link').first()).not.toHaveText('... loading')
19+
20+
// Perform a search
21+
await filterInput.fill('hopper')
22+
await filterInput.press('Enter')
23+
24+
// Verify URL change with search params
25+
await expect(page).toHaveURL('/?search=hopper')
26+
27+
// Check for loading indicators after search
28+
await expect(
29+
page.locator('li a:has-text("... loading")').first(),
30+
).toBeVisible()
31+
// Wait for the loading placeholders to disappear
32+
await page.waitForSelector('li a:has-text("... loading")', {
33+
state: 'detached',
34+
})
35+
36+
// Verify filtered results
37+
const shipLinks = page
38+
.getByRole('list')
39+
.first()
40+
.getByRole('listitem')
41+
.getByRole('link')
42+
for (const link of await shipLinks.all()) {
43+
await expect(link).toContainText('hopper', { ignoreCase: true })
44+
}
45+
46+
// Find and click on a ship in the filtered list
47+
const shipLink = shipLinks.first()
48+
const shipName = await shipLink.textContent()
49+
await shipLink.click()
50+
51+
// Verify URL change
52+
await expect(page).toHaveURL(/\/[a-zA-Z0-9-]+/)
53+
54+
// Verify ship detail view
55+
const shipTitle = page.getByRole('heading', { level: 2 })
56+
await expect(shipTitle).toHaveText(shipName)
757
})
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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)
739
})
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import { test, expect } from '@playwright/test'
22

3-
test('TODO: write an appropriate test for this exercise', async ({ page }) => {
3+
test('should display the home page and perform search', async ({ page }) => {
44
await page.goto('/')
5-
expect(true).toBe(true)
6-
// TODO: write a test for this exercise
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)
739
})

0 commit comments

Comments
 (0)