Skip to content

Commit 9841c41

Browse files
committed
tests for exercise 1
1 parent b651f40 commit 9841c41

18 files changed

+6195
-501
lines changed

epicshop/.diffignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
tsconfig.json
2+
*.test.*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const catResult = await testStep('The user can see the results', async () => {
16+
const result = screen.getByText(/caring for your feline friend/i)
17+
expect(result).toBeInTheDocument()
18+
return result
19+
})
20+
21+
await testStep('The user can search for a term', async () => {
22+
fireEvent.change(searchBox, { target: { value: 'dog' } })
23+
})
24+
25+
await testStep('The results are filtered', async () => {
26+
await dtl.waitFor(() => {
27+
expect(catResult).not.toBeInTheDocument()
28+
})
29+
await screen.findByText(/the joy of owning a dog/i)
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const dogCheckbox = await testStep(
16+
'The user can see the dog checkbox',
17+
async () => {
18+
const result = await screen.findByRole('checkbox', { name: /dog/i })
19+
expect(result).not.toBeChecked()
20+
return result
21+
},
22+
)
23+
24+
await testStep('The user can select the dog checkbox', async () => {
25+
fireEvent.click(dogCheckbox)
26+
expect(dogCheckbox).toBeChecked()
27+
})
28+
29+
await testStep(
30+
'Selecting the checkbox updates the search and results',
31+
async () => {
32+
// Check that the search box value has been updated
33+
expect(searchBox).toHaveValue('dog')
34+
35+
// Check that the results have been filtered
36+
await dtl.waitFor(async () => {
37+
await screen.findByText(/the joy of owning a dog/i)
38+
39+
const catResult = screen.queryByText(/caring for your feline friend/i)
40+
expect(catResult).not.toBeInTheDocument()
41+
})
42+
},
43+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const catResult = await testStep('The user can see the results', async () => {
16+
const result = screen.getByText(/caring for your feline friend/i)
17+
expect(result).toBeInTheDocument()
18+
return result
19+
})
20+
21+
await testStep('The user can search for a term', async () => {
22+
fireEvent.change(searchBox, { target: { value: 'dog' } })
23+
})
24+
25+
await testStep('The results are filtered', async () => {
26+
await dtl.waitFor(() => {
27+
expect(catResult).not.toBeInTheDocument()
28+
})
29+
await screen.findByText(/the joy of owning a dog/i)
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const dogCheckbox = await testStep(
16+
'The user can see the dog checkbox',
17+
async () => {
18+
const result = await screen.findByRole('checkbox', { name: /dog/i })
19+
expect(result).not.toBeChecked()
20+
return result
21+
},
22+
)
23+
24+
await testStep('The user can search for a checkbox value', async () => {
25+
fireEvent.change(searchBox, { target: { value: 'dog' } })
26+
})
27+
28+
await testStep('checkbox is checked automatically', async () => {
29+
expect(dogCheckbox).toBeChecked()
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const dogCheckbox = await testStep(
16+
'The user can see the dog checkbox',
17+
async () => {
18+
const result = await screen.findByRole('checkbox', { name: /dog/i })
19+
expect(result).not.toBeChecked()
20+
return result
21+
},
22+
)
23+
24+
await testStep('The user can select the dog checkbox', async () => {
25+
fireEvent.click(dogCheckbox)
26+
expect(dogCheckbox).toBeChecked()
27+
})
28+
29+
await testStep(
30+
'Selecting the checkbox updates the search and results',
31+
async () => {
32+
// Check that the search box value has been updated
33+
expect(searchBox).toHaveValue('dog')
34+
35+
// Check that the results have been filtered
36+
await dtl.waitFor(async () => {
37+
await screen.findByText(/the joy of owning a dog/i)
38+
39+
const catResult = screen.queryByText(/caring for your feline friend/i)
40+
expect(catResult).not.toBeInTheDocument()
41+
})
42+
},
43+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const catResult = await testStep('The user can see the results', async () => {
16+
const result = screen.getByText(/caring for your feline friend/i)
17+
expect(result).toBeInTheDocument()
18+
return result
19+
})
20+
21+
await testStep('The user can search for a term', async () => {
22+
fireEvent.change(searchBox, { target: { value: 'dog' } })
23+
})
24+
25+
await testStep('The results are filtered', async () => {
26+
await dtl.waitFor(() => {
27+
expect(catResult).not.toBeInTheDocument()
28+
})
29+
await screen.findByText(/the joy of owning a dog/i)
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const dogCheckbox = await testStep(
16+
'The user can see the dog checkbox',
17+
async () => {
18+
const result = await screen.findByRole('checkbox', { name: /dog/i })
19+
expect(result).not.toBeChecked()
20+
return result
21+
},
22+
)
23+
24+
await testStep('The user can search for a checkbox value', async () => {
25+
fireEvent.change(searchBox, { target: { value: 'dog' } })
26+
})
27+
28+
await testStep('checkbox is checked automatically', async () => {
29+
expect(dogCheckbox).toBeChecked()
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const dogCheckbox = await testStep(
16+
'The user can see the dog checkbox',
17+
async () => {
18+
const result = await screen.findByRole('checkbox', { name: /dog/i })
19+
expect(result).not.toBeChecked()
20+
return result
21+
},
22+
)
23+
24+
await testStep('The user can select the dog checkbox', async () => {
25+
fireEvent.click(dogCheckbox)
26+
expect(dogCheckbox).toBeChecked()
27+
})
28+
29+
await testStep(
30+
'Selecting the checkbox updates the search and results',
31+
async () => {
32+
// Check that the search box value has been updated
33+
expect(searchBox).toHaveValue('dog')
34+
35+
// Check that the results have been filtered
36+
await dtl.waitFor(async () => {
37+
await screen.findByText(/the joy of owning a dog/i)
38+
39+
const catResult = screen.queryByText(/caring for your feline friend/i)
40+
expect(catResult).not.toBeInTheDocument()
41+
})
42+
},
43+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const catResult = await testStep('The user can see the results', async () => {
16+
const result = screen.getByText(/caring for your feline friend/i)
17+
expect(result).toBeInTheDocument()
18+
return result
19+
})
20+
21+
await testStep('The user can search for a term', async () => {
22+
fireEvent.change(searchBox, { target: { value: 'dog' } })
23+
})
24+
25+
await testStep('The results are filtered', async () => {
26+
await dtl.waitFor(() => {
27+
expect(catResult).not.toBeInTheDocument()
28+
})
29+
await screen.findByText(/the joy of owning a dog/i)
30+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
window.history.pushState({}, '', '?query=dog')
5+
6+
await import('./index.tsx')
7+
8+
await testStep(
9+
'The search box is initialized with URL query parameter',
10+
async () => {
11+
const searchBox = await screen.findByRole('searchbox', { name: /search/i })
12+
expect(searchBox).toHaveValue('dog')
13+
},
14+
)

exercises/01.managing-ui-state/05.problem.cb/README.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ const [query, setQuery] = useState(getQueryParam)
4343
```
4444

4545
You're going to be making the `getQueryParam` function. Got it? Great, let's go!
46+
47+
<callout-info>
48+
🚨 Note, we can't reasonably test whether you're doing this right so the tests
49+
are passing from the get-go, but you'll know you didn't break anything if the
50+
tests are still working when you're finished.
51+
</callout-info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test'
2+
const { screen, fireEvent } = dtl
3+
4+
import './index.tsx'
5+
6+
const searchBox = await testStep(
7+
'The user can see the search box',
8+
async () => {
9+
const result = await screen.findByRole('searchbox', { name: /search/i })
10+
expect(result).toHaveValue('')
11+
return result
12+
},
13+
)
14+
15+
const dogCheckbox = await testStep(
16+
'The user can see the dog checkbox',
17+
async () => {
18+
const result = await screen.findByRole('checkbox', { name: /dog/i })
19+
expect(result).not.toBeChecked()
20+
return result
21+
},
22+
)
23+
24+
await testStep('The user can search for a checkbox value', async () => {
25+
fireEvent.change(searchBox, { target: { value: 'dog' } })
26+
})
27+
28+
await testStep('checkbox is checked automatically', async () => {
29+
expect(dogCheckbox).toBeChecked()
30+
})

0 commit comments

Comments
 (0)