UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

49 lines (48 loc) 3.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); require('../../../../mocks/mockAll'); const path_1 = __importDefault(require("path")); const getProjectPath_1 = require("../../../../../utils/getProjectPath"); const importAndroidLaunchIcon_1 = require("../../../../../utils/upgrade/android/importAndroidLaunchIcon"); const mockFs_1 = require("../../../../mocks/mockFs"); describe('importAndroidLaunchIcon', () => { it('should get launch icon', async () => { mockFs_1.mockFs.writeFileSync('/oldProject/android/app/src/main/res/mipmap-any/ic_launcher.png', 'old image data'); mockFs_1.mockFs.writeFileSync('/oldProject/android/app/src/main/res/drawable-any/ic_notification.png', 'old image data'); mockFs_1.mockFs.writeFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android/app/src/main/res/mipmap-any/ic_launcher.png'), 'existing image data'); mockFs_1.mockFs.writeFileSync('/oldProject/android/app/src/main/AndroidManifest.xml', `android:label="@string/app_name" android:icon="@mipmap/test_ic_launcher" android:roundIcon="@mipmap/test_ic_launcher_round" android:allowBackup="false"`); mockFs_1.mockFs.writeFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android/app/src/main/AndroidManifest.xml'), `android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false"`); const importGetter = (0, importAndroidLaunchIcon_1.importAndroidLaunchIcon)('/oldProject'); expect(importGetter).toBeTruthy(); expect(importGetter.value).toEqual('@mipmap/test_ic_launcher'); await importGetter.apply(); expect(mockFs_1.mockFs.readFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android/app/src/main/AndroidManifest.xml'))).toContain('android:icon="@mipmap/test_ic_launcher"'); }); it('should remove roundIcon when does not exist in old project', async () => { mockFs_1.mockFs.writeFileSync('/oldProject/android/app/src/main/AndroidManifest.xml', 'android:icon="@mipmap/test_ic_launcher"'); mockFs_1.mockFs.writeFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android/app/src/main/AndroidManifest.xml'), `android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round"`); const importGetter = (0, importAndroidLaunchIcon_1.importAndroidLaunchIcon)('/oldProject'); await importGetter.apply(); expect(mockFs_1.mockFs.readFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android/app/src/main/AndroidManifest.xml'))).not.toContain('android:roundIcon="@mipmap/ic_launcher_round"'); }); it('should handle errors', () => { mockFs_1.mockFs.setReadPermission(false); const importGetter = (0, importAndroidLaunchIcon_1.importAndroidLaunchIcon)('/oldProject'); expect(importGetter).toBeNull(); }); it('should handle not finding icon', () => { mockFs_1.mockFs.writeFileSync('/oldProject/android/app/src/main/AndroidManifest.xml', 'random'); const importGetter = (0, importAndroidLaunchIcon_1.importAndroidLaunchIcon)('/oldProject'); expect(importGetter).toBeNull(); }); });