Skip to content

Commit c069286

Browse files
authored
Merge pull request #31 from Iterable/MOB-11402-add-tests-for-withdeeplinks
[MOB-11402] add-tests-for-withdeeplinks
2 parents 0de9d36 + 3f98b27 commit c069286

File tree

4 files changed

+78
-15
lines changed

4 files changed

+78
-15
lines changed

plugin/__mocks__/testUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export const createMockPlistConfig = (
9797
modResults,
9898
});
9999

100+
/**
101+
* Creates a mock config object for the Android manifest file.
102+
* @param modResults - The results of the module to create the mock config for.
103+
* @returns A mock config object for the Android manifest file.
104+
*/
100105
export const createMockManifestConfig = (
101106
modResults: Record<string, any> = {}
102107
): ExportedConfigWithProps<Record<string, any>> => ({
@@ -115,3 +120,16 @@ export const createMockAndroidManifest = (): Record<string, any> => ({
115120
],
116121
},
117122
});
123+
124+
/**
125+
* Creates a test config object. This should be passed as the first argument
126+
* to the config plugin functions.
127+
* @returns A test config object.
128+
*/
129+
export const createTestConfig = (): ConfigWithMods => ({
130+
name: 'TestApp',
131+
slug: 'test-app',
132+
ios: { infoPlist: {}, entitlements: {} },
133+
android: { googleServicesFile: './__mocks__/google-services.json' },
134+
_internal: { projectRoot: process.cwd() },
135+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
createMockAndroidManifest,
3+
createMockManifestConfig,
4+
createTestConfig,
5+
type ConfigWithMods,
6+
type WithIterableResult,
7+
} from '../__mocks__/testUtils';
8+
import withIterable from '../src/withIterable';
9+
import { type ConfigPluginProps } from '../src/withIterable.types';
10+
11+
describe('withDeepLinks', () => {
12+
it('should set the launch mode to singleTask if activities exist', async () => {
13+
const config = createTestConfig();
14+
const props: ConfigPluginProps = {};
15+
const result = withIterable(config, props) as WithIterableResult;
16+
const modifiedManifest = await result.mods.android.manifest(
17+
createMockManifestConfig(createMockAndroidManifest())
18+
);
19+
const manifest = modifiedManifest.modResults.manifest;
20+
expect(manifest.application[0].activity).toEqual(
21+
expect.arrayContaining([
22+
expect.objectContaining({
23+
$: {
24+
'android:launchMode': 'singleTask',
25+
},
26+
}),
27+
])
28+
);
29+
});
30+
31+
it('should not set the launch mode to singleTask if activities do not exist', async () => {
32+
const config = createTestConfig();
33+
const props: ConfigPluginProps = {};
34+
const result = withIterable(config, props) as WithIterableResult;
35+
const modifiedManifest = await result.mods.android.manifest(
36+
createMockManifestConfig({
37+
manifest: {
38+
application: [
39+
{ $: { 'android:name': '.MainApplication' }, activity: [] },
40+
],
41+
},
42+
})
43+
);
44+
const manifest = modifiedManifest.modResults.manifest;
45+
expect(manifest.application[0].activity).not.toEqual(
46+
expect.arrayContaining([
47+
expect.objectContaining({
48+
$: {
49+
'android:launchMode': 'singleTask',
50+
},
51+
}),
52+
])
53+
);
54+
});
55+
});

plugin/__tests__/withIterable.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createTestConfig } from '../__mocks__/testUtils';
12
import withIterable from '../src/withIterable';
23
import { ConfigPluginProps } from '../src/withIterable.types';
34
import { withStoreConfigValues } from '../src/withStoreConfigValues';
@@ -19,12 +20,6 @@ jest.mock('../src/withDeepLinks', () => ({
1920
}));
2021

2122
describe('withIterable', () => {
22-
const mockConfig = {
23-
name: 'TestApp',
24-
slug: 'test-app',
25-
_internal: { projectRoot: process.cwd() },
26-
};
27-
2823
beforeEach(() => {
2924
jest.clearAllMocks();
3025
});
@@ -35,6 +30,7 @@ describe('withIterable', () => {
3530
});
3631

3732
it('should set default values when no props are provided', () => {
33+
const mockConfig = createTestConfig();
3834
// @ts-expect-error
3935
const result = withIterable(mockConfig);
4036

@@ -48,6 +44,7 @@ describe('withIterable', () => {
4844
});
4945

5046
it('should use provided props when available', () => {
47+
const mockConfig = createTestConfig();
5148
const props: ConfigPluginProps = {
5249
appEnvironment: 'production',
5350
autoConfigurePushNotifications: false,
@@ -62,6 +59,7 @@ describe('withIterable', () => {
6259
});
6360

6461
it('should handle partial props', () => {
62+
const mockConfig = createTestConfig();
6563
const props: ConfigPluginProps = {
6664
appEnvironment: 'production',
6765
// Other props should use defaults

plugin/__tests__/withStoreConfigValues.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@ import {
44
createMockAndroidManifest,
55
createMockManifestConfig,
66
createMockPlistConfig,
7-
type ConfigWithMods,
7+
createTestConfig,
88
type WithIterableResult,
99
} from '../__mocks__/testUtils';
1010
import withIterable from '../src/withIterable';
1111
import { type ConfigPluginProps } from '../src/withIterable.types';
1212

13-
const createTestConfig = (): ConfigWithMods => ({
14-
name: 'TestApp',
15-
slug: 'test-app',
16-
ios: { infoPlist: {}, entitlements: {} },
17-
android: { googleServicesFile: './__mocks__/google-services.json' },
18-
_internal: { projectRoot: process.cwd() },
19-
});
20-
2113
describe('withStoreConfigValues', () => {
2214
it('should store `ITERABLE_REQUEST_PERMISSIONS_FOR_PUSH_NOTIFICATIONS` in Info.plist', async () => {
2315
const config = createTestConfig();

0 commit comments

Comments
 (0)