1+ /// <reference types="cypress" />
2+ import { mount } from 'cypress/react' ;
3+ import React from 'react' ;
4+ import { Card , CardContent , Typography , Chip , Button , Box , Divider } from '@mui/material' ;
5+
6+ const mockMatch = {
7+ matchID : 'match1' ,
8+ status : 'CONFIRMED' ,
9+ group : {
10+ date : '2024-12-25' ,
11+ time : 9 ,
12+ location : 'Mensa Arcisstraße' ,
13+ userStatus : [
14+ { userID : 'user1' , status : 'CONFIRMED' } ,
15+ { userID : 'user2' , status : 'CONFIRMED' } ,
16+ { userID : 'user3' , status : 'SENT' } ,
17+ ] ,
18+ conversationStarters : {
19+ conversationsStarters : [
20+ { prompt : 'What is your favorite food?' } ,
21+ { prompt : 'If you could travel anywhere, where would you go?' } ,
22+ { prompt : 'What is your favorite hobby?' } ,
23+ ] ,
24+ } ,
25+ } ,
26+ } ;
27+
28+ const getConfirmedCount = ( userStatuses ) => userStatuses . filter ( ( u ) => u . status === 'CONFIRMED' ) . length ;
29+
30+ const formatDate = ( dateString ) => new Date ( dateString ) . toLocaleDateString ( 'en-US' , { weekday : 'long' , year : 'numeric' , month : 'long' , day : 'numeric' } ) ;
31+
32+ const formatTime = ( timeSlot ) => {
33+ const times = [
34+ '8:00 AM' , '8:30 AM' , '9:00 AM' , '9:30 AM' , '10:00 AM' , '10:30 AM' , '11:00 AM' , '11:30 AM' ,
35+ '12:00 PM' , '12:30 PM' , '1:00 PM' , '1:30 PM' , '2:00 PM' , '2:30 PM' , '3:00 PM' , '3:30 PM' ,
36+ ] ;
37+ return times [ timeSlot - 1 ] || 'Unknown time' ;
38+ } ;
39+
40+ describe ( 'MatchesCard.cy.tsx' , ( ) => {
41+ it ( 'should render match card information correctly' , ( ) => {
42+ mount (
43+ < Card sx = { { height : '280px' , display : 'flex' , flexDirection : 'column' } } >
44+ < CardContent sx = { { p : 2 , flex : 1 , display : 'flex' , flexDirection : 'column' } } >
45+ < Box display = "flex" justifyContent = "space-between" alignItems = "flex-start" mb = { 1.5 } >
46+ < Typography variant = "subtitle1" component = "h2" sx = { { fontSize : '0.9rem' , fontWeight : 600 } } data-testid = "match-date" >
47+ { formatDate ( mockMatch . group . date ) }
48+ </ Typography >
49+ < Chip label = { mockMatch . status } color = "success" size = "small" sx = { { fontSize : '0.7rem' , height : '20px' } } data-testid = "match-status" />
50+ </ Box >
51+ < Box mb = { 1.5 } >
52+ < Typography variant = "body2" color = "text.secondary" sx = { { fontSize : '0.8rem' , mb : 0.5 } } data-testid = "match-time" >
53+ < strong > Time:</ strong > { formatTime ( mockMatch . group . time ) }
54+ </ Typography >
55+ < Typography variant = "body2" color = "text.secondary" sx = { { fontSize : '0.8rem' , mb : 0.5 } } data-testid = "match-location" >
56+ < strong > Location:</ strong > { mockMatch . group . location }
57+ </ Typography >
58+ < Box display = "flex" alignItems = "center" gap = { 1 } >
59+ < Typography variant = "body2" color = "text.secondary" sx = { { fontSize : '0.8rem' } } >
60+ < strong > Participants:</ strong >
61+ </ Typography >
62+ < Chip
63+ label = { `${ getConfirmedCount ( mockMatch . group . userStatus ) } /${ mockMatch . group . userStatus . length } confirmed` }
64+ size = "small"
65+ variant = "outlined"
66+ sx = { { borderColor : 'primary.main' , color : 'primary.main' , fontSize : '0.65rem' , height : '18px' } }
67+ data-testid = "match-participants"
68+ />
69+ </ Box >
70+ </ Box >
71+ < Divider sx = { { my : 1.5 } } />
72+ < Box sx = { { flex : 1 , display : 'flex' , flexDirection : 'column' } } >
73+ < Typography variant = "subtitle2" gutterBottom sx = { { fontSize : '0.8rem' , fontWeight : 600 } } >
74+ Conversation Starters:
75+ </ Typography >
76+ < Box sx = { { flex : 1 , overflow : 'hidden' } } >
77+ { mockMatch . group . conversationStarters . conversationsStarters . slice ( 0 , 2 ) . map ( ( starter , index ) => (
78+ < Typography key = { index } variant = "body2" color = "text.secondary" sx = { { fontStyle : 'italic' , fontSize : '0.75rem' , mb : 0.5 , lineHeight : 1.3 , '&:last-child' : { mb : 0 } } } data-testid = { `conversation-starter-${ index } ` } >
79+ "{ starter . prompt } "
80+ </ Typography >
81+ ) ) }
82+ { mockMatch . group . conversationStarters . conversationsStarters . length > 2 && (
83+ < Button size = "small" sx = { { mt : 0.5 , fontSize : '0.7rem' , textTransform : 'none' , color : 'primary.main' , p : 0 , minWidth : 'auto' , '&:hover' : { backgroundColor : 'transparent' , textDecoration : 'underline' } } } data-testid = "view-all-starters" >
84+ View all ({ mockMatch . group . conversationStarters . conversationsStarters . length } )
85+ </ Button >
86+ ) }
87+ </ Box >
88+ </ Box >
89+ </ CardContent >
90+ </ Card >
91+ ) ;
92+ cy . get ( '[data-testid="match-date"]' ) . should ( 'contain' , 'Wednesday, December 25, 2024' ) ;
93+ cy . get ( '[data-testid="match-status"]' ) . should ( 'contain' , 'CONFIRMED' ) ;
94+ cy . get ( '[data-testid="match-time"]' ) . should ( 'contain' , '12:00 PM' ) ;
95+ cy . get ( '[data-testid="match-location"]' ) . should ( 'contain' , 'Mensa Arcisstraße' ) ;
96+ cy . get ( '[data-testid="match-participants"]' ) . should ( 'contain' , '2/3 confirmed' ) ;
97+ cy . get ( '[data-testid="conversation-starter-0"]' ) . should ( 'contain' , 'What is your favorite food?' ) ;
98+ cy . get ( '[data-testid="conversation-starter-1"]' ) . should ( 'contain' , 'If you could travel anywhere, where would you go?' ) ;
99+ cy . get ( '[data-testid="view-all-starters"]' ) . should ( 'be.visible' ) ;
100+ } ) ;
101+ } ) ;
0 commit comments