@@ -2,25 +2,31 @@ import React from "react";
22import { render , waitFor , screen , fireEvent } from "@testing-library/react" ;
33import CSCalendar from "../../components/CSCalendar" ;
44
5- // Mock dependencies
6- jest . mock ( "../../utils/createTds" , ( ) => ( {
7- createTds : jest . fn ( ) ,
8- } ) ) ;
9-
105jest . mock ( "../../constants/events" , ( ) => ( {
116 events : [
127 {
138 title : "جلسه مرحله سوم" ,
149 fullName : "جلسه مرحله سوم: پرسشوپاسخ" ,
10+ link : "https://teams.microsoft.com/meeting-3" ,
11+ resource : "https://example.com/resource-3" ,
1512 } ,
1613 {
1714 title : "جلسه مرحله دوم" ,
1815 fullName : "جلسه مرحله دوم: پرسشوپاسخ" ,
16+ link : "https://teams.microsoft.com/meeting-2" ,
17+ resource : "https://example.com/resource-2" ,
18+ } ,
19+ {
20+ title : "جلسه مصاحبه" ,
21+ fullName : "جلسه مصاحبه ورود به برنامه" ,
22+ link : "" ,
23+ resource : "" ,
1924 } ,
20- { title : "جلسه مصاحبه" , fullName : "جلسه مصاحبه ورود به برنامه" } ,
2125 {
2226 title : "جلسه مرحله اول" ,
2327 fullName : "جلسه مرحله اول: پرسشوپاسخ" ,
28+ link : "https://teams.microsoft.com/meeting-1" ,
29+ resource : "https://example.com/resource-1" ,
2430 } ,
2531 ] ,
2632} ) ) ;
@@ -41,10 +47,6 @@ jest.mock("../../constants/persianWeekDays", () => ({
4147 ] ,
4248} ) ) ;
4349
44- jest . mock ( "../../components/useIsMobile" , ( ) => ( {
45- useIsMobile : jest . fn ( ( ) => false ) ,
46- } ) ) ;
47-
4850jest . mock ( "../../components/CalendarEventCreator" , ( ) => {
4951 return function MockCalendarEventCreator ( ) {
5052 return (
@@ -187,31 +189,93 @@ describe("CSCalendar", () => {
187189 expect ( getByText ( "ماه بعد" ) ) . toBeInTheDocument ( ) ;
188190 } ) ;
189191
190- it ( "should render Alert component" , ( ) => {
192+ it ( "should not render bottom Alert component anymore (popup replaces it) " , ( ) => {
191193 const { container } = render (
192194 < CSCalendar
193195 setAnnouncementData = { mockSetAnnouncementData }
194196 addToCurrentWeek = { mockAddToCurrentWeek }
195197 />
196198 ) ;
197199
198- expect ( container . querySelector ( ".ant-alert" ) ) . toBeInTheDocument ( ) ;
200+ expect ( container . querySelector ( ".ant-alert" ) ) . not . toBeInTheDocument ( ) ;
199201 } ) ;
200202
201- it ( "should display event description" , ( ) => {
202- const { getByText } = render (
203+ it ( "clicking a calendar cell with event should open anchored popup showing event details" , async ( ) => {
204+ const { container, getByText } = render (
205+ < CSCalendar
206+ setAnnouncementData = { mockSetAnnouncementData }
207+ addToCurrentWeek = { mockAddToCurrentWeek }
208+ />
209+ ) ;
210+
211+ await waitFor ( ( ) => {
212+ // find clickable cell wrapper
213+ const cells = container . querySelectorAll (
214+ ".calendar-cell-with-event"
215+ ) ;
216+ expect ( cells . length ) . toBeGreaterThanOrEqual ( 0 ) ;
217+ // find the first wrapper that actually contains an event (stage-tag)
218+ const clickable = Array . from ( cells ) . find ( ( c ) =>
219+ c . querySelector ( ".stage-tag" )
220+ ) ;
221+ expect ( clickable ) . toBeTruthy ( ) ;
222+ if ( clickable ) fireEvent . click ( clickable ) ;
223+ } ) ;
224+
225+ // popup should show the Persian date label
226+ expect ( getByText ( "تاریخ شمسی" ) ) . toBeInTheDocument ( ) ;
227+ // session link should be labeled as Microsoft Teams in Persian and resource should be present
228+ expect ( getByText ( "ماکروسافت تیمز" ) ) . toBeInTheDocument ( ) ;
229+ expect ( getByText ( "مشاهده منبع" ) ) . toBeInTheDocument ( ) ;
230+ } ) ;
231+
232+ it ( "clicking the calendar TD (cell square) containing a staged event opens the popup" , async ( ) => {
233+ const { container, getByText } = render (
203234 < CSCalendar
204235 setAnnouncementData = { mockSetAnnouncementData }
205236 addToCurrentWeek = { mockAddToCurrentWeek }
206237 />
207238 ) ;
208239
209- // Should render event description or "no event" message
210- const eventDescription = getByText ( ( content , element ) => {
211- return element && element . className === "event-description" ;
240+ await waitFor ( ( ) => {
241+ // find a table cell that contains our clickable wrapper
242+ const tds = Array . from (
243+ container . querySelectorAll ( ".ant-picker-cell" )
244+ ) ;
245+ const tdWithEvent = tds . find ( ( td ) =>
246+ td . querySelector ( ".calendar-cell-with-event .stage-tag" )
247+ ) ;
248+
249+ expect ( tdWithEvent ) . toBeTruthy ( ) ;
250+
251+ if ( tdWithEvent ) {
252+ fireEvent . click ( tdWithEvent ) ;
253+ }
212254 } ) ;
213255
214- expect ( eventDescription ) . toBeInTheDocument ( ) ;
256+ expect ( getByText ( "تاریخ شمسی" ) ) . toBeInTheDocument ( ) ;
257+ expect ( getByText ( "ماکروسافت تیمز" ) ) . toBeInTheDocument ( ) ;
258+ expect ( getByText ( "مشاهده منبع" ) ) . toBeInTheDocument ( ) ;
259+ } ) ;
260+
261+ it ( "every calendar cell should contain a date-label Tag and be annotated with data-date" , async ( ) => {
262+ const { container } = render (
263+ < CSCalendar
264+ setAnnouncementData = { mockSetAnnouncementData }
265+ addToCurrentWeek = { mockAddToCurrentWeek }
266+ />
267+ ) ;
268+
269+ await waitFor ( ( ) => {
270+ const wrappers = container . querySelectorAll (
271+ ".calendar-cell-with-event"
272+ ) ;
273+ expect ( wrappers . length ) . toBeGreaterThan ( 0 ) ;
274+ const hasDateAttr = Array . from ( wrappers ) . some ( ( w ) =>
275+ w . getAttribute ( "data-date" )
276+ ) ;
277+ expect ( hasDateAttr ) . toBeTruthy ( ) ;
278+ } ) ;
215279 } ) ;
216280
217281 it ( "should have select elements for month and year" , ( ) => {
@@ -356,16 +420,16 @@ describe("CSCalendar", () => {
356420 expect ( todayBtn ) . toBeInTheDocument ( ) ;
357421 } ) ;
358422
359- it ( "should render ConfigProvider with RTL direction " , ( ) => {
423+ it ( "should not show the anchored popup on initial render " , ( ) => {
360424 const { container } = render (
361425 < CSCalendar
362426 setAnnouncementData = { mockSetAnnouncementData }
363427 addToCurrentWeek = { 0 }
364428 />
365429 ) ;
366430
367- const alert = container . querySelector ( ".ant-alert " ) ;
368- expect ( alert ) . toBeInTheDocument ( ) ;
431+ const popup = container . querySelector ( ".event-popup " ) ;
432+ expect ( popup ) . not . toBeInTheDocument ( ) ;
369433 } ) ;
370434
371435 it ( "should handle onPanelChange when month/year changes" , ( ) => {
0 commit comments