|
| 1 | +import { describe, expect, it, jest } from '@jest/globals'; |
| 2 | +import { setFireBaseMessagingAndroidManifest } from '../src/android/setupFirebaseNotifationIcon'; |
| 3 | +import { ExpoConfig } from '@expo/config-types'; |
| 4 | +import expoConfigExample from './fixtures/expo-config-example'; |
| 5 | +import manifestApplicationExample from './fixtures/application-example'; |
| 6 | +import { ManifestApplication } from '@expo/config-plugins/build/android/Manifest'; |
| 7 | + |
| 8 | +describe('Config Plugin Android Tests', function () { |
| 9 | + it('applies changes to app/src/main/AndroidManifest.xml with color', async function () { |
| 10 | + const config: ExpoConfig = JSON.parse(JSON.stringify(expoConfigExample)); |
| 11 | + const manifestApplication: ManifestApplication = JSON.parse( |
| 12 | + JSON.stringify(manifestApplicationExample), |
| 13 | + ); |
| 14 | + setFireBaseMessagingAndroidManifest(config, manifestApplication); |
| 15 | + expect(manifestApplication['meta-data']).toContainEqual({ |
| 16 | + $: { |
| 17 | + 'android:name': 'com.google.firebase.messaging.default_notification_icon', |
| 18 | + 'android:resource': '@drawable/notification_icon', |
| 19 | + }, |
| 20 | + }); |
| 21 | + expect(manifestApplication['meta-data']).toContainEqual({ |
| 22 | + $: { |
| 23 | + 'android:name': 'com.google.firebase.messaging.default_notification_color', |
| 24 | + 'android:resource': '@color/notification_icon_color', |
| 25 | + 'tools:replace': 'android:resource', |
| 26 | + }, |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + it('applies changes to app/src/main/AndroidManifest.xml without color', async function () { |
| 31 | + const config = JSON.parse(JSON.stringify(expoConfigExample)); |
| 32 | + const manifestApplication: ManifestApplication = JSON.parse( |
| 33 | + JSON.stringify(manifestApplicationExample), |
| 34 | + ); |
| 35 | + config.notification!.color = undefined; |
| 36 | + setFireBaseMessagingAndroidManifest(config, manifestApplication); |
| 37 | + expect(manifestApplication['meta-data']).toContainEqual({ |
| 38 | + $: { |
| 39 | + 'android:name': 'com.google.firebase.messaging.default_notification_icon', |
| 40 | + 'android:resource': '@drawable/notification_icon', |
| 41 | + }, |
| 42 | + }); |
| 43 | + expect(manifestApplication['meta-data']).not.toContainEqual({ |
| 44 | + $: { |
| 45 | + 'android:name': 'com.google.firebase.messaging.default_notification_icon', |
| 46 | + 'android:resource': '@drawable/notification_icon_color', |
| 47 | + 'tools:replace': 'android:resource', |
| 48 | + }, |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('applies changes to app/src/main/AndroidManifest.xml without notification', async function () { |
| 53 | + const warnSpy = jest.spyOn(console, 'warn'); |
| 54 | + const config: ExpoConfig = JSON.parse(JSON.stringify(expoConfigExample)); |
| 55 | + const manifestApplication: ManifestApplication = JSON.parse( |
| 56 | + JSON.stringify(manifestApplicationExample), |
| 57 | + ); |
| 58 | + config.notification = undefined; |
| 59 | + setFireBaseMessagingAndroidManifest(config, manifestApplication); |
| 60 | + expect(warnSpy).toHaveBeenCalled(); |
| 61 | + warnSpy.mockRestore(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments