Skip to content

Commit 21b2f90

Browse files
authored
test(AnimateBlock): test for AnimateBlock added (#167)
* test(AnimateBlock): test for AnimateBlock added
1 parent a385a50 commit 21b2f90

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/components/AnimateBlock/AnimateBlock.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ export interface AnimateBlockProps extends AnimateContextProps {
1414
className?: string;
1515
style?: CSSProperties;
1616
onScroll?: () => void;
17+
qa?: string;
1718
}
1819

1920
const AnimateBlock = (props: WithChildren<AnimateBlockProps>) => {
2021
const {animated} = useContext(AnimateContext);
21-
const {children, className, offset = 100, onScroll, style, animate = animated} = props;
22+
const {children, className, offset = 100, onScroll, style, animate = animated, qa} = props;
2223
const [playAnimation, setPlayAnimation] = useState<boolean>(false);
2324

2425
const divClassName = animate
2526
? b(null, `${playAnimation && 'animate'} ${className}`)
2627
: className;
2728
return (
28-
<div className={divClassName} style={style}>
29+
<div className={divClassName} style={style} data-qa={qa}>
2930
<Waypoint
3031
// trigger animation if element is above screen
3132
topOffset={'-100000%'}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
3+
import {render, screen} from '@testing-library/react';
4+
import userEvent from '@testing-library/user-event';
5+
6+
import AnimateBlock from '../AnimateBlock';
7+
8+
const qaId = 'animate-block';
9+
10+
describe('AnimateBlock', () => {
11+
test('render AnimateBlock by default', async () => {
12+
render(<AnimateBlock qa={qaId} />);
13+
14+
const component = screen.getByTestId(qaId);
15+
expect(component).toBeInTheDocument();
16+
});
17+
18+
test('add className', () => {
19+
const className = 'my-class';
20+
21+
render(<AnimateBlock qa={qaId} className={className} />);
22+
const component = screen.getByTestId(qaId);
23+
24+
expect(component).toHaveClass(className);
25+
});
26+
27+
test('use passed style', () => {
28+
const style = {color: 'red'};
29+
30+
render(<AnimateBlock style={style} qa={qaId} />);
31+
const component = screen.getByTestId(qaId);
32+
33+
expect(component).toHaveStyle(style);
34+
});
35+
36+
test('call onScroll', async () => {
37+
const onScroll = jest.fn();
38+
const user = userEvent.setup();
39+
40+
render(
41+
<div style={{paddingTop: 100000}}>
42+
<AnimateBlock onScroll={onScroll} qa={qaId} />
43+
</div>,
44+
);
45+
const component = screen.getByTestId(qaId);
46+
47+
await user.hover(component);
48+
expect(onScroll).toHaveBeenCalledTimes(1);
49+
});
50+
});

0 commit comments

Comments
 (0)