import { PrivateRoute } from '@/main/proxies' ; import { renderWithHistory } from '@/tests/presentation/mocks' ; import { mockAccountModel } from '@/tests/domain/mocks' ; import { createMemoryHistory , MemoryHistory } from 'history' ; type SutTypes = { history : MemoryHistory ; } ; const makeSut = ( account = mockAccountModel ( ) ) : SutTypes => { const history = createMemoryHistory ( { initialEntries : [ '/' ] } ) ; renderWithHistory ( { history , Page : PrivateRoute , account } ) ; return { history } ; } ; describe ( 'PrivateRoute' , ( ) => { test ( 'Should redirect to /login if token is empty' , ( ) => { const { history } = makeSut ( null ) ; expect ( history . location . pathname ) . toBe ( '/login' ) ; } ) ; test ( 'Should render current component if token is not empty' , ( ) => { const { history } = makeSut ( ) ; expect ( history . location . pathname ) . toBe ( '/' ) ; } ) ; } ) ;