@@ -302,6 +302,48 @@ describe('Platform Service Tests', () => {
302
302
303
303
await assertCorrectDataIsPassedToPacoteService ( latestCompatibleVersion ) ;
304
304
} ) ;
305
+
306
+ // Workflow: tns preview; tns platform add
307
+ it ( `should add platform when only .js part of the platform has already been added (nativePlatformStatus is ${ constants . NativePlatformStatus . requiresPlatformAdd } )` , async ( ) => {
308
+ const fs = testInjector . resolve ( "fs" ) ;
309
+ fs . exists = ( ) => true ;
310
+ const projectChangesService = testInjector . resolve ( "projectChangesService" ) ;
311
+ projectChangesService . getPrepareInfo = ( ) => ( { nativePlatformStatus : constants . NativePlatformStatus . requiresPlatformAdd } ) ;
312
+ const projectData = testInjector . resolve ( "projectData" ) ;
313
+ let isJsPlatformAdded = false ;
314
+ const preparePlatformJSService = testInjector . resolve ( "preparePlatformJSService" ) ;
315
+ preparePlatformJSService . addPlatform = async ( ) => isJsPlatformAdded = true ;
316
+ let isNativePlatformAdded = false ;
317
+ const preparePlatformNativeService = testInjector . resolve ( "preparePlatformNativeService" ) ;
318
+ preparePlatformNativeService . addPlatform = async ( ) => isNativePlatformAdded = true ;
319
+
320
+ await platformService . addPlatforms ( [ "android" ] , "" , projectData , config ) ;
321
+
322
+ assert . isTrue ( isJsPlatformAdded ) ;
323
+ assert . isTrue ( isNativePlatformAdded ) ;
324
+ } ) ;
325
+
326
+ // Workflow: tns platform add; tns platform add
327
+ it ( "shouldn't add platform when platforms folder exist and no .nsprepare file" , async ( ) => {
328
+ const fs = testInjector . resolve ( "fs" ) ;
329
+ fs . exists = ( ) => true ;
330
+ const projectChangesService = testInjector . resolve ( "projectChangesService" ) ;
331
+ projectChangesService . getPrepareInfo = ( ) => < any > null ;
332
+ const projectData = testInjector . resolve ( "projectData" ) ;
333
+
334
+ await assert . isRejected ( platformService . addPlatforms ( [ "android" ] , "" , projectData , config ) , "Platform android already added" ) ;
335
+ } ) ;
336
+
337
+ // Workflow: tns run; tns platform add
338
+ it ( `shouldn't add platform when both native and .js parts of the platform have already been added (nativePlatformStatus is ${ constants . NativePlatformStatus . alreadyPrepared } )` , async ( ) => {
339
+ const fs = testInjector . resolve ( "fs" ) ;
340
+ fs . exists = ( ) => true ;
341
+ const projectChangesService = testInjector . resolve ( "projectChangesService" ) ;
342
+ projectChangesService . getPrepareInfo = ( ) => ( { nativePlatformStatus : constants . NativePlatformStatus . alreadyPrepared } ) ;
343
+ const projectData = testInjector . resolve ( "projectData" ) ;
344
+
345
+ await assert . isRejected ( platformService . addPlatforms ( [ "android" ] , "" , projectData , config ) , "Platform android already added" ) ;
346
+ } ) ;
305
347
} ) ;
306
348
} ) ;
307
349
0 commit comments