import TeamCredentials from '../support/types/teamCredentials' ; describe ( 'Logging In' , ( ) => { const teamCredentials = { teamName : 'Test Login' , teamId : 'test-login' , password : 'Login1234' , jwt : '' , } as TeamCredentials ; before ( ( ) => { cy . createTeam ( teamCredentials ) ; } ) ; beforeEach ( ( ) => { cy . intercept ( 'POST' , '/api/team/login' ) . as ( 'postTeamLogin' ) ; } ) ; it ( 'Redirects to login page when action comes back unauthorized' , ( ) => { cy . login ( teamCredentials ) ; cy . wait ( '@postTeamLogin' ) . then ( ( ) => { cy . document ( ) . setCookie ( 'token' , '' ) ; cy . document ( ) . setCookie ( 'JSESSIONID' , '' ) ; cy . enterThought ( 'happy' , 'I have a thought' ) ; cy . url ( ) . should ( 'eq' , Cypress . config ( ) . baseUrl + '/login' ) ; } ) ; } ) ; it ( 'Displays invalid team name when logging in with bad team' , ( ) => { cy . login ( { teamName : 'Something not correct' , teamId : 'Something not correct' , password : 'Something else wrong' , jwt : '' , } ) ; cy . findByText ( 'Incorrect board name. Please try again.' ) . should ( 'exist' ) ; } ) ; it ( 'Displays invalid team name/password when using bad password' , ( ) => { cy . login ( { ... teamCredentials , password : 'Something else wrong' , } ) ; cy . findByText ( 'Incorrect board or password. Please try again.' ) . should ( 'exist' ) ; } ) ; it ( 'Navigates to team board after successful login' , ( ) => { cy . login ( teamCredentials ) ; cy . url ( ) . should ( 'eq' , `${ Cypress . config ( ) . baseUrl }/team/${ teamCredentials . teamId }` ) ; } ) ; it ( 'Pre-populates team name' , ( ) => { cy . visit ( '/login' ) ; cy . contains ( 'Sign in to your Board!' ) ; cy . get ( '#teamNameInput' ) . as ( 'teamNameInput' ) ; cy . get ( '@teamNameInput' ) . should ( 'have.value' , '' ) ; cy . visit ( `/login/${ teamCredentials . teamId }` ) ; cy . get ( '@teamNameInput' ) . should ( 'have.value' , teamCredentials . teamName ) ; } ) ; } ) ;