import { Header } from '@/presentation/components' ; import { AccountModel } from '@/domain/models' ; import { mockAccountModel } from '@/tests/domain/mocks' ; import { renderWithHistory } from '@/tests/presentation/mocks' ; import { fireEvent , screen } from '@testing-library/react' ; import { createMemoryHistory , MemoryHistory } from 'history' ; type SutTypes = { history : MemoryHistory ; setCurrentAccountMock : ( account : AccountModel ) => void ; } ; const makeSut = ( account = mockAccountModel ( ) ) : SutTypes => { const history = createMemoryHistory ( { initialEntries : [ '/' ] } ) ; const { setCurrentAccountMock } = renderWithHistory ( { history , Page : Header , account } ) ; return { history , setCurrentAccountMock } ; } ; describe ( 'Header Component' , ( ) => { test ( 'Should call setCurrentAccount with null' , ( ) => { const { history , setCurrentAccountMock } = makeSut ( ) ; fireEvent . click ( screen . getByTestId ( 'logout' ) ) ; expect ( setCurrentAccountMock ) . toHaveBeenCalledWith ( undefined ) ; expect ( history . location . pathname ) . toBe ( '/login' ) ; } ) ; test ( 'Should render username correctly' , ( ) => { const account = mockAccountModel ( ) ; makeSut ( account ) ; expect ( screen . getByTestId ( 'username' ) ) . toHaveTextContent ( account . name ) ; } ) ; } ) ;