import * as chai from "chai" ; import * as chaiAsPromised from "chai-as-promised" ; import { ProcessDetector } from "@itwin/core-bentley" ; import { IModelApp , PrimitiveTool , SnapshotConnection , Viewport } from "@itwin/core-frontend" ; import { EditTools } from "@itwin/editor-frontend" ; import { testCmdIds , TestCmdOjb1 , TestCmdResult , TestCommandIpc } from "../../common/TestEditCommandIpc" ; import { TestUtility } from "../TestUtility" ; const expect = chai . expect ; const assert = chai . assert ; chai . use ( chaiAsPromised ) ; let iModel ; let testOut ; const cmdArg = "test command arg" ; let cmdStr ; class TestEditTool1 extends PrimitiveTool { public static override toolId = "TestEditTool1" ; public override isCompatibleViewport ( _vp , _isSelectedViewChange ) { return true ; } public async onRestartTool ( ) { return this . exitTool ( ) ; } public static callCommand < T extends keyof TestCommandIpc > ( method , ... args ) { return EditTools . callCommand ( method , ... args ) as ReturnType < TestCommandIpc [ T ] > ; } public async go ( cmd , str1 , str2 , obj1 ) { cmdStr = await EditTools . startCommand < string > ( cmd , iModel . key , cmdArg ) ; testOut = await TestEditTool1 . callCommand ( "testMethod1" , str1 , str2 , obj1 ) ; } } if ( ! ProcessDetector . isMobileAppFrontend ) { describe ( "EditTools" , ( ) => { before ( async ( ) => { await TestUtility . startFrontend ( undefined , undefined , true ) ; const namespace = "TestApp" ; await IModelApp . localization . registerNamespace ( namespace ) ; IModelApp . tools . register ( TestEditTool1 , namespace ) ; iModel = await SnapshotConnection . openFile ( "test.bim" ) ; } ) ; after ( async ( ) => { await iModel . close ( ) ; await TestUtility . shutdownFrontend ( ) ; } ) ; it ( "should start edit commands" , async ( ) => { expect ( await IModelApp . tools . run ( "TestEditTool1" ) ) . to . be . true ; const tool = IModelApp . toolAdmin . currentTool as TestEditTool1 ; assert . isTrue ( tool instanceof TestEditTool1 ) ; const str1 = "abc" ; const str2 = "def" ; const obj1 = { i1 : 10 , i2 : 20 , buf : Int8Array . from ( [ 1 , 2 , 3 , 4 , 6 ] ) } ; await tool . go ( testCmdIds . cmd1 , str1 , str2 , obj1 ) ; assert . equal ( cmdStr , `${ cmdArg }:1` ) ; assert . equal ( testOut . num , 30 ) ; assert . equal ( testOut . str , "abcdef" ) ; assert . deepEqual ( Array . from ( testOut . buf ) , [ 1 , 2 , 3 , 4 , 6 , - 22 ] ) ; await tool . go ( testCmdIds . cmd2 , str1 , str2 , obj1 ) ; assert . equal ( cmdStr , `${ cmdArg }:2` ) ; assert . equal ( testOut . num , - 10 ) ; assert . equal ( testOut . str , "defabc" ) ; assert . deepEqual ( Array . from ( testOut . buf ) , [ 1 , 2 , 3 , 4 , 6 , - 32 ] ) ; } ) ; } ) ; }