import { ListBuffer } from "./list" ; import { Neovim } from "neovim" ; import { BufferContainer } from "./container" ; import { HistoryList , HistoryListItem } from "./historyList" ; import { HistoryRepository , History } from "../repository/history" ; import { HighlightRepository } from "../repository/highlight" ; import { EventRegisterer } from "./event" ; describe ( "HistoryList" , ( ) => { let vim ; let bufferContainer ; let listBuffer ; let eventRegisterer ; let historyRepository ; let highlightRepository ; let historyList ; let getCurrent ; let getRangeModels ; let open ; let tabOpen ; beforeEach ( ( ) => { const NeovimClass = jest . fn ( ( ) => ( { } ) ) as any ; vim = new NeovimClass ( ) ; const BufferContainerClass = jest . fn ( ( ) => ( { } ) ) as any ; bufferContainer = new BufferContainerClass ( ) ; getCurrent = jest . fn ( ) . mockReturnValue ( null ) ; getRangeModels = jest . fn ( ) . mockReturnValue ( [ ] ) ; const TreeBufferClass = jest . fn ( ( ) => ( { getCurrent : getCurrent , getRangeModels : getRangeModels , } ) ) as any ; listBuffer = new TreeBufferClass ( ) ; const EventRegistererClass = jest . fn ( ( ) => ( { } ) ) as any ; eventRegisterer = new EventRegistererClass ( ) ; open = jest . fn ( ) ; tabOpen = jest . fn ( ) ; const HistoryRepositoryClass = jest . fn ( ( ) => ( { open : open , tabOpen : tabOpen , } ) ) as any ; historyRepository = new HistoryRepositoryClass ( ) ; const HighlightRepositoryClass = jest . fn ( ( ) => ( { } ) ) as any ; highlightRepository = new HighlightRepositoryClass ( ) ; historyList = new HistoryList ( vim , bufferContainer , listBuffer , eventRegisterer , highlightRepository , historyRepository ) ; } ) ; it ( "openHistory does nothing when the current item is null" , async ( ) => { await historyList . openHistory ( ) ; expect ( open ) . not . toHaveBeenCalled ( ) ; } ) ; it ( "openHistory does nothing when the current item does not have url" , async ( ) => { const history = { title : "title" , } ; getCurrent = jest . fn ( ) . mockReturnValue ( history ) ; const TreeBufferClass = jest . fn ( ( ) => ( { getCurrent : getCurrent , } ) ) as any ; listBuffer = new TreeBufferClass ( ) ; historyList = new HistoryList ( vim , bufferContainer , listBuffer , eventRegisterer , highlightRepository , historyRepository ) ; await historyList . openHistory ( ) ; expect ( open ) . not . toHaveBeenCalled ( ) ; } ) ; it ( "openHistory" , async ( ) => { const url = "url" ; const history = { title : "title" , url : url , } ; getCurrent = jest . fn ( ) . mockReturnValue ( history ) ; const TreeBufferClass = jest . fn ( ( ) => ( { getCurrent : getCurrent , } ) ) as any ; listBuffer = new TreeBufferClass ( ) ; historyList = new HistoryList ( vim , bufferContainer , listBuffer , eventRegisterer , highlightRepository , historyRepository ) ; await historyList . openHistory ( ) ; expect ( open ) . toHaveBeenCalledWith ( url ) ; } ) ; it ( "tabOpenHistory does nothing when the current item is null" , async ( ) => { await historyList . tabOpenHistory ( 1 , 1 ) ; expect ( tabOpen ) . toHaveBeenCalledWith ( [ ] ) ; } ) ; it ( "tabOpenHistory does nothing when the current item does not have url" , async ( ) => { const history = { title : "title" , } ; getRangeModels = jest . fn ( ) . mockReturnValue ( [ history ] ) ; const TreeBufferClass = jest . fn ( ( ) => ( { getRangeModels : getRangeModels , } ) ) as any ; listBuffer = new TreeBufferClass ( ) ; historyList = new HistoryList ( vim , bufferContainer , listBuffer , eventRegisterer , highlightRepository , historyRepository ) ; await historyList . tabOpenHistory ( 1 , 1 ) ; expect ( tabOpen ) . toHaveBeenCalledWith ( [ ] ) ; } ) ; it ( "tabOpenHistory" , async ( ) => { const url = "url" ; const history = { title : "title" , url : url , } ; getRangeModels = jest . fn ( ) . mockReturnValue ( [ history ] ) ; const TreeBufferClass = jest . fn ( ( ) => ( { getRangeModels : getRangeModels , } ) ) as any ; listBuffer = new TreeBufferClass ( ) ; historyList = new HistoryList ( vim , bufferContainer , listBuffer , eventRegisterer , highlightRepository , historyRepository ) ; await historyList . tabOpenHistory ( 1 , 1 ) ; expect ( tabOpen ) . toHaveBeenCalledWith ( [ url ] ) ; } ) ; } ) ; describe ( "HistoryListItem" , ( ) => { let item ; let history ; beforeEach ( ( ) => { const HistoryClass = jest . fn ( ( ) => ( { title : "title" , url : "url" , } ) ) ; history = new HistoryClass ( ) ; item = new HistoryListItem ( history ) ; } ) ; it ( "toString" , ( ) => { expect ( "title\turl" ) . toEqual ( item . toString ( ) ) ; } ) ; it ( "value" , ( ) => { expect ( history ) . toEqual ( item . value ) ; } ) ; } ) ;