Skip to content

Commit 3b1ccec

Browse files
committed
chore: add unit tests for platform add
1 parent 855b6e1 commit 3b1ccec

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/platform-service.ts

+42
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,48 @@ describe('Platform Service Tests', () => {
302302

303303
await assertCorrectDataIsPassedToPacoteService(latestCompatibleVersion);
304304
});
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+
});
305347
});
306348
});
307349

0 commit comments

Comments
 (0)