import { createAndLoginTA , checkInTA , createQueue , createQuestion , createQueueWithoutOfficeHour , } from "../../utils" ; describe ( "Can successfuly check in and out of a queue when their is scheduled office hours" , ( ) => { beforeEach ( ( ) => { createAndLoginTA ( ) ; createQueue ( { courseId : "ta.course.id" } ) ; } ) ; it ( "checking in multiple TAs then checking one out" , function ( ) { createAndLoginTA ( { identifier : "ta2" , courseId : "ta.course.id" } ) ; checkInTA ( ) ; createQuestion ( { queueId : "queue.id" } ) ; cy . get ( ".ant-modal-close-x" ) . click ( ) ; cy . get ( "[data-cy='check-in-button']" ) . click ( ) ; cy . location ( "pathname" ) . should ( "contain" , "/queue" ) ; cy . contains ( "Check Out" ) ; cy . get ( "[data-cy='ta-status-card']" ) . should ( "have.length" , "2" ) ; cy . percySnapshot ( "TA Queue Page - Two TA's Checked In" ) ; cy . get ( `[data-cy="list-queue"] [data-cy^="queue-list-item"]` ) . should ( "have.length" , "1" ) ; cy . get ( "[data-cy='check-out-button']" ) . click ( ) ; cy . get ( "button" ) . should ( "contain" , "Check In" ) ; cy . get ( "[data-cy='ta-status-card']" ) . should ( "have.length" , "1" ) ; cy . get ( `[data-cy="list-queue"] [data-cy^="queue-list-item"]` ) . should ( "have.length" , "1" ) ; cy . percySnapshot ( "TA Queue Page - One TA Checked out One TA Checked In" ) ; } ) ; it ( "from the queue page" , function ( ) { cy . visit ( `/course/${ this . queue . courseId }/queue/${ this . queue . id }` ) ; cy . get ( "body" ) . should ( "contain" , "There are no questions in the queue" ) ; cy . get ( "[data-cy='check-in-button']" ) . click ( ) ; cy . contains ( "Check Out" ) ; cy . percySnapshot ( "TA Queue Page - TA Checked In" ) ; cy . get ( "[data-cy='check-out-button']" ) . click ( ) ; cy . get ( "button" ) . should ( "contain" , "Check In" ) ; cy . contains ( "Schedule" ) ; cy . percySnapshot ( "TA Queue Page - TA Checked Out" ) ; } ) ; it ( "checkout from the today page" , function ( ) { cy . visit ( `/course/${ this . queue . courseId }/today` ) ; cy . get ( ".ant-modal-close-x" ) . click ( ) ; cy . contains ( "No Staff Checked In" ) ; cy . get ( "[data-cy='check-in-button']" ) . click ( ) ; cy . location ( "pathname" ) . should ( "contain" , "/queue" ) ; cy . get ( "body" ) . should ( "contain" , "There are no questions in the queue" ) ; cy . visit ( `/course/${ this . ta . courseId }/today` ) ; cy . get ( "[data-cy='check-out-button']" ) . click ( ) ; cy . get ( "button" ) . should ( "contain" , "Check In" ) ; } ) ; } ) ; describe ( "Checking out when office hours end soon" , ( ) => { beforeEach ( ( ) => { createAndLoginTA ( ) ; createQueue ( { courseId : "ta.course.id" , closesIn : 5 * 60 * 1000 } ) ; checkInTA ( ) ; createQuestion ( { queueId : "queue.id" } ) ; } ) ; it ( "opens the clean queue page from the queue page" , function ( ) { cy . visit ( `/course/${ this . queue . courseId }/queue/${ this . queue . id }` ) ; cy . get ( "[data-cy='list-queue'] [data-cy^='queue-list-item']" ) . should ( "have.length" , "1" ) ; cy . get ( "[data-cy='check-out-button']" ) . click ( ) ; cy . get ( "[data-cy='clear-queue-btn']" ) . click ( ) ; cy . get ( "body" ) . should ( "contain" , "There are no questions in the queue" ) ; } ) ; it ( "opens the clean queue page from the today page" , function ( ) { cy . visit ( `/course/${ this . queue . courseId }/today` ) ; cy . get ( "div" ) . should ( "contain" , "1 in queue" ) ; cy . get ( ".ant-modal-close-x" ) . click ( ) ; cy . get ( "[data-cy='check-out-button']" ) . click ( ) ; cy . get ( "[data-cy='clear-queue-btn']" ) . click ( ) ; } ) ; } ) ; describe ( "Checking in and out when there arent scheduled office hours, but the online queue exists" , function ( ) { beforeEach ( ( ) => { createAndLoginTA ( ) ; cy . get ( "@ta" ) . then ( ( ta ) => { createQueueWithoutOfficeHour ( { courseId : ta . courseId } ) ; cy . request ( { method : "POST" , url : `/api/v1/courses/${ ta . courseId }/ta_location/Online` } ) . then ( ( res ) => res . body ) . as ( "queue" ) . then ( ( queue ) => { createQuestion ( { queueId : "queue.id" , identifier : "question" } ) ; cy . visit ( `/course/${ ta . courseId }/queue/${ queue . id }` ) ; } ) ; } ) ; } ) ; it ( "checking in a TA when there is not scheduled office hours" , function ( ) { cy . get ( "[data-cy='ta-status-card']" ) . should ( "be.visible" ) ; cy . get ( `[data-cy="list-queue"] [data-cy^="queue-list-item"]` ) . should ( "have.length" , "1" ) ; cy . get ( "[data-cy='check-out-button']" ) . click ( ) ; cy . get ( "[data-cy='clear-queue-btn']" ) . click ( ) ; cy . get ( "[data-cy='ta-status-card']" ) . should ( "not.exist" ) ; cy . get ( `[data-cy="list-queue"] [data-cy^="queue-list-item"]` ) . should ( "not.exist" ) ; } ) ; } ) ;