import { assert } from "chai" ; import * as tsMockito from "ts-mockito" ; import { instance , mock , when } from "ts-mockito" ; import { ResourceProvider } from "../../../src/view/dataproviders/resourceprovider" ; import { CheckInInfo } from "../../../src/bll/entities/checkininfo" ; import { CvsSupportProvider } from "../../../src/dal/cvsprovider" ; import { GitProvider } from "../../../src/dal/git/GitProvider" ; import { CvsResource } from "../../../src/bll/entities/cvsresources/cvsresource" ; import { AddedCvsResource } from "../../../src/bll/entities/cvsresources/addedcvsresource" ; import { CheckInInfoItem } from "../../../src/bll/entities/presentable/checkininfoitem" ; import { CvsResourceItem } from "../../../src/bll/entities/cvsresources/cvsresourceitem" ; import { DataProviderEnum } from "../../../src/bll/utils/constants" ; suite ( "ResourceProviders" , ( ) => { const mockedCvsProvider = tsMockito . mock ( GitProvider ) ; const cvsProviderSpy = tsMockito . instance ( mockedCvsProvider ) ; const emptyCheckInInfo = new CheckInInfo ( [ ] , cvsProviderSpy , "testWRP" ) ; const emptyCheckInInfo2 = new CheckInInfo ( [ ] , cvsProviderSpy , "testWRP" ) ; test ( "should verify resource data provider constructor" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; assert . notEqual ( resourceProvider , undefined ) ; } ) ; test ( "should verify getType" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; assert . equal ( resourceProvider . getType ( ) , DataProviderEnum . ResourcesProvider ) ; } ) ; test ( "should verify setContent" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; const checkInInfo = [ emptyCheckInInfo , emptyCheckInInfo2 ] ; resourceProvider . setContent ( checkInInfo ) ; const expectedCheckInInfoItems = [ ] ; checkInInfo . forEach ( ( changes ) => expectedCheckInInfoItems . push ( new CheckInInfoItem ( changes ) ) ) ; assert . deepEqual ( resourceProvider . getChildren ( ) , expectedCheckInInfoItems ) ; } ) ; test ( "should verify resetContent" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; const checkInInfo = [ emptyCheckInInfo , emptyCheckInInfo2 ] ; resourceProvider . setContent ( checkInInfo ) ; resourceProvider . resetTreeContent ( ) ; assert . deepEqual ( resourceProvider . getChildren ( ) , [ ] ) ; } ) ; test ( "should verify getChildren with no arguments" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; const checkInInfo = [ emptyCheckInInfo , emptyCheckInInfo2 ] ; resourceProvider . setContent ( checkInInfo ) ; const expectedCheckInInfoItems = [ ] ; checkInInfo . forEach ( ( changes ) => expectedCheckInInfoItems . push ( new CheckInInfoItem ( changes ) ) ) ; assert . deepEqual ( resourceProvider . getChildren ( ) , expectedCheckInInfoItems ) ; } ) ; test ( "should verify getChildren with TreeItem argument" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; const cvsProviderMock = mock ( GitProvider ) ; when ( cvsProviderMock . getRootPath ( ) ) . thenReturn ( "" ) ; const cvsProviderSpy = instance ( cvsProviderMock ) ; const aResources = [ new AddedCvsResource ( undefined , undefined , undefined ) ] ; const aResourceItems = [ ] ; aResources . forEach ( ( resource ) => aResourceItems . push ( new CvsResourceItem ( resource ) ) ) ; const stabbedCheckInInfo = new CheckInInfo ( aResources , cvsProviderSpy , "testWRP" ) ; const stabbedCheckInInfoItem = new CheckInInfoItem ( stabbedCheckInInfo ) ; assert . deepEqual ( resourceProvider . getChildren ( stabbedCheckInInfoItem ) , aResourceItems ) ; } ) ; test ( "should verify getSelectedContent with all selected content" , function ( ) { const resourceProvider = new ResourceProvider ( ) ; const mockedCvsProvider = tsMockito . mock ( GitProvider ) ; const cvsProviderSpy = tsMockito . instance ( mockedCvsProvider ) ; const includedResource = new AddedCvsResource ( undefined , undefined , undefined ) ; const includedResource2 = new AddedCvsResource ( undefined , undefined , undefined ) ; const mockedCheckInInfo = new CheckInInfo ( [ includedResource , includedResource2 ] , cvsProviderSpy , "testWRP" ) ; const expectedCheckInInfo = new CheckInInfo ( [ includedResource , includedResource2 ] , cvsProviderSpy , "testWRP" ) ; resourceProvider . setContent ( [ mockedCheckInInfo ] ) ; assert . deepEqual ( resourceProvider . getSelectedContent ( ) , [ expectedCheckInInfo ] ) ; } ) ; } ) ;