From d8afff04a01817c7ae14ac1fbad8c65e7a71fed9 Mon Sep 17 00:00:00 2001 From: Shivam Kumar Date: Tue, 2 Dec 2025 19:45:22 +0530 Subject: [PATCH 1/3] test: Improve code coverage for EventCalendar.tsx --- .../Monthly/EventCalendar.spec.tsx | 184 +++++++++++------- 1 file changed, 111 insertions(+), 73 deletions(-) diff --git a/src/components/EventCalender/Monthly/EventCalendar.spec.tsx b/src/components/EventCalender/Monthly/EventCalendar.spec.tsx index 70f4d64fdf8..fd643d6d1c1 100644 --- a/src/components/EventCalender/Monthly/EventCalendar.spec.tsx +++ b/src/components/EventCalender/Monthly/EventCalendar.spec.tsx @@ -10,6 +10,7 @@ import { weekdays, months } from 'types/Event/utils'; import { BrowserRouter as Router } from 'react-router'; import { vi, describe, it, expect, afterEach, test } from 'vitest'; import { eventData, MOCKS } from '../EventCalenderMocks'; +import type { InterfaceEvent } from 'types/Event/interface'; const link = new StaticMockLink(MOCKS, true); @@ -88,7 +89,7 @@ describe('Calendar', () => { it('Should show prev and next month on clicking < & > buttons', () => { //testing previous month button render( - + { it('Should show prev and next year on clicking < & > buttons when in year view', async () => { //testing previous month button render( - + { it('Should show prev and next date on clicking < & > buttons in the day view', async () => { render( - + { ]; render( - + { it('Test for superadmin case', () => { render( - + { it('Today Cell is having correct styles', () => { render( - + { it('Today button should show today cell', () => { render( - + { }); it('Should handle window resize in day view', async () => { - const today = new Date(); - const year = today.getFullYear(); - const month = String(today.getMonth() + 1).padStart(2, '0'); - const day = String(today.getDate()).padStart(2, '0'); - const date = `${year}-${month}-${day}`; + const date = new Date().toISOString().split('T')[0]; const multipleEventData = [ { id: '1', @@ -361,7 +358,7 @@ describe('Calendar', () => { ]; render( - + { test('Handles window resize', () => { render( - + { // Test navigation at month boundaries render( - + { render( - + { render( - + { render( - + { render( - + { render( - + { }; it('should return all events when user role is ADMINISTRATOR', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; const adminTestEventData = [ { id: 'event1', @@ -835,7 +828,7 @@ describe('Calendar', () => { const { container } = render( - + { }); it('should filter events for regular users who are organization members', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; const memberTestEventData = [ { id: 'event1', @@ -906,7 +895,7 @@ describe('Calendar', () => { const { container } = render( - + { }); it('should filter events for regular users who are NOT organization members', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; // Test with 3 events: 2 public and 1 private to better test filtering const nonMemberTestEventData = [ { @@ -991,7 +976,7 @@ describe('Calendar', () => { // Render with organization member first to verify all events are shown const { rerender } = render( - + { // Now test with non-member rerender( - + { }); it('should only show public events when userRole is not provided', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; const noRoleTestEventData = [ { id: 'event1', @@ -1085,7 +1066,7 @@ describe('Calendar', () => { const { container, rerender } = render( - + { // Now test without userRole - should only see public events rerender( - + { }); it('should only show public events when userId is not provided', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; const noUserIdTestEventData = [ { id: 'event1', @@ -1175,7 +1152,7 @@ describe('Calendar', () => { const { container, rerender } = render( - + { // Now test without userId - should only see public events rerender( - + { }); it('should handle empty organization data for private events', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; const emptyOrgTestEventData = [ { id: 'event1', @@ -1265,7 +1238,7 @@ describe('Calendar', () => { const { container, rerender } = render( - + { // Now test without orgData - should only see public events rerender( - + { }, }; - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; + const currentDate = new Date().toISOString().split('T')[0]; const emptyMembersTestEventData = [ { id: 'event1', @@ -1366,7 +1335,7 @@ describe('Calendar', () => { const { container, rerender } = render( - + { // Now test with empty members orgData - should only see public events rerender( - + { }); it('should handle mixed public and private events correctly for organization members', async () => { - const date = new Date(); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - const currentDate = `${year}-${month}-${day}`; // Use current date + const currentDate = new Date().toISOString().split('T')[0]; // Use current date const mixedEventData = [ { id: 'event1', @@ -1472,7 +1437,7 @@ describe('Calendar', () => { const { container } = render( - + { expect(viewAllButton).toHaveTextContent('View all'); }); }); + + describe('Additional Coverage Tests (Day View & Edge Cases)', () => { + it('should toggle "View all" and "View less" specifically in DAY View', async () => { + const today = new Date(); + const year = today.getFullYear(); + const month = String(today.getMonth() + 1).padStart(2, '0'); + const day = String(today.getDate()).padStart(2, '0'); + const dateString = `${year}-${month}-${day}`; + + const dayEvents: InterfaceEvent[] = [1, 2, 3].map((i) => ({ + id: `day-evt-${i}`, + name: `Day Event ${i}`, + description: 'Description', + startAt: `${dateString}T10:00:00Z`, + endAt: `${dateString}T11:00:00Z`, + location: 'Location', + startTime: '10:00', + endTime: '11:00', + allDay: false, + isPublic: true, + isRegisterable: true, + attendees: [], + creator: { id: 'user-1' } as InterfaceEvent['creator'], + })); + + render( + + + + + + + , + ); + + const viewAllBtn = await screen.findByText('View all'); + expect(viewAllBtn).toBeInTheDocument(); + fireEvent.click(viewAllBtn); + const viewLessBtn = await screen.findByText('View less'); + expect(viewLessBtn).toBeInTheDocument(); + fireEvent.click(viewLessBtn); + const viewAllBtnAgain = await screen.findByText('View all'); + expect(viewAllBtnAgain).toBeInTheDocument(); + }); + + it('should render safely with no events', () => { + const emptyEvents: InterfaceEvent[] = []; + + render( + + + + + + + , + ); + + expect(screen.getByTestId('current-date')).toBeInTheDocument(); + }); + }); }); From 6d9c004a3dff0229db692901443610d51338fed0 Mon Sep 17 00:00:00 2001 From: Shivam Kumar Date: Tue, 2 Dec 2025 20:25:15 +0530 Subject: [PATCH 2/3] test: update EventCalendar tests per CodeRabbit review --- src/components/EventCalender/Monthly/EventCalendar.spec.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/EventCalender/Monthly/EventCalendar.spec.tsx b/src/components/EventCalender/Monthly/EventCalendar.spec.tsx index fd643d6d1c1..e45ef332bfb 100644 --- a/src/components/EventCalender/Monthly/EventCalendar.spec.tsx +++ b/src/components/EventCalender/Monthly/EventCalendar.spec.tsx @@ -1471,7 +1471,6 @@ describe('Calendar', () => { expect(viewAllButton).toHaveTextContent('View all'); }); }); - describe('Additional Coverage Tests (Day View & Edge Cases)', () => { it('should toggle "View all" and "View less" specifically in DAY View', async () => { const today = new Date(); @@ -1498,7 +1497,7 @@ describe('Calendar', () => { render( - + { const viewAllBtn = await screen.findByText('View all'); expect(viewAllBtn).toBeInTheDocument(); + fireEvent.click(viewAllBtn); const viewLessBtn = await screen.findByText('View less'); expect(viewLessBtn).toBeInTheDocument(); + fireEvent.click(viewLessBtn); const viewAllBtnAgain = await screen.findByText('View all'); expect(viewAllBtnAgain).toBeInTheDocument(); From 25892a721e5fa2239e2e228d2136dfec6480cf4b Mon Sep 17 00:00:00 2001 From: Shivam Kumar Date: Tue, 2 Dec 2025 20:38:26 +0530 Subject: [PATCH 3/3] test: make EventCalendar tests timezone-safe --- .../Monthly/EventCalendar.spec.tsx | 61 ++++++++++++++++--- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/src/components/EventCalender/Monthly/EventCalendar.spec.tsx b/src/components/EventCalender/Monthly/EventCalendar.spec.tsx index e45ef332bfb..176e4f80295 100644 --- a/src/components/EventCalender/Monthly/EventCalendar.spec.tsx +++ b/src/components/EventCalender/Monthly/EventCalendar.spec.tsx @@ -278,7 +278,11 @@ describe('Calendar', () => { }); it('Should handle window resize in day view', async () => { - const date = new Date().toISOString().split('T')[0]; + const now = new Date(); + const year = now.getFullYear(); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const day = String(now.getDate()).padStart(2, '0'); + const date = `${year}-${month}-${day}`; const multipleEventData = [ { id: '1', @@ -777,7 +781,12 @@ describe('Calendar', () => { }; it('should return all events when user role is ADMINISTRATOR', async () => { - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + const adminTestEventData = [ { id: 'event1', @@ -859,7 +868,12 @@ describe('Calendar', () => { }); it('should filter events for regular users who are organization members', async () => { - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + const memberTestEventData = [ { id: 'event1', @@ -923,7 +937,12 @@ describe('Calendar', () => { }); it('should filter events for regular users who are NOT organization members', async () => { - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + // Test with 3 events: 2 public and 1 private to better test filtering const nonMemberTestEventData = [ { @@ -1030,7 +1049,12 @@ describe('Calendar', () => { }); it('should only show public events when userRole is not provided', async () => { - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + const noRoleTestEventData = [ { id: 'event1', @@ -1116,7 +1140,12 @@ describe('Calendar', () => { }); it('should only show public events when userId is not provided', async () => { - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + const noUserIdTestEventData = [ { id: 'event1', @@ -1202,7 +1231,12 @@ describe('Calendar', () => { }); it('should handle empty organization data for private events', async () => { - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + const emptyOrgTestEventData = [ { id: 'event1', @@ -1299,7 +1333,12 @@ describe('Calendar', () => { }, }; - const currentDate = new Date().toISOString().split('T')[0]; + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; + const emptyMembersTestEventData = [ { id: 'event1', @@ -1386,7 +1425,11 @@ describe('Calendar', () => { }); it('should handle mixed public and private events correctly for organization members', async () => { - const currentDate = new Date().toISOString().split('T')[0]; // Use current date + const date = new Date(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const currentDate = `${year}-${month}-${day}`; const mixedEventData = [ { id: 'event1',