Skip to content

Commit a31622d

Browse files
committed
finish tests
1 parent fcfead0 commit a31622d

File tree

16 files changed

+312
-46
lines changed

16 files changed

+312
-46
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('should display the home page and perform search', async ({ page }) => {
55
const {
66
ships: [ship],
77
} = await searchShips({ search: 'hopper' })
8-
const newName = `${ship.name} 🚀`
8+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
99
await page.goto(`/${ship.id}`)
1010

1111
// Wait for the loading state to disappear

exercises/03.client-components/02.solution.module-resolution/tests/edit-text.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('should display the home page and perform search', async ({ page }) => {
55
const {
66
ships: [ship],
77
} = await searchShips({ search: 'hopper' })
8-
const newName = `${ship.name} 🚀`
8+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
99
await page.goto(`/${ship.id}`)
1010

1111
// Wait for the loading state to disappear

exercises/05.actions/02.problem.client/tests/action-post.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('Submitting the form posts to the action endpoint correctly', async ({
1212

1313
await page.getByRole('button', { name: ship.name }).click()
1414

15-
const newName = `${ship.name} 🚀`
15+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
1616

1717
// Change the value of the input
1818
await page.getByRole('textbox', { name: 'Ship Name' }).fill(newName)

exercises/05.actions/02.solution.client/tests/action-post.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('Submitting the form posts to the action endpoint correctly', async ({
1212

1313
await page.getByRole('button', { name: ship.name }).click()
1414

15-
const newName = `${ship.name} 🚀`
15+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
1616

1717
// Change the value of the input
1818
await page.getByRole('textbox', { name: 'Ship Name' }).fill(newName)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { test, expect } from '@playwright/test'
2+
import { searchShips } from '../db/ship-api.js'
3+
4+
test('Submitting the form posts to the action endpoint correctly', async ({
5+
page,
6+
}) => {
7+
const {
8+
ships: [ship],
9+
} = await searchShips({ search: '' })
10+
await page.goto(`/${ship.id}`)
11+
await page.waitForLoadState('networkidle')
12+
13+
await page.getByRole('button', { name: ship.name }).click()
14+
15+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
16+
17+
// Change the value of the input
18+
await page.getByRole('textbox', { name: 'Ship Name' }).fill(newName)
19+
20+
// Intercept the request to /action
21+
const actionRequest = page.waitForRequest(request => {
22+
return request.url().includes('/action') && request.method() === 'POST'
23+
})
24+
25+
// Press Enter
26+
await page.keyboard.press('Enter')
27+
28+
// Wait for the request to be made
29+
const request = await actionRequest
30+
31+
// Verify the request URL
32+
expect(request.url()).toContain(`/action/${ship.id}`)
33+
34+
const response = await request.response()
35+
expect(response.status(), '🚨 have you made the action endpoint yet?').toBe(
36+
200,
37+
)
38+
39+
// Verify the form data payload
40+
const postData = await request.postData()
41+
expect(postData).toContain(newName)
42+
expect(postData).toContain(ship.id)
43+
44+
// Verify the rsc-action header
45+
const headers = request.headers()
46+
expect(headers['rsc-action']).toContain('ui/actions.js#updateShipName')
47+
48+
// Verify the response body
49+
const responseBody = await response.text()
50+
// it should have a returnValue and a root
51+
expect(responseBody).toContain('returnValue')
52+
expect(responseBody).toContain('root')
53+
// It should have the success message in the return value
54+
expect(responseBody).toContain('Success!')
55+
// And it should have updated the ship name
56+
expect(responseBody).toContain(newName)
57+
})

exercises/05.actions/03.problem.server/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { test, expect } from '@playwright/test'
2+
import { searchShips } from '../db/ship-api.js'
3+
4+
test('Submitting the form posts to the action endpoint correctly', async ({
5+
page,
6+
}) => {
7+
const {
8+
ships: [ship],
9+
} = await searchShips({ search: '' })
10+
await page.goto(`/${ship.id}`)
11+
await page.waitForLoadState('networkidle')
12+
13+
await page.getByRole('button', { name: ship.name }).click()
14+
15+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
16+
17+
// Change the value of the input
18+
await page.getByRole('textbox', { name: 'Ship Name' }).fill(newName)
19+
20+
// Intercept the request to /action
21+
const actionRequest = page.waitForRequest(request => {
22+
return request.url().includes('/action') && request.method() === 'POST'
23+
})
24+
25+
// Press Enter
26+
await page.keyboard.press('Enter')
27+
28+
// Wait for the request to be made
29+
const request = await actionRequest
30+
31+
// Verify the request URL
32+
expect(request.url()).toContain(`/action/${ship.id}`)
33+
34+
const response = await request.response()
35+
expect(response.status(), '🚨 have you made the action endpoint yet?').toBe(
36+
200,
37+
)
38+
39+
// Verify the form data payload
40+
const postData = await request.postData()
41+
expect(postData).toContain(newName)
42+
expect(postData).toContain(ship.id)
43+
44+
// Verify the rsc-action header
45+
const headers = request.headers()
46+
expect(headers['rsc-action']).toContain('ui/actions.js#updateShipName')
47+
48+
// Verify the response body
49+
const responseBody = await response.text()
50+
// it should have a returnValue and a root
51+
expect(responseBody).toContain('returnValue')
52+
expect(responseBody).toContain('root')
53+
// It should have the success message in the return value
54+
expect(responseBody).toContain('Success!')
55+
// And it should have updated the ship name
56+
expect(responseBody).toContain(newName)
57+
})

exercises/05.actions/03.solution.server/tests/solution.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { test, expect } from '@playwright/test'
2+
import { searchShips } from '../db/ship-api.js'
3+
4+
test('Submitting the form posts to the action endpoint correctly', async ({
5+
page,
6+
}) => {
7+
const {
8+
ships: [ship],
9+
} = await searchShips({ search: '' })
10+
await page.goto(`/${ship.id}`)
11+
await page.waitForLoadState('networkidle')
12+
13+
await page.getByRole('button', { name: ship.name }).click()
14+
15+
const newName = `${ship.name} ${Math.random().toString(16).slice(2, 5)}`
16+
17+
// Change the value of the input
18+
await page.getByRole('textbox', { name: 'Ship Name' }).fill(newName)
19+
20+
// Intercept the request to /action
21+
const actionRequest = page.waitForRequest(request => {
22+
return request.url().includes('/action') && request.method() === 'POST'
23+
})
24+
25+
// Press Enter
26+
await page.keyboard.press('Enter')
27+
28+
// Wait for the request to be made
29+
const request = await actionRequest
30+
31+
// Verify the request URL
32+
expect(request.url()).toContain(`/action/${ship.id}`)
33+
34+
const response = await request.response()
35+
expect(response.status(), '🚨 have you made the action endpoint yet?').toBe(
36+
200,
37+
)
38+
39+
// Verify the form data payload
40+
const postData = await request.postData()
41+
expect(postData).toContain(newName)
42+
expect(postData).toContain(ship.id)
43+
44+
// Verify the rsc-action header
45+
const headers = request.headers()
46+
expect(headers['rsc-action']).toContain('ui/actions.js#updateShipName')
47+
48+
// Verify the response body
49+
const responseBody = await response.text()
50+
// it should have a returnValue and a root
51+
expect(responseBody).toContain('returnValue')
52+
expect(responseBody).toContain('root')
53+
// It should have the success message in the return value
54+
expect(responseBody).toContain('Success!')
55+
// And it should have updated the ship name
56+
expect(responseBody).toContain(newName)
57+
58+
// Verify the name of the ship in the list has been updated
59+
await expect(
60+
await page.getByRole('list').getByText(newName),
61+
'🚨 the list of ships has not been updated. Make sure to update the RSC content with the root returned from the action call',
62+
).toBeVisible()
63+
})

exercises/05.actions/04.problem.revalidation/tests/solution.test.js

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

0 commit comments

Comments
 (0)