1
1
import { AndroidApplicationManager } from "../../mobile/android/android-application-manager" ;
2
2
import { Yok } from "../../yok" ;
3
3
import { 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" ;
5
6
const invalidIdentifier = "invalid.identifier" ;
6
7
const validDeviceIdentifier = "device.identifier" ;
7
8
const validIdentifier = "org.nativescript.testApp" ;
8
9
const validStartOptions = { appId : validIdentifier , projectName : "" , projectDir : "" } ;
10
+ const validSigning : any = { keyStoreAlias : "string" , keyStorePath : "string" , keyStoreAliasPassword : "string" , keyStorePassword : "string" } ;
9
11
10
12
class AndroidDebugBridgeStub {
13
+ public calledInstallApplication = false ;
11
14
public calledStopApplication = false ;
12
15
public startedWithActivityManager = false ;
13
16
public validIdentifierPassed = false ;
@@ -42,6 +45,12 @@ class AndroidDebugBridgeStub {
42
45
frontOfTask=true task=TaskRecord{fe592ac #449 A=org.nativescript.testApp U=0 StackId=1 sz=1}"
43
46
] ;
44
47
48
+ public async executeCommand ( args : string [ ] , options ?: any ) : Promise < any > {
49
+ if ( args [ 0 ] === "install" ) {
50
+ this . calledInstallApplication = true ;
51
+ }
52
+ }
53
+
45
54
public async executeShellCommand ( args : string [ ] ) : Promise < any > {
46
55
if ( args && args . length > 0 ) {
47
56
if ( args [ 0 ] . startsWith ( "cat" ) ) {
@@ -111,9 +120,11 @@ function createTestInjector(options?: {
111
120
testInjector . register ( "identifier" , validDeviceIdentifier ) ;
112
121
testInjector . register ( "logcatHelper" , LogcatHelperStub ) ;
113
122
testInjector . register ( "androidProcessService" , AndroidProcessServiceStub ) ;
123
+ testInjector . register ( "androidBundleToolService" , AndroidBundleToolServiceStub ) ;
124
+ testInjector . register ( "fs" , FileSystemStub ) ;
114
125
testInjector . register ( "httpClient" , { } ) ;
115
126
testInjector . register ( "deviceLogProvider" , DeviceLogProviderStub ) ;
116
- testInjector . register ( "hooksService" , { } ) ;
127
+ testInjector . register ( "hooksService" , HooksServiceStub ) ;
117
128
return testInjector ;
118
129
}
119
130
@@ -140,6 +151,7 @@ describe("android-application-manager", () => {
140
151
}
141
152
142
153
describe ( "startApplication" , ( ) => {
154
+
143
155
it ( "fires up the right application" , async ( ) => {
144
156
setup ( ) ;
145
157
for ( let i = 0 ; i < androidDebugBridge . getInputLength ( ) ; i ++ ) {
@@ -244,6 +256,55 @@ describe("android-application-manager", () => {
244
256
} ) ;
245
257
} ) ;
246
258
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
+
247
308
describe ( "stopApplication" , ( ) => {
248
309
it ( "should stop the logcat helper" , async ( ) => {
249
310
setup ( ) ;
0 commit comments