-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
609ee76
commit 7f3a506
Showing
13 changed files
with
364 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
|
||
import './index.tsx' | ||
|
||
await testStep('VanillaTilt is initialized', async () => { | ||
await dtl.waitFor(() => { | ||
const tiltElement = document.querySelector('.tilt-root') | ||
expect(tiltElement).toHaveProperty('vanillaTilt') | ||
}) | ||
}) |
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 { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
import './index.tsx' | ||
|
||
const toggleButton = await testStep( | ||
'The user can see the toggle visibility button', | ||
async () => { | ||
const result = await screen.findByRole('button', { | ||
name: /toggle visibility/i, | ||
}) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}, | ||
) | ||
|
||
await testStep('The Tilt component is initially visible', async () => { | ||
return dtl.waitFor(() => { | ||
const result = document.querySelector('.tilt-root') | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
}) | ||
|
||
const countButton = await testStep( | ||
'The count button is visible inside the Tilt component', | ||
async () => { | ||
const result = await screen.findByRole('button', { name: /0/i }) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}, | ||
) | ||
|
||
await testStep('The user can increment the count', async () => { | ||
fireEvent.click(countButton) | ||
const updatedButton = await screen.findByRole('button', { name: /1/i }) | ||
expect(updatedButton).toBeInTheDocument() | ||
}) | ||
|
||
await testStep( | ||
'The user can toggle the Tilt component visibility', | ||
async () => { | ||
fireEvent.click(toggleButton) | ||
await dtl.waitFor(() => { | ||
expect(document.querySelector('.tilt-root')).not.toBeInTheDocument() | ||
}) | ||
|
||
fireEvent.click(toggleButton) | ||
const visibleTiltElement = await dtl.waitFor(() => { | ||
const result = document.querySelector('.tilt-root') | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
expect(visibleTiltElement).toBeInTheDocument() | ||
}, | ||
) |
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,50 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
import type VanillaTilt from 'vanilla-tilt' | ||
const { screen, fireEvent, waitFor } = dtl | ||
|
||
interface HTMLVanillaTiltElement extends HTMLDivElement { | ||
vanillaTilt?: VanillaTilt | ||
} | ||
|
||
import './index.tsx' | ||
|
||
const tiltElement = await testStep('Initialize tilt element', async () => { | ||
const result = await waitFor(() => { | ||
const element = document.querySelector('.tilt-root') | ||
expect(element).toBeInTheDocument() | ||
return element | ||
}) | ||
await waitFor(() => { | ||
expect(result).toHaveProperty('vanillaTilt') | ||
}) | ||
return result as HTMLVanillaTiltElement | ||
}) | ||
|
||
await testStep('Find count button', async () => { | ||
const button = await screen.findByRole('button', { name: /0/i }) | ||
expect(button).toBeInTheDocument() | ||
return button as HTMLButtonElement | ||
}) | ||
|
||
const maxInput = await testStep('Find max input', async () => { | ||
const input = (await screen.findByLabelText('Max:')) as HTMLInputElement | ||
expect(input).toBeInTheDocument() | ||
return input as HTMLInputElement | ||
}) | ||
|
||
await testStep('Tilt effect resets when options change', async () => { | ||
const initialVanillaTilt = tiltElement.vanillaTilt | ||
fireEvent.change(maxInput, { target: { value: '30' } }) | ||
await waitFor(() => { | ||
expect(tiltElement.vanillaTilt).not.toBe(initialVanillaTilt) | ||
}) | ||
}) | ||
|
||
await testStep('Tilt effect uses updated options', async () => { | ||
const newMax = 35 | ||
fireEvent.change(maxInput, { target: { value: newMax.toString() } }) | ||
await waitFor(() => { | ||
// @ts-expect-error this is not exposed | ||
expect(tiltElement.vanillaTilt?.settings.max).toBe(newMax) | ||
}) | ||
}) |
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 { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
import './index.tsx' | ||
|
||
const toggleButton = await testStep( | ||
'The user can see the toggle visibility button', | ||
async () => { | ||
const result = await screen.findByRole('button', { | ||
name: /toggle visibility/i, | ||
}) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}, | ||
) | ||
|
||
await testStep('The Tilt component is initially visible', async () => { | ||
return dtl.waitFor(() => { | ||
const result = document.querySelector('.tilt-root') | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
}) | ||
|
||
const countButton = await testStep( | ||
'The count button is visible inside the Tilt component', | ||
async () => { | ||
const result = await screen.findByRole('button', { name: /0/i }) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}, | ||
) | ||
|
||
await testStep('The user can increment the count', async () => { | ||
fireEvent.click(countButton) | ||
const updatedButton = await screen.findByRole('button', { name: /1/i }) | ||
expect(updatedButton).toBeInTheDocument() | ||
}) | ||
|
||
await testStep( | ||
'The user can toggle the Tilt component visibility', | ||
async () => { | ||
fireEvent.click(toggleButton) | ||
await dtl.waitFor(() => { | ||
expect(document.querySelector('.tilt-root')).not.toBeInTheDocument() | ||
}) | ||
|
||
fireEvent.click(toggleButton) | ||
const visibleTiltElement = await dtl.waitFor(() => { | ||
const result = document.querySelector('.tilt-root') | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
expect(visibleTiltElement).toBeInTheDocument() | ||
}, | ||
) |
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,59 @@ | ||
import { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
import type VanillaTilt from 'vanilla-tilt' | ||
const { screen, fireEvent, waitFor } = dtl | ||
|
||
interface HTMLVanillaTiltElement extends HTMLDivElement { | ||
vanillaTilt?: VanillaTilt | ||
} | ||
|
||
import './index.tsx' | ||
|
||
const tiltElement = await testStep('Initialize tilt element', async () => { | ||
const result = await waitFor(() => { | ||
const element = document.querySelector('.tilt-root') | ||
expect(element).toBeInTheDocument() | ||
return element | ||
}) | ||
await waitFor(() => { | ||
expect(result).toHaveProperty('vanillaTilt') | ||
}) | ||
return result as HTMLVanillaTiltElement | ||
}) | ||
|
||
const countButton = await testStep('Find count button', async () => { | ||
const button = await screen.findByRole('button', { name: /0/i }) | ||
expect(button).toBeInTheDocument() | ||
return button as HTMLButtonElement | ||
}) | ||
|
||
const maxInput = await testStep('Find max input', async () => { | ||
const input = (await screen.findByLabelText('Max:')) as HTMLInputElement | ||
expect(input).toBeInTheDocument() | ||
return input as HTMLInputElement | ||
}) | ||
|
||
await testStep('Tilt effect persists after count increment', async () => { | ||
const initialVanillaTilt = tiltElement.vanillaTilt | ||
fireEvent.click(countButton) | ||
await screen.findByRole('button', { name: /1/i }) | ||
expect(tiltElement.vanillaTilt, 'vanilla tilt was reinitialized').toBe( | ||
initialVanillaTilt, | ||
) | ||
}) | ||
|
||
await testStep('Tilt effect resets when options change', async () => { | ||
const initialVanillaTilt = tiltElement.vanillaTilt | ||
fireEvent.change(maxInput, { target: { value: '30' } }) | ||
await waitFor(() => { | ||
expect(tiltElement.vanillaTilt).not.toBe(initialVanillaTilt) | ||
}) | ||
}) | ||
|
||
await testStep('Tilt effect uses updated options', async () => { | ||
const newMax = 35 | ||
fireEvent.change(maxInput, { target: { value: newMax.toString() } }) | ||
await waitFor(() => { | ||
// @ts-expect-error this is not exposed | ||
expect(tiltElement.vanillaTilt?.settings.max).toBe(newMax) | ||
}) | ||
}) |
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 { expect, testStep, dtl } from '@epic-web/workshop-utils/test' | ||
const { screen, fireEvent } = dtl | ||
|
||
import './index.tsx' | ||
|
||
const toggleButton = await testStep( | ||
'The user can see the toggle visibility button', | ||
async () => { | ||
const result = await screen.findByRole('button', { | ||
name: /toggle visibility/i, | ||
}) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}, | ||
) | ||
|
||
await testStep('The Tilt component is initially visible', async () => { | ||
return dtl.waitFor(() => { | ||
const result = document.querySelector('.tilt-root') | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
}) | ||
|
||
const countButton = await testStep( | ||
'The count button is visible inside the Tilt component', | ||
async () => { | ||
const result = await screen.findByRole('button', { name: /0/i }) | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}, | ||
) | ||
|
||
await testStep('The user can increment the count', async () => { | ||
fireEvent.click(countButton) | ||
const updatedButton = await screen.findByRole('button', { name: /1/i }) | ||
expect(updatedButton).toBeInTheDocument() | ||
}) | ||
|
||
await testStep( | ||
'The user can toggle the Tilt component visibility', | ||
async () => { | ||
fireEvent.click(toggleButton) | ||
await dtl.waitFor(() => { | ||
expect(document.querySelector('.tilt-root')).not.toBeInTheDocument() | ||
}) | ||
|
||
fireEvent.click(toggleButton) | ||
const visibleTiltElement = await dtl.waitFor(() => { | ||
const result = document.querySelector('.tilt-root') | ||
expect(result).toBeInTheDocument() | ||
return result | ||
}) | ||
expect(visibleTiltElement).toBeInTheDocument() | ||
}, | ||
) |
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
Oops, something went wrong.