import { expect } from "chai" ; import { BackgroundMapProps , BackgroundMapProviderName , BackgroundMapSettings , BackgroundMapType , GlobeMode , PersistentBackgroundMapProps , TerrainHeightOriginMode , } from "@itwin/core-common" ; import { IModelConnection , SnapshotConnection } from "@itwin/core-frontend" ; import { TestUtility } from "../TestUtility" ; import { testOnScreenViewport , TestViewport } from "../TestViewport" ; describe ( "Background map" , ( ) => { let imodel ; before ( async ( ) => { await TestUtility . startFrontend ( { ... TestUtility . iModelAppOptions , renderSys : { dpiAwareViewports : false } } ) ; imodel = await SnapshotConnection . openFile ( "mirukuru.ibim" ) ; } ) ; after ( async ( ) => { if ( imodel ) await imodel . close ( ) ; await TestUtility . shutdownFrontend ( ) ; } ) ; it ( "produces a different tile tree when background map settings change" , async ( ) => { async function isSameTileTree ( vp , props ) { expect ( vp . viewFlags . backgroundMap ) . to . be . true ; await vp . waitForAllTilesToRender ( ) ; const prevTree = vp . backgroundMap ! . treeOwner . tileTree ! ; expect ( prevTree ) . not . to . be . undefined ; vp . changeBackgroundMapProps ( props as BackgroundMapProps ) ; if ( props . providerName || props . providerData ) { vp . displayStyle . changeBackgroundMapProvider ( { name : props . providerName as BackgroundMapProviderName , type : props . providerData ?. mapType } ) ; } await vp . waitForAllTilesToRender ( ) ; const newTree = vp . backgroundMap ! . treeOwner . tileTree ! ; expect ( newTree ) . not . to . be . undefined ; return newTree === prevTree ; } type Test = [ BackgroundMapProps | PersistentBackgroundMapProps , boolean ] ; const tests = [ [ { } , true ] , [ BackgroundMapSettings . fromJSON ( ) . toJSON ( ) , true ] , [ { useDepthBuffer : true } , false ] , [ { groundBias : 100 } , false ] , [ { groundBias : 0 } , false ] , [ { transparency : 0.5 } , false ] , [ { providerName : "NotAValidProvider" } , true ] , [ { providerName : "MapBoxProvider" } , true ] , [ { providerData : { mapType : BackgroundMapType . Street } } , true ] , [ { globeMode : GlobeMode . Plane } , false ] , [ { terrainSettings : { exaggeration : 42 } } , true ] , [ { terrainSettings : { heightOrigin : 21 } } , true ] , [ { terrainSettings : { heightOriginMode : TerrainHeightOriginMode . Ground } } , true ] , ] ; await testOnScreenViewport ( "0x24" , imodel , 100 , 100 , async ( vp ) => { vp . viewFlags = vp . viewFlags . with ( "backgroundMap" , true ) ; for ( const test of tests ) { expect ( await isSameTileTree ( vp , test [ 0 ] ) ) . to . equal ( test [ 1 ] ) ; expect ( await isSameTileTree ( vp , test [ 0 ] ) ) . to . be . true ; } } ) ; } ) ; } ) ;