|
| 1 | +import { AndroidLocalBuildRequirements } from '../lib/local-build-requirements/android-local-build-requirements'; |
| 2 | +import { assert } from "chai"; |
| 3 | + |
| 4 | +interface ITestCaseData { |
| 5 | + testName: string; |
| 6 | + validateInfo?: NativeScriptDoctor.IWarning[]; |
| 7 | + validateJavacVersion?: NativeScriptDoctor.IWarning[]; |
| 8 | + getJavaCompilerVersion?: string; |
| 9 | + getAdbVersion?: string; |
| 10 | +} |
| 11 | + |
| 12 | +describe("androidLocalBuildRequirements", () => { |
| 13 | + describe("checkRequirements", () => { |
| 14 | + const setupTestCase = (results: ITestCaseData): AndroidLocalBuildRequirements => { |
| 15 | + const androidToolsInfo: NativeScriptDoctor.IAndroidToolsInfo = { |
| 16 | + validateInfo: (): NativeScriptDoctor.IWarning[] => results.validateInfo || [], |
| 17 | + validateAndroidHomeEnvVariable: (): NativeScriptDoctor.IWarning[] => [], |
| 18 | + getToolsInfo: (): NativeScriptDoctor.IAndroidToolsInfoData => null, |
| 19 | + validateJavacVersion: (installedJavaVersion: string, projectDir?: string, runtimeVersion?: string): NativeScriptDoctor.IWarning[] => results.validateJavacVersion || [], |
| 20 | + getPathToAdbFromAndroidHome: async (): Promise<string> => undefined, |
| 21 | + getPathToEmulatorExecutable: (): string => undefined |
| 22 | + }; |
| 23 | + |
| 24 | + const sysInfo: NativeScriptDoctor.ISysInfo = { |
| 25 | + getJavaCompilerVersion: async (): Promise<string> => results.hasOwnProperty("getJavaCompilerVersion") ? results.getJavaCompilerVersion : "8.0.0", |
| 26 | + getAdbVersion: async (pathToAdb?: string): Promise<string> => results.hasOwnProperty("getAdbVersion") ? results.getAdbVersion : "1.0.39", |
| 27 | + getXcodeVersion: async (): Promise<string> => undefined, |
| 28 | + getNodeVersion: async (): Promise<string> => undefined, |
| 29 | + getNpmVersion: async (): Promise<string> => undefined, |
| 30 | + getNodeGypVersion: async (): Promise<string> => undefined, |
| 31 | + getXcodeprojLocation: async (): Promise<string> => undefined, |
| 32 | + isITunesInstalled: async (): Promise<boolean> => false, |
| 33 | + getCocoaPodsVersion: async (): Promise<string> => undefined, |
| 34 | + getOs: async (): Promise<string> => undefined, |
| 35 | + isAndroidInstalled: async (): Promise<boolean> => false, |
| 36 | + getMonoVersion: async (): Promise<string> => undefined, |
| 37 | + getGitVersion: async (): Promise<string> => undefined, |
| 38 | + getGitPath: async (): Promise<string> => undefined, |
| 39 | + getGradleVersion: async (): Promise<string> => undefined, |
| 40 | + isCocoaPodsWorkingCorrectly: async (): Promise<boolean> => false, |
| 41 | + getNativeScriptCliVersion: async (): Promise<string> => undefined, |
| 42 | + getXcprojInfo: async (): Promise<NativeScriptDoctor.IXcprojInfo> => null, |
| 43 | + isCocoaPodsUpdateRequired: async (): Promise<boolean> => true, |
| 44 | + isAndroidSdkConfiguredCorrectly: async (): Promise<boolean> => true, |
| 45 | + getSysInfo: async (config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.ISysInfoData> => null, |
| 46 | + setShouldCacheSysInfo: (shouldCache: boolean): void => undefined |
| 47 | + }; |
| 48 | + |
| 49 | + const androidLocalBuildRequirements = new AndroidLocalBuildRequirements(androidToolsInfo, sysInfo); |
| 50 | + return androidLocalBuildRequirements; |
| 51 | + }; |
| 52 | + |
| 53 | + it("returns true when everything is setup correctly", async () => { |
| 54 | + const androidLocalBuildRequirements = setupTestCase({ testName: "returns true when everything is setup correctly" }); |
| 55 | + const result = await androidLocalBuildRequirements.checkRequirements(); |
| 56 | + assert.isTrue(result); |
| 57 | + }); |
| 58 | + |
| 59 | + describe("returns false", () => { |
| 60 | + const getWarnings = (): NativeScriptDoctor.IWarning[] => { |
| 61 | + return [{ |
| 62 | + warning: "warning", |
| 63 | + additionalInformation: "additional info", |
| 64 | + platforms: ["android"] |
| 65 | + }]; |
| 66 | + }; |
| 67 | + const testData: ITestCaseData[] = [ |
| 68 | + { |
| 69 | + testName: "when java is not installed", |
| 70 | + getJavaCompilerVersion: null |
| 71 | + }, |
| 72 | + { |
| 73 | + testName: "when java is installed, but it is not compatible for current project", |
| 74 | + validateJavacVersion: getWarnings() |
| 75 | + }, |
| 76 | + { |
| 77 | + testName: "when Android tools are not installed correctly", |
| 78 | + validateInfo: getWarnings() |
| 79 | + }, |
| 80 | + { |
| 81 | + testName: "when adb cannot be found", |
| 82 | + getAdbVersion: null |
| 83 | + } |
| 84 | + ]; |
| 85 | + |
| 86 | + testData.forEach(testCase => { |
| 87 | + it(testCase.testName, async () => { |
| 88 | + const androidLocalBuildRequirements = setupTestCase(testCase); |
| 89 | + const result = await androidLocalBuildRequirements.checkRequirements(); |
| 90 | + assert.isFalse(result); |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments