-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89c64c6
commit 9490a7e
Showing
14 changed files
with
163 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
exercises/03.custom-hooks/01.solution.function/search-params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
window.history.pushState({}, '', '?query=dog') | ||
|
||
await import('./index.tsx') | ||
|
||
await testStep( | ||
'The search box is initialized with URL query parameter', | ||
async () => { | ||
const searchBox = await screen.findByRole('searchbox', { name: /search/i }) | ||
expect(searchBox).toHaveValue('dog') | ||
}, | ||
) | ||
|
||
await testStep( | ||
'Updating the search box updates the URL search params', | ||
async () => { | ||
const searchBox = screen.getByRole('searchbox', { name: /search/i }) | ||
fireEvent.change(searchBox, { target: { value: 'cat' } }) | ||
|
||
expect(searchBox).toHaveValue('cat') | ||
expect(window.location.search).toBe('?query=cat') | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
exercises/03.custom-hooks/02.solution.callback/callback.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect, testStep } from '@epic-web/workshop-utils/test' | ||
import { useReducer } from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
import { useSearchParams } from './index' | ||
|
||
let setSearchParams: ReturnType<typeof useSearchParams>[1] | ||
let rerender: () => void | ||
function TestComponent() { | ||
const reducerTuple = useReducer((state) => state + 1, 0) | ||
const searchParamsTuple = useSearchParams() | ||
setSearchParams = searchParamsTuple[1] | ||
rerender = reducerTuple[1] | ||
return null | ||
} | ||
|
||
await testStep('setSearchParams is memoized', async () => { | ||
const container = document.createElement('div') | ||
const root = createRoot(container) | ||
root.render(<TestComponent />) | ||
await new Promise((resolve) => setTimeout(resolve, 100)) | ||
const firstSetSearchParams = setSearchParams | ||
rerender() | ||
await new Promise((resolve) => setTimeout(resolve, 100)) | ||
expect(firstSetSearchParams).toBe(setSearchParams) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
exercises/03.custom-hooks/02.solution.callback/search-params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
window.history.pushState({}, '', '?query=dog') | ||
|
||
await import('./index.tsx') | ||
|
||
await testStep( | ||
'The search box is initialized with URL query parameter', | ||
async () => { | ||
const searchBox = await screen.findByRole('searchbox', { name: /search/i }) | ||
expect(searchBox).toHaveValue('dog') | ||
}, | ||
) | ||
|
||
await testStep( | ||
'Updating the search box updates the URL search params', | ||
async () => { | ||
const searchBox = screen.getByRole('searchbox', { name: /search/i }) | ||
fireEvent.change(searchBox, { target: { value: 'cat' } }) | ||
|
||
expect(searchBox).toHaveValue('cat') | ||
expect(window.location.search).toBe('?query=cat') | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
exercises/04.context/01.solution.provider/filtering.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
import './index.tsx' | ||
|
||
const searchBox = await testStep( | ||
'The user can see the search box', | ||
async () => { | ||
const result = await screen.findByRole('searchbox', { name: /search/i }) | ||
expect(result).toHaveValue('') | ||
return result | ||
}, | ||
) | ||
|
||
const catResult = await testStep('The user can see the results', async () => { | ||
const result = screen.getByText(/caring for your feline friend/i) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
|
||
await testStep('The user can search for a term', async () => { | ||
fireEvent.change(searchBox, { target: { value: 'dog' } }) | ||
}) | ||
|
||
await testStep('The results are filtered', async () => { | ||
await dtl.waitFor(() => { | ||
expect(catResult).not.toBeInTheDocument() | ||
}) | ||
await screen.findByText(/the joy of owning a dog/i) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
import './index.tsx' | ||
|
||
const searchBox = await testStep( | ||
'The user can see the search box', | ||
async () => { | ||
const result = await screen.findByRole('searchbox', { name: /search/i }) | ||
expect(result).toHaveValue('') | ||
return result | ||
}, | ||
) | ||
|
||
const catResult = await testStep('The user can see the results', async () => { | ||
const result = screen.getByText(/caring for your feline friend/i) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
|
||
await testStep('The user can search for a term', async () => { | ||
fireEvent.change(searchBox, { target: { value: 'dog' } }) | ||
}) | ||
|
||
await testStep('The results are filtered', async () => { | ||
await dtl.waitFor(() => { | ||
expect(catResult).not.toBeInTheDocument() | ||
}) | ||
await screen.findByText(/the joy of owning a dog/i) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
import './index.tsx' | ||
|
||
await testStep('The portal is rendered to the body', async () => { | ||
const [heartButton] = await screen.findAllByText('🤍') | ||
heartButton.focus() | ||
|
||
const tooltip = await screen.findByText('Add favorite') | ||
expect(tooltip).toBeTruthy() | ||
expect( | ||
tooltip.closest('li'), | ||
'🚨 The tooltip is still rendered inside the li', | ||
).toBe(null) | ||
}) |