1import rnFixture from '../../plugins/__tests__/fixtures/react-native-project'; 2import * as XML from '../../utils/XML'; 3import { getAllowBackup, getAllowBackupFromManifest, setAllowBackup } from '../AllowBackup'; 4import { AndroidManifest } from '../Manifest'; 5 6async function getFixtureManifestAsync() { 7 return (await XML.parseXMLAsync( 8 rnFixture['android/app/src/main/AndroidManifest.xml'] 9 )) as AndroidManifest; 10} 11 12describe('allowBackup', () => { 13 it(`defaults to true`, () => { 14 expect(getAllowBackup({})).toBe(true); 15 expect(getAllowBackup({ android: { allowBackup: false } })).toBe(false); 16 }); 17 18 it('sets the allowBackup property to true', async () => { 19 const androidManifestJsonUnaltered = await getFixtureManifestAsync(); 20 let androidManifestJson = await getFixtureManifestAsync(); 21 androidManifestJson = await setAllowBackup({}, { ...androidManifestJson }); 22 23 const result = getAllowBackupFromManifest(androidManifestJson); 24 // The fixture has `android:allowBackup="false"`, lets test that it did in fact get modified. 25 expect(getAllowBackupFromManifest(androidManifestJsonUnaltered)).not.toEqual(result); 26 27 // Sanity check `getAllowBackupFromManifest` works as expected. 28 expect(result).toBe(true); 29 }); 30 it('sets the allowBackup property to false', async () => { 31 const androidManifestJsonUnaltered = await getFixtureManifestAsync(); 32 let androidManifestJson = await getFixtureManifestAsync(); 33 androidManifestJson = await setAllowBackup( 34 { android: { allowBackup: false } }, 35 androidManifestJson 36 ); 37 38 const result = getAllowBackupFromManifest(androidManifestJson); 39 40 expect(androidManifestJsonUnaltered).toEqual(androidManifestJson); 41 expect(result).toBe(false); 42 }); 43}); 44