import React from 'react' ; import { render , screen } from '@testing-library/react' ; import { HeaderComponent } from './header.component' ; describe ( 'HeaderComponent unit tests' , ( ) => { it ( 'should show the trainer and the students links when passing valid values' , ( ) => { const props = { currentTrainerUrl : 'http://current.trainer.url' , currentStudentUrl : 'http://current.student.url' , } ; render ( < HeaderComponent { ... props } / > ) ; const linkCopyInputs = screen . getAllByRole ( 'textbox' ) ; const linkCopyButtons = screen . getAllByRole ( 'button' ) ; expect ( linkCopyInputs . length ) . toBe ( 2 ) ; expect ( linkCopyButtons . length ) . toBe ( 2 ) ; linkCopyInputs . forEach ( input => expect ( input ) . toHaveAttribute ( 'readonly' ) ) ; expect ( linkCopyInputs [ 0 ] ) . toHaveValue ( props . currentTrainerUrl ) ; expect ( linkCopyInputs [ 1 ] ) . toHaveValue ( props . currentStudentUrl ) ; } ) ; it ( 'should show empty trainer and the students link when passing undefined values' , ( ) => { const props = { currentTrainerUrl : undefined , currentStudentUrl : undefined , } ; render ( < HeaderComponent { ... props } / > ) ; const linkCopyInputs = screen . getAllByRole ( 'textbox' ) ; expect ( linkCopyInputs [ 0 ] ) . toBeEmpty ( ) ; expect ( linkCopyInputs [ 1 ] ) . toBeEmpty ( ) ; } ) ; it ( 'should show empty trainer and the students link when passing null values' , ( ) => { const props = { currentTrainerUrl : null , currentStudentUrl : null , } ; render ( < HeaderComponent { ... props } / > ) ; const linkCopyInputs = screen . getAllByRole ( 'textbox' ) ; expect ( linkCopyInputs [ 0 ] ) . toBeEmpty ( ) ; expect ( linkCopyInputs [ 1 ] ) . toBeEmpty ( ) ; } ) ; } ) ;