-
Notifications
You must be signed in to change notification settings - Fork 666
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
167833b
commit 3f79ded
Showing
10 changed files
with
191 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
57 changes: 57 additions & 0 deletions
57
exercises/02.context/01.solution.memo-context/memo-context.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,57 @@ | ||
import { getComponentCalls } from '#shared/get-component-calls' | ||
import { testStep, expect, dtl } from '@epic-web/workshop-utils/test' | ||
|
||
const { screen, fireEvent } = dtl | ||
|
||
await import('./index.tsx') | ||
|
||
await testStep( | ||
'changing the app counter should not re-render the Footer component', | ||
async () => { | ||
// Find the app count button | ||
const appCountButton = await screen.findByRole('button', { | ||
name: /the app count is/i, | ||
}) | ||
|
||
// Get the component calls when clicking the app count button | ||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.click(appCountButton) | ||
// Give components time to render | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toEqual(['App', 'FooterSetters', 'Main']) | ||
}, | ||
) | ||
|
||
await testStep('changing footer color should re-render Footer', async () => { | ||
// Find the color button | ||
const colorButton = await screen.findByRole('button', { name: /blue/i }) | ||
|
||
// Get the component calls when changing the color | ||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.click(colorButton) | ||
// Give components time to render | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toEqual( | ||
expect.arrayContaining(['App', 'FooterSetters', 'Main', 'FooterImpl']), | ||
) | ||
}) | ||
|
||
await testStep('changing footer name should re-render Footer', async () => { | ||
// Find the name input | ||
const nameInput = await screen.findByLabelText(/name/i) | ||
|
||
// Get the component calls when changing the name | ||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.change(nameInput, { target: { value: 'New Name' } }) | ||
// Give components time to render | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toEqual( | ||
expect.arrayContaining(['App', 'FooterSetters', 'Main', 'FooterImpl']), | ||
) | ||
}) |
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
63 changes: 63 additions & 0 deletions
63
exercises/02.context/02.solution.provider-component/provider.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,63 @@ | ||
import { getComponentCalls } from '#shared/get-component-calls' | ||
import { testStep, expect, dtl } from '@epic-web/workshop-utils/test' | ||
|
||
const { screen, fireEvent } = dtl | ||
|
||
await import('./index.tsx') | ||
|
||
await testStep( | ||
'changing the app counter should not re-render the Footer component', | ||
async () => { | ||
const appCountButton = await screen.findByRole('button', { | ||
name: /the app count is/i, | ||
}) | ||
|
||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.click(appCountButton) | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toEqual([ | ||
'App', | ||
'FooterProvider', | ||
'FooterSetters', | ||
'Main', | ||
]) | ||
}, | ||
) | ||
|
||
await testStep( | ||
'changing footer color should not re-render App or Main', | ||
async () => { | ||
const colorButton = await screen.findByRole('button', { name: /blue/i }) | ||
|
||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.click(colorButton) | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toEqual( | ||
expect.arrayContaining(['FooterSetters', 'FooterImpl', 'FooterProvider']), | ||
) | ||
expect(componentNames).not.toContain('App') | ||
expect(componentNames).not.toContain('Main') | ||
}, | ||
) | ||
|
||
await testStep( | ||
'changing footer name should not re-render App or Main', | ||
async () => { | ||
const nameInput = await screen.findByLabelText(/name/i) | ||
|
||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.change(nameInput, { target: { value: 'New Name' } }) | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toEqual( | ||
expect.arrayContaining(['FooterSetters', 'FooterImpl', 'FooterProvider']), | ||
) | ||
expect(componentNames).not.toContain('App') | ||
expect(componentNames).not.toContain('Main') | ||
}, | ||
) |
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
56 changes: 56 additions & 0 deletions
56
exercises/02.context/03.solution.split-context/split.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,56 @@ | ||
import { getComponentCalls } from '#shared/get-component-calls' | ||
import { testStep, expect, dtl } from '@epic-web/workshop-utils/test' | ||
|
||
const { screen, fireEvent } = dtl | ||
|
||
await import('./index.tsx') | ||
|
||
await testStep( | ||
'FooterSetters should not re-render when footer state changes', | ||
async () => { | ||
const colorButton = await screen.findByRole('button', { name: /blue/i }) | ||
|
||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.click(colorButton) | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toContain('FooterImpl') | ||
expect(componentNames).not.toContain('FooterSetters') | ||
}, | ||
) | ||
|
||
await testStep( | ||
'FooterSetters should not re-render when footer name changes', | ||
async () => { | ||
const nameInput = await screen.findByLabelText(/name/i) | ||
|
||
const componentNames = await getComponentCalls(async () => { | ||
fireEvent.change(nameInput, { target: { value: 'New Name' } }) | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
expect(componentNames).toContain('FooterImpl') | ||
expect(componentNames).not.toContain('FooterSetters') | ||
}, | ||
) | ||
|
||
await testStep( | ||
'FooterSetters should render only once during initial render', | ||
async () => { | ||
const componentNames = await getComponentCalls(async () => { | ||
// Force a re-render of the entire app | ||
const appCountButton = await screen.findByRole('button', { | ||
name: /the app count is/i, | ||
}) | ||
fireEvent.click(appCountButton) | ||
await new Promise((resolve) => setTimeout(resolve, 10)) | ||
}) | ||
|
||
const footerSettersCount = componentNames.filter( | ||
(name) => name === 'FooterSetters', | ||
).length | ||
|
||
expect(footerSettersCount).toBe(0) | ||
}, | ||
) |
8 changes: 8 additions & 0 deletions
8
exercises/03.concurrent-rendering/01.solution.deferred/concurrent.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,8 @@ | ||
import { testStep } from '@epic-web/workshop-utils/test' | ||
|
||
await testStep( | ||
`There is no real test for this because it's basically impossible to test. (Consider that an invitation to try if you want!)`, | ||
async () => { | ||
await import('./index.tsx') | ||
}, | ||
) |