Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domhhv committed Feb 29, 2024
1 parent 0c3bea3 commit 8d5f76f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/components/calendar/OccurrenceChip.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useHabits, useOccurrences } from '@context';
import { useScreenSize } from '@hooks';
import { render, waitFor } from '@testing-library/react';
import { getHabitIconUrl } from '@utils';
import React from 'react';
Expand All @@ -11,6 +12,7 @@ jest.mock('@utils', () => ({

jest.mock('@hooks', () => ({
useHabitTraitChipColor: jest.fn(),
useScreenSize: jest.fn(),
}));

jest.mock('@context', () => ({
Expand Down Expand Up @@ -118,4 +120,24 @@ describe(OccurrenceChip.name, () => {
expect(loader).toBeInTheDocument();
expect(chipDelete).toBeNull();
});

it('should not render delete button on small screens', () => {
(useHabits as jest.Mock).mockReturnValue({
habitsMap: {
2: {
id: 2,
name: 'Test Habit Name',
iconPath: 'path/to/test/icon',
traitId: 1,
},
},
});
(useOccurrences as jest.Mock).mockReturnValue({
occurrenceIdBeingDeleted: null,
});
(useScreenSize as jest.Mock).mockReturnValue(1024);
const { queryByRole } = render(<OccurrenceChip {...props} />);
const chipDelete = queryByRole('habit-chip-delete-button');
expect(chipDelete).toBeNull();
});
});
7 changes: 3 additions & 4 deletions src/hooks/useScreenSize.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook } from '@testing-library/react';
import { fireEvent, renderHook } from '@testing-library/react';

import useScreenSize from './useScreenSize';

Expand All @@ -15,8 +15,7 @@ describe(useScreenSize.name, () => {

it('should update the screen size when the window is resized', () => {
const { result } = renderHook(() => useScreenSize());
const initialSize = result.current;
global.dispatchEvent(new Event('resize'));
expect(result.current).not.toEqual(initialSize);
fireEvent.resize(window, { target: { innerWidth: 1000 } });
expect(result.current).toEqual(1000);
});
});

0 comments on commit 8d5f76f

Please sign in to comment.