11import { AndroidApplicationManager } from "../../mobile/android/android-application-manager" ;
22import { Yok } from "../../yok" ;
33import { assert } from "chai" ;
4- import { CommonLoggerStub , LogcatHelperStub , AndroidProcessServiceStub , DeviceLogProviderStub , ErrorsStub } from "./stubs" ;
4+ import { AndroidBundleToolServiceStub , CommonLoggerStub , HooksServiceStub , LogcatHelperStub , AndroidProcessServiceStub , DeviceLogProviderStub , ErrorsStub } from "./stubs" ;
5+ import { FileSystemStub } from "../../../../test/stubs" ;
56const invalidIdentifier = "invalid.identifier" ;
67const validDeviceIdentifier = "device.identifier" ;
78const validIdentifier = "org.nativescript.testApp" ;
89const validStartOptions = { appId : validIdentifier , projectName : "" , projectDir : "" } ;
10+ const validSigning : any = { keyStoreAlias : "string" , keyStorePath : "string" , keyStoreAliasPassword : "string" , keyStorePassword : "string" } ;
911
1012class AndroidDebugBridgeStub {
13+ public calledInstallApplication = false ;
1114 public calledStopApplication = false ;
1215 public startedWithActivityManager = false ;
1316 public validIdentifierPassed = false ;
@@ -42,6 +45,12 @@ class AndroidDebugBridgeStub {
4245 frontOfTask=true task=TaskRecord{fe592ac #449 A=org.nativescript.testApp U=0 StackId=1 sz=1}"
4346 ] ;
4447
48+ public async executeCommand ( args : string [ ] , options ?: any ) : Promise < any > {
49+ if ( args [ 0 ] === "install" ) {
50+ this . calledInstallApplication = true ;
51+ }
52+ }
53+
4554 public async executeShellCommand ( args : string [ ] ) : Promise < any > {
4655 if ( args && args . length > 0 ) {
4756 if ( args [ 0 ] . startsWith ( "cat" ) ) {
@@ -111,9 +120,11 @@ function createTestInjector(options?: {
111120 testInjector . register ( "identifier" , validDeviceIdentifier ) ;
112121 testInjector . register ( "logcatHelper" , LogcatHelperStub ) ;
113122 testInjector . register ( "androidProcessService" , AndroidProcessServiceStub ) ;
123+ testInjector . register ( "androidBundleToolService" , AndroidBundleToolServiceStub ) ;
124+ testInjector . register ( "fs" , FileSystemStub ) ;
114125 testInjector . register ( "httpClient" , { } ) ;
115126 testInjector . register ( "deviceLogProvider" , DeviceLogProviderStub ) ;
116- testInjector . register ( "hooksService" , { } ) ;
127+ testInjector . register ( "hooksService" , HooksServiceStub ) ;
117128 return testInjector ;
118129}
119130
@@ -140,6 +151,7 @@ describe("android-application-manager", () => {
140151 }
141152
142153 describe ( "startApplication" , ( ) => {
154+
143155 it ( "fires up the right application" , async ( ) => {
144156 setup ( ) ;
145157 for ( let i = 0 ; i < androidDebugBridge . getInputLength ( ) ; i ++ ) {
@@ -244,6 +256,55 @@ describe("android-application-manager", () => {
244256 } ) ;
245257 } ) ;
246258
259+ describe ( "installApplication" , ( ) => {
260+ afterEach ( function ( ) {
261+ androidDebugBridge . calledInstallApplication = false ;
262+ const bundleToolService = testInjector . resolve < AndroidBundleToolServiceStub > ( "androidBundleToolService" ) ;
263+ bundleToolService . isBuildApksCalled = false ;
264+ bundleToolService . isInstallApksCalled = false ;
265+ } ) ;
266+
267+ it ( "should install apk using adb" , async ( ) => {
268+ const bundleToolService = testInjector . resolve < AndroidBundleToolServiceStub > ( "androidBundleToolService" ) ;
269+
270+ await androidApplicationManager . installApplication ( "myApp.apk" ) ;
271+
272+ assert . isFalse ( bundleToolService . isBuildApksCalled ) ;
273+ assert . isFalse ( bundleToolService . isInstallApksCalled ) ;
274+ assert . isTrue ( androidDebugBridge . calledInstallApplication ) ;
275+ } ) ;
276+
277+ it ( "should install aab using bundletool" , async ( ) => {
278+ const bundleToolService = testInjector . resolve < AndroidBundleToolServiceStub > ( "androidBundleToolService" ) ;
279+
280+ await androidApplicationManager . installApplication ( "myApp.aab" ) ;
281+
282+ assert . isTrue ( bundleToolService . isBuildApksCalled ) ;
283+ assert . isTrue ( bundleToolService . isInstallApksCalled ) ;
284+ assert . isFalse ( androidDebugBridge . calledInstallApplication ) ;
285+ } ) ;
286+
287+ it ( "should skip aab build when already built" , async ( ) => {
288+ const fsStub = testInjector . resolve < FileSystemStub > ( "fs" ) ;
289+ const bundleToolService = testInjector . resolve < AndroidBundleToolServiceStub > ( "androidBundleToolService" ) ;
290+
291+ await androidApplicationManager . installApplication ( "myApp.aab" , "my.app" , validSigning ) ;
292+
293+ assert . isTrue ( bundleToolService . isBuildApksCalled ) ;
294+ assert . isTrue ( bundleToolService . isInstallApksCalled ) ;
295+ assert . isFalse ( androidDebugBridge . calledInstallApplication ) ;
296+
297+ fsStub . fsStatCache [ "myApp.aab" ] = fsStub . fsStatCache [ "myApp.apks" ] ;
298+ bundleToolService . isBuildApksCalled = false ;
299+ bundleToolService . isInstallApksCalled = false ;
300+ await androidApplicationManager . installApplication ( "myApp.aab" , "my.app" , validSigning ) ;
301+
302+ assert . isFalse ( bundleToolService . isBuildApksCalled ) ;
303+ assert . isTrue ( bundleToolService . isInstallApksCalled ) ;
304+ assert . isFalse ( androidDebugBridge . calledInstallApplication ) ;
305+ } ) ;
306+ } ) ;
307+
247308 describe ( "stopApplication" , ( ) => {
248309 it ( "should stop the logcat helper" , async ( ) => {
249310 setup ( ) ;
0 commit comments