Skip to content

Commit 6afc330

Browse files
committed
Refactor: Migrated src/components/EventListCard/EventListCard.test.tsx from Jest to Vitest
1 parent f60d17d commit 6afc330

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/components/EventListCard/EventListCard.test.tsx renamed to src/components/EventListCard/EventListCard.spec.tsx

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
1717
import useLocalStorage from 'utils/useLocalstorage';
1818
import { props } from './EventListCardProps';
1919
import { ERROR_MOCKS, MOCKS } from './EventListCardMocks';
20+
import { vi, beforeAll, afterAll, expect, it } from 'vitest';
2021

2122
const { setItem } = useLocalStorage();
2223

2324
const link = new StaticMockLink(MOCKS, true);
2425
const link2 = new StaticMockLink(ERROR_MOCKS, true);
2526

26-
jest.mock('react-toastify', () => ({
27+
vi.mock('react-toastify', () => ({
2728
toast: {
28-
success: jest.fn(),
29-
error: jest.fn(),
29+
success: vi.fn(),
30+
error: vi.fn(),
3031
},
3132
}));
3233

@@ -101,18 +102,17 @@ describe('Testing Event List Card', () => {
101102
};
102103

103104
beforeAll(() => {
104-
jest.mock('react-router-dom', () => ({
105-
...jest.requireActual('react-router-dom'),
106-
useParams: () => ({ orgId: 'orgId' }),
105+
vi.mock('react-router-dom', async () => ({
106+
...(await vi.importActual('react-router-dom')),
107107
}));
108108
});
109109

110110
afterAll(() => {
111111
localStorage.clear();
112-
jest.clearAllMocks();
112+
vi.clearAllMocks();
113113
});
114114

115-
test('Testing for event modal', async () => {
115+
it('Testing for event modal', async () => {
116116
renderEventListCard(props[1]);
117117

118118
userEvent.click(screen.getByTestId('card'));
@@ -129,7 +129,7 @@ describe('Testing Event List Card', () => {
129129
});
130130
});
131131

132-
test('Should navigate to "/" if orgId is not defined', async () => {
132+
it('Should navigate to "/" if orgId is not defined', async () => {
133133
render(
134134
<MockedProvider addTypename={false} link={link}>
135135
<I18nextProvider i18n={i18n}>
@@ -163,15 +163,15 @@ describe('Testing Event List Card', () => {
163163
});
164164
});
165165

166-
test('Should render default text if event details are null', async () => {
166+
it('Should render default text if event details are null', async () => {
167167
renderEventListCard(props[0]);
168168

169169
await waitFor(() => {
170170
expect(screen.getByText('Dogs Care')).toBeInTheDocument();
171171
});
172172
});
173173

174-
test('should render props and text elements test for the screen', async () => {
174+
it('should render props and text elements test for the screen', async () => {
175175
renderEventListCard(props[1]);
176176

177177
expect(screen.getByText(props[1].eventName)).toBeInTheDocument();
@@ -198,7 +198,7 @@ describe('Testing Event List Card', () => {
198198
});
199199
});
200200

201-
test('Should render truncated event name when length is more than 100', async () => {
201+
it('Should render truncated event name when length is more than 100', async () => {
202202
const longEventName = 'a'.repeat(101);
203203
renderEventListCard({ ...props[1], eventName: longEventName });
204204

@@ -221,7 +221,7 @@ describe('Testing Event List Card', () => {
221221
});
222222
});
223223

224-
test('Should render full event name when length is less than or equal to 100', async () => {
224+
it('Should render full event name when length is less than or equal to 100', async () => {
225225
const shortEventName = 'a'.repeat(100);
226226
renderEventListCard({ ...props[1], eventName: shortEventName });
227227

@@ -242,7 +242,7 @@ describe('Testing Event List Card', () => {
242242
});
243243
});
244244

245-
test('Should render truncated event description when length is more than 256', async () => {
245+
it('Should render truncated event description when length is more than 256', async () => {
246246
const longEventDescription = 'a'.repeat(257);
247247

248248
renderEventListCard({
@@ -268,7 +268,7 @@ describe('Testing Event List Card', () => {
268268
});
269269
});
270270

271-
test('Should render full event description when length is less than or equal to 256', async () => {
271+
it('Should render full event description when length is less than or equal to 256', async () => {
272272
const shortEventDescription = 'a'.repeat(256);
273273

274274
renderEventListCard({
@@ -294,7 +294,7 @@ describe('Testing Event List Card', () => {
294294
});
295295
});
296296

297-
test('Should navigate to event dashboard when clicked (For Admin)', async () => {
297+
it('Should navigate to event dashboard when clicked (For Admin)', async () => {
298298
renderEventListCard(props[1]);
299299

300300
userEvent.click(screen.getByTestId('card'));
@@ -311,7 +311,7 @@ describe('Testing Event List Card', () => {
311311
});
312312
});
313313

314-
test('Should navigate to event dashboard when clicked (For User)', async () => {
314+
it('Should navigate to event dashboard when clicked (For User)', async () => {
315315
setItem('userId', '123');
316316
renderEventListCard(props[2]);
317317

@@ -329,7 +329,7 @@ describe('Testing Event List Card', () => {
329329
});
330330
});
331331

332-
test('Should update a non-recurring event', async () => {
332+
it('Should update a non-recurring event', async () => {
333333
renderEventListCard(props[1]);
334334

335335
userEvent.click(screen.getByTestId('card'));
@@ -372,7 +372,7 @@ describe('Testing Event List Card', () => {
372372
});
373373
});
374374

375-
test('Should update a non all day non-recurring event', async () => {
375+
it('Should update a non all day non-recurring event', async () => {
376376
renderEventListCard(props[1]);
377377

378378
userEvent.click(screen.getByTestId('card'));
@@ -425,7 +425,7 @@ describe('Testing Event List Card', () => {
425425
});
426426
});
427427

428-
test('should update a single event to be recurring', async () => {
428+
it('should update a single event to be recurring', async () => {
429429
renderEventListCard(props[1]);
430430

431431
userEvent.click(screen.getByTestId('card'));
@@ -469,7 +469,7 @@ describe('Testing Event List Card', () => {
469469
});
470470
});
471471

472-
test('should show different update options for a recurring event based on different conditions', async () => {
472+
it('should show different update options for a recurring event based on different conditions', async () => {
473473
renderEventListCard(props[5]);
474474

475475
userEvent.click(screen.getByTestId('card'));
@@ -595,7 +595,7 @@ describe('Testing Event List Card', () => {
595595
});
596596
});
597597

598-
test('should show recurrenceRule as changed if the recurrence weekdays have changed', async () => {
598+
it('should show recurrenceRule as changed if the recurrence weekdays have changed', async () => {
599599
renderEventListCard(props[4]);
600600

601601
userEvent.click(screen.getByTestId('card'));
@@ -656,7 +656,7 @@ describe('Testing Event List Card', () => {
656656
});
657657
});
658658

659-
test('should update all instances of a recurring event', async () => {
659+
it('should update all instances of a recurring event', async () => {
660660
renderEventListCard(props[6]);
661661

662662
userEvent.click(screen.getByTestId('card'));
@@ -706,7 +706,7 @@ describe('Testing Event List Card', () => {
706706
});
707707
});
708708

709-
test('should update thisAndFollowingInstances of a recurring event', async () => {
709+
it('should update thisAndFollowingInstances of a recurring event', async () => {
710710
renderEventListCard(props[5]);
711711

712712
userEvent.click(screen.getByTestId('card'));
@@ -772,7 +772,7 @@ describe('Testing Event List Card', () => {
772772
});
773773
});
774774

775-
test('should render the delete modal', async () => {
775+
it('should render the delete modal', async () => {
776776
renderEventListCard(props[1]);
777777

778778
userEvent.click(screen.getByTestId('card'));
@@ -807,7 +807,7 @@ describe('Testing Event List Card', () => {
807807
});
808808
});
809809

810-
test('should call the delete event mutation when the "Yes" button is clicked', async () => {
810+
it('should call the delete event mutation when the "Yes" button is clicked', async () => {
811811
renderEventListCard(props[1]);
812812

813813
userEvent.click(screen.getByTestId('card'));
@@ -833,7 +833,7 @@ describe('Testing Event List Card', () => {
833833
});
834834
});
835835

836-
test('select different delete options on recurring events & then delete the recurring event', async () => {
836+
it('select different delete options on recurring events & then delete the recurring event', async () => {
837837
renderEventListCard(props[4]);
838838

839839
await wait();
@@ -873,7 +873,7 @@ describe('Testing Event List Card', () => {
873873
});
874874
});
875875

876-
test('should show an error toast when the delete event mutation fails', async () => {
876+
it('should show an error toast when the delete event mutation fails', async () => {
877877
// Destructure key from props[1] and pass it separately to avoid spreading it
878878
const { key, ...otherProps } = props[1];
879879
render(
@@ -908,7 +908,7 @@ describe('Testing Event List Card', () => {
908908
});
909909
});
910910

911-
test('handle register should work properly', async () => {
911+
it('handle register should work properly', async () => {
912912
setItem('userId', '456');
913913

914914
renderEventListCard(props[2]);
@@ -933,7 +933,7 @@ describe('Testing Event List Card', () => {
933933
});
934934
});
935935

936-
test('should show already registered text when the user is registered for an event', async () => {
936+
it('should show already registered text when the user is registered for an event', async () => {
937937
renderEventListCard(props[3]);
938938

939939
userEvent.click(screen.getByTestId('card'));

src/components/EventListCard/EventListCardModals.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function EventListCardModals({
292292
}
293293
}
294294
} catch (error: unknown) {
295-
/* istanbul ignore next */
295+
/* istanbul ignore next -- @preserve */
296296
errorHandler(t, error);
297297
}
298298
};
@@ -322,6 +322,7 @@ function EventListCardModals({
322322
},
323323
});
324324

325+
/* istanbul ignore else -- @preserve */
325326
if (data) {
326327
toast.success(t('eventDeleted') as string);
327328
setEventDeleteModalIsOpen(false);
@@ -362,7 +363,7 @@ function EventListCardModals({
362363
hideViewModal();
363364
}
364365
} catch (error: unknown) {
365-
/* istanbul ignore next */
366+
/* istanbul ignore next -- @preserve */
366367
errorHandler(t, error);
367368
}
368369
}
@@ -507,6 +508,7 @@ function EventListCardModals({
507508
className={styles.datebox}
508509
value={dayjs(eventEndDate)}
509510
onChange={(date: Dayjs | null): void => {
511+
/* istanbul ignore else -- @preserve */
510512
if (date) {
511513
setEventEndDate(date?.toDate());
512514
}

0 commit comments

Comments
 (0)