Skip to content

Commit

Permalink
✅ Add tests for Waves
Browse files Browse the repository at this point in the history
  • Loading branch information
mariush2 committed Jan 16, 2025
1 parent a07e2d3 commit a661375
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/molecules/Waves/WaveStatic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const WaveStatic: FC = () => {
useEffect(() => {
const resizeHandler = (event: Event) => {
const target = event.target as Window;
console.log(target);
setViewBox(`0 0 ${target.innerWidth} ${target.innerHeight - 64}`);
};

Expand Down
37 changes: 24 additions & 13 deletions src/molecules/Waves/Waves.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { act } from 'react';

import { faker } from '@faker-js/faker';
import { render } from '@testing-library/react';

import { Waves, WavesProps } from './Waves';
import { Waves } from './Waves';

test('renders expected amount of svgs', () => {
const { container } = render(<Waves />);
expect(container).toBeInTheDocument();

expect(container.children[0].children[0].childNodes.length).toBe(2);
});

const renderVisualWaves = (props: Partial<WavesProps> = {}) => {
const defaultProps: WavesProps = {
waveIntervalDist: 3,
waveDelay: 0.75,
numWaves: 10,
heightFromBottom: 600,
};
test('resize actually resizes', async () => {
const { container } = render(<Waves />);
const randomWidth = faker.number.int({ min: 100, max: 1920 });
const randomHeight = faker.number.int({ min: 100, max: 1080 });

return render(<Waves {...defaultProps} {...props} />);
};
await act(async () => {
window['innerWidth'] = randomWidth;
window['innerHeight'] = randomHeight;
window.dispatchEvent(new Event('resize'));
});

test('renders correctly with default props', () => {
const { container } = renderVisualWaves();
expect(container).toBeInTheDocument();
expect(container.children[0].children[0]).toHaveAttribute(
'viewBox',
`0 0 ${randomWidth} ${randomHeight - 64}`
);
});

0 comments on commit a661375

Please sign in to comment.