@@ -10,10 +10,16 @@ import { Logger } from '@salesforce/core';
1010import { TestContext } from '@salesforce/core/testSetup' ;
1111import { stubMethod } from '@salesforce/ts-sinon' ;
1212import {
13+ AndroidDevice ,
1314 AndroidDeviceManager ,
15+ AndroidOSType ,
16+ AppleDevice ,
1417 AppleDeviceManager ,
18+ AppleOSType ,
1519 CommonUtils ,
16- RequirementProcessor
20+ DeviceType ,
21+ RequirementProcessor ,
22+ Version
1723} from '@salesforce/lwc-dev-mobile-core' ;
1824import { expect } from 'chai' ;
1925import { Install } from '../../../../../../../../src/cli/commands/force/lightning/local/app/install.js' ;
@@ -48,7 +54,7 @@ describe('App Install Tests', () => {
4854 } ) ;
4955
5056 describe ( 'Android Platform Tests' , ( ) => {
51- it ( 'Should successfully install app on Android device' , async ( ) => {
57+ it ( 'Should successfully install app on Android device for cli mode ' , async ( ) => {
5258 const mockDevice = {
5359 boot : sinon . stub ( ) . resolves ( ) ,
5460 installApp : sinon . stub ( ) . resolves ( )
@@ -68,7 +74,39 @@ describe('App Install Tests', () => {
6874 expect ( loggerInfoMock . called ) . to . be . true ;
6975 } ) ;
7076
71- it ( 'Should handle Android device not found error' , async ( ) => {
77+ it ( 'Should successfully install app on Android device for JSON mode' , async ( ) => {
78+ const androidDevice = new AndroidDevice (
79+ androidTarget ,
80+ 'Test Android Device' ,
81+ DeviceType . mobile ,
82+ AndroidOSType . googleAPIs ,
83+ new Version ( 35 , 0 , 0 ) ,
84+ false
85+ ) ;
86+
87+ const bootMock = stubMethod ( $$ . SANDBOX , AndroidDevice . prototype , 'boot' ) ;
88+ bootMock . resolves ( ) ;
89+ const installAppMock = stubMethod ( $$ . SANDBOX , AndroidDevice . prototype , 'installApp' ) ;
90+ installAppMock . resolves ( ) ;
91+
92+ const getDeviceMock = stubMethod ( $$ . SANDBOX , AndroidDeviceManager . prototype , 'getDevice' ) ;
93+ getDeviceMock . resolves ( androidDevice ) ;
94+
95+ const result = await Install . run ( [ '-p' , 'android' , '-t' , androidTarget , '-a' , appBundlePath , '--json' ] ) ;
96+
97+ expect ( executeSetupMock . called ) . to . be . false ;
98+ expect ( getDeviceMock . calledWith ( androidTarget ) ) . to . be . true ;
99+ expect ( bootMock . calledWith ( true ) ) . to . be . true ;
100+ expect ( installAppMock . calledWith ( appBundlePath ) ) . to . be . true ;
101+ expect ( startCliActionMock . called ) . to . be . false ;
102+ expect ( stopCliActionMock . called ) . to . be . false ;
103+ expect ( loggerInfoMock . called ) . to . be . true ;
104+ expect ( result ) . to . have . property ( 'success' , true ) ;
105+ expect ( result ) . to . have . property ( 'device' ) ;
106+ expect ( result ) . to . have . property ( 'message' ) ;
107+ } ) ;
108+
109+ it ( 'Should handle Android device not found error for cli mode' , async ( ) => {
72110 const getDeviceMock = stubMethod ( $$ . SANDBOX , AndroidDeviceManager . prototype , 'getDevice' ) ;
73111 getDeviceMock . resolves ( null ) ;
74112
@@ -84,6 +122,22 @@ describe('App Install Tests', () => {
84122 }
85123 } ) ;
86124
125+ it ( 'Should handle Android device not found error for JSON mode' , async ( ) => {
126+ const getDeviceMock = stubMethod ( $$ . SANDBOX , AndroidDeviceManager . prototype , 'getDevice' ) ;
127+ getDeviceMock . resolves ( null ) ;
128+
129+ try {
130+ await Install . run ( [ '-p' , 'android' , '-t' , androidTarget , '-a' , appBundlePath , '--json' ] ) ;
131+ expect . fail ( 'Should have thrown an error' ) ;
132+ } catch ( error ) {
133+ expect ( executeSetupMock . called ) . to . be . false ;
134+ expect ( getDeviceMock . calledWith ( androidTarget ) ) . to . be . true ;
135+ expect ( startCliActionMock . called ) . to . be . false ;
136+ expect ( stopCliActionMock . called ) . to . be . false ;
137+ expect ( loggerWarnMock . called ) . to . be . true ;
138+ }
139+ } ) ;
140+
87141 it ( 'Should handle Android device boot failure' , async ( ) => {
88142 const mockDevice = {
89143 boot : sinon . stub ( ) . rejects ( new Error ( 'Boot failed' ) ) ,
@@ -146,7 +200,7 @@ describe('App Install Tests', () => {
146200 } ) ;
147201
148202 describe ( 'iOS Platform Tests' , ( ) => {
149- it ( 'Should successfully install app on iOS device' , async ( ) => {
203+ it ( 'Should successfully install app on iOS device cli mode ' , async ( ) => {
150204 const mockDevice = {
151205 boot : sinon . stub ( ) . resolves ( ) ,
152206 installApp : sinon . stub ( ) . resolves ( )
@@ -166,7 +220,38 @@ describe('App Install Tests', () => {
166220 expect ( loggerInfoMock . called ) . to . be . true ;
167221 } ) ;
168222
169- it ( 'Should handle iOS device not found error' , async ( ) => {
223+ it ( 'Should successfully install app on iOS device for JSON mode' , async ( ) => {
224+ const appleDevice = new AppleDevice (
225+ iosTarget ,
226+ 'Test iOS Device' ,
227+ DeviceType . mobile ,
228+ AppleOSType . iOS ,
229+ new Version ( 18 , 0 , 0 )
230+ ) ;
231+
232+ const bootMock = stubMethod ( $$ . SANDBOX , AppleDevice . prototype , 'boot' ) ;
233+ bootMock . resolves ( ) ;
234+ const installAppMock = stubMethod ( $$ . SANDBOX , AppleDevice . prototype , 'installApp' ) ;
235+ installAppMock . resolves ( ) ;
236+
237+ const getDeviceMock = stubMethod ( $$ . SANDBOX , AppleDeviceManager . prototype , 'getDevice' ) ;
238+ getDeviceMock . resolves ( appleDevice ) ;
239+
240+ const result = await Install . run ( [ '-p' , 'ios' , '-t' , iosTarget , '-a' , iosAppBundlePath , '--json' ] ) ;
241+
242+ expect ( executeSetupMock . called ) . to . be . false ;
243+ expect ( getDeviceMock . calledWith ( iosTarget ) ) . to . be . true ;
244+ expect ( bootMock . calledWith ( true ) ) . to . be . true ;
245+ expect ( installAppMock . calledWith ( iosAppBundlePath ) ) . to . be . true ;
246+ expect ( startCliActionMock . called ) . to . be . false ;
247+ expect ( stopCliActionMock . called ) . to . be . false ;
248+ expect ( loggerInfoMock . called ) . to . be . true ;
249+ expect ( result ) . to . have . property ( 'success' , true ) ;
250+ expect ( result ) . to . have . property ( 'device' ) ;
251+ expect ( result ) . to . have . property ( 'message' ) ;
252+ } ) ;
253+
254+ it ( 'Should handle iOS device not found error for cli mode' , async ( ) => {
170255 const getDeviceMock = stubMethod ( $$ . SANDBOX , AppleDeviceManager . prototype , 'getDevice' ) ;
171256 getDeviceMock . resolves ( null ) ;
172257
@@ -182,6 +267,22 @@ describe('App Install Tests', () => {
182267 }
183268 } ) ;
184269
270+ it ( 'Should handle iOS device not found error for JSON mode' , async ( ) => {
271+ const getDeviceMock = stubMethod ( $$ . SANDBOX , AppleDeviceManager . prototype , 'getDevice' ) ;
272+ getDeviceMock . resolves ( null ) ;
273+
274+ try {
275+ await Install . run ( [ '-p' , 'ios' , '-t' , iosTarget , '-a' , iosAppBundlePath , '--json' ] ) ;
276+ expect . fail ( 'Should have thrown an error' ) ;
277+ } catch ( error ) {
278+ expect ( executeSetupMock . called ) . to . be . false ;
279+ expect ( getDeviceMock . calledWith ( iosTarget ) ) . to . be . true ;
280+ expect ( startCliActionMock . called ) . to . be . false ;
281+ expect ( stopCliActionMock . called ) . to . be . false ;
282+ expect ( loggerWarnMock . called ) . to . be . true ;
283+ }
284+ } ) ;
285+
185286 it ( 'Should handle iOS device boot failure' , async ( ) => {
186287 const mockDevice = {
187288 boot : sinon . stub ( ) . rejects ( new Error ( 'Boot failed' ) ) ,
0 commit comments