-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read main activity from
AndroidManifest.xml
automatically (#1967
) * feat: read main activity from `AndroidManifest.xml` automatically * test: update e2e snaphosts * test: add test scenario for main activity as class name * chore: types cleanup * chore: code cleaning * fix: tests
- Loading branch information
1 parent
bd496c4
commit 7342221
Showing
18 changed files
with
276 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/cli-platform-android/src/config/__fixtures__/files/AndroidManifest-className.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.some.example"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application android:name=".MainApplication"> | ||
<activity android:name="com.example.ExampleAppActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
20 changes: 20 additions & 0 deletions
20
...ges/cli-platform-android/src/config/__fixtures__/files/AndroidManifest-few-activities.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:name=".ExampleApplication"> | ||
<activity android:name=".ExampleAppActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> | ||
</intent-filter> | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
<data android:scheme="rntester" android:host="example" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/> | ||
</application> | ||
</queries> | ||
</manifest> |
14 changes: 11 additions & 3 deletions
14
packages/cli-platform-android/src/config/__fixtures__/files/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.some.example"> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.some.example"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application android:name=".MainApplication"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/cli-platform-android/src/config/__tests__/getMainActivity.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import findManifest from '../findManifest'; | ||
import getMainActivity from '../getMainActivity'; | ||
import * as mocks from '../__fixtures__/android'; | ||
|
||
jest.mock('path'); | ||
jest.mock('fs'); | ||
|
||
const fs = require('fs'); | ||
|
||
describe('android::getMainActivity', () => { | ||
beforeAll(() => { | ||
fs.__setMockFilesystem({ | ||
empty: {}, | ||
valid: { | ||
android: { | ||
app: mocks.valid, | ||
}, | ||
}, | ||
className: { | ||
android: { | ||
app: mocks.className, | ||
}, | ||
}, | ||
few: { | ||
android: { | ||
app: mocks.fewActivities, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('returns main activity if file exists in the folder', () => { | ||
const manifestPath = findManifest('/valid'); | ||
const manifest = getMainActivity(manifestPath || ''); | ||
expect(manifest).not.toBeNull(); | ||
expect(typeof manifest).toBe('string'); | ||
expect(manifest).toBe('.MainActivity'); | ||
}); | ||
|
||
it('returns main activity if there is few activities', () => { | ||
const manifestPath = findManifest('/few'); | ||
const mainActivity = getMainActivity(manifestPath || ''); | ||
expect(mainActivity).not.toBeNull(); | ||
expect(typeof mainActivity).toBe('string'); | ||
expect(mainActivity).toBe('.ExampleAppActivity'); | ||
}); | ||
|
||
it('returns main activity if it is class name', () => { | ||
const manifestPath = findManifest('/className'); | ||
const mainActivity = getMainActivity(manifestPath || ''); | ||
expect(mainActivity).not.toBeNull(); | ||
expect(typeof mainActivity).toBe('string'); | ||
expect(mainActivity).toBe('com.example.ExampleAppActivity'); | ||
}); | ||
|
||
it('returns null if file do not exist', () => { | ||
const fakeManifestPath = findManifest('/empty'); | ||
expect(getMainActivity(fakeManifestPath || '')).toBeNull(); | ||
}); | ||
}); |
Oops, something went wrong.