-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: basic animate group tests, trigger onEnter and onExit
- Loading branch information
Coltin Kifer
committed
Sep 8, 2024
1 parent
c8bba64
commit c43629e
Showing
5 changed files
with
111 additions
and
9 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
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 |
---|---|---|
@@ -1,13 +1,91 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import React, { useState } from 'react'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
import AnimateGroupChild from '../src/AnimateGroupChild'; | ||
|
||
describe('AnimateGroupChild', () => { | ||
it('Should render AnimateGroupChild', () => { | ||
render( | ||
it('Should render AnimateGroupChild and its children', () => { | ||
const { container } = render( | ||
<AnimateGroupChild> | ||
<div /> | ||
</AnimateGroupChild>, | ||
); | ||
|
||
const isDiv = container.firstChild instanceof HTMLDivElement; | ||
expect(isDiv).toBe(true); | ||
}); | ||
|
||
it('Should render AnimateGroupChild with basic options set', () => { | ||
const appearOptions = { duration: 0.5, steps: [] }; | ||
const leaveOptions = { duration: 0.5, steps: [{ duration: 0.2 }] }; | ||
const enterOptions = { duration: 0.5, steps: [{ duration: 0.2 }, { duration: 0.4 }] }; | ||
const { container } = render( | ||
<AnimateGroupChild appearOptions={appearOptions} leaveOptions={leaveOptions} enterOptions={enterOptions}> | ||
<div /> | ||
</AnimateGroupChild>, | ||
); | ||
}); | ||
|
||
const Example = ({ enterOptions, inPropDefault }) => { | ||
const [inProp, setInProp] = useState(inPropDefault); | ||
|
||
const appearOptions = { duration: 0.5, steps: [] }; | ||
const leaveOptions = { duration: 0.5, steps: [{ duration: 0.2, style: { opacity: 0 } }] }; | ||
|
||
return ( | ||
<> | ||
<button type="button" onClick={() => setInProp(p => !p)}> | ||
click me | ||
</button> | ||
<AnimateGroupChild | ||
in={inProp} | ||
appearOptions={appearOptions} | ||
leaveOptions={leaveOptions} | ||
enterOptions={enterOptions} | ||
> | ||
<div /> | ||
</AnimateGroupChild> | ||
</> | ||
); | ||
}; | ||
|
||
it('Should render AnimateGroupChild and trigger enter state with custom onAnimationEnd', () => { | ||
const enterOptions = { | ||
duration: 0.5, | ||
steps: [ | ||
{ duration: 0.2, style: { opacity: 10 } }, | ||
{ duration: 0.4, style: { opacity: 10 } }, | ||
], | ||
onAnimationEnd: vi.fn(), | ||
}; | ||
|
||
render(<Example enterOptions={enterOptions} inPropDefault={false} />); | ||
// enter state triggered | ||
act(() => { | ||
screen.getByText('click me').click(); | ||
}); | ||
}); | ||
|
||
it('Should render AnimateGroupChild and trigger enter state without custom onAnimationEnd', () => { | ||
const enterOptions = { | ||
duration: 0.5, | ||
steps: [ | ||
{ duration: 0.2, style: { opacity: 10 } }, | ||
{ duration: 0.4, style: { opacity: 10 } }, | ||
], | ||
}; | ||
render(<Example enterOptions={enterOptions} inPropDefault={false} />); | ||
// enter state triggered | ||
act(() => { | ||
screen.getByText('click me').click(); | ||
}); | ||
}); | ||
|
||
it('Should render AnimateGroupChild and trigger exit state', () => { | ||
const enterOptions = { duration: 0.5, steps: [{ duration: 0.2, style: { opacity: 0 } }, { duration: 0.4 }] }; | ||
render(<Example enterOptions={enterOptions} inPropDefault={true} />); | ||
// enter state triggered | ||
act(() => { | ||
screen.getByText('click me').click(); | ||
}); | ||
}); | ||
}); |
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