Skip to content

Commit ff0f0b1

Browse files
committed
chore: cleanup deeplink handling and fix tests
1 parent 59fb8b7 commit ff0f0b1

3 files changed

Lines changed: 30 additions & 31 deletions

File tree

app/components/UI/BrazeBanner/BrazeBanner.test.tsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ jest.mock('../../../core/Braze', () => ({
5151
}));
5252

5353
// ---------------------------------------------------------------------------
54-
// Mock: deeplink handler
54+
// Mock: SharedDeeplinkManager
5555
// ---------------------------------------------------------------------------
56-
const mockHandleDeeplink = jest.fn();
57-
jest.mock(
58-
'../../../core/DeeplinkManager/handlers/legacy/handleDeeplink',
59-
() => ({
60-
handleDeeplink: (...args: unknown[]) => mockHandleDeeplink(...args),
61-
}),
62-
);
56+
const mockParse = jest.fn().mockResolvedValue(undefined);
57+
jest.mock('../../../core/DeeplinkManager/DeeplinkManager', () => ({
58+
__esModule: true,
59+
default: {
60+
getInstance: () => ({ parse: mockParse }),
61+
},
62+
}));
6363

6464
// ---------------------------------------------------------------------------
6565
// Mock: isAllowedBrazeDeeplink — default to true; individual tests can override
@@ -149,7 +149,7 @@ function makeRawProperties(props: {
149149
body: { type: 'string', value: props.body ?? 'Default body text' },
150150
};
151151
if (props.bannerName !== undefined)
152-
result.banner_name = { type: 'string', value: props.bannerName };
152+
result.campaign_name = { type: 'string', value: props.bannerName };
153153
if (props.dismissable !== undefined)
154154
result.dismissable = { type: 'boolean', value: props.dismissable };
155155
if (props.deeplink !== undefined)
@@ -192,9 +192,9 @@ type BannerState = 'loading' | 'visible' | 'empty';
192192

193193
/**
194194
* Asserts the complete set of structural test IDs for a given banner state:
195-
* - `loading` → CONTAINER + SKELETON present; PRESSABLE + DISMISS_BUTTON absent
196-
* - `visible` → CONTAINER + PRESSABLE + DISMISS_BUTTON present; SKELETON absent
197-
* - `empty` → all four absent (component returns null)
195+
* - `loading` → CONTAINER present; PRESSABLE + DISMISS_BUTTON absent
196+
* - `visible` → CONTAINER + PRESSABLE + DISMISS_BUTTON present
197+
* - `empty` → all absent (component returns null)
198198
*/
199199
function assertBannerState(
200200
queryByTestId: (id: string) => unknown,
@@ -205,17 +205,14 @@ function assertBannerState(
205205

206206
if (state === 'loading') {
207207
present(BRAZE_BANNER_TEST_IDS.CONTAINER);
208-
present(BRAZE_BANNER_TEST_IDS.SKELETON);
209208
absent(BRAZE_BANNER_TEST_IDS.PRESSABLE);
210209
absent(BRAZE_BANNER_TEST_IDS.DISMISS_BUTTON);
211210
} else if (state === 'visible') {
212211
present(BRAZE_BANNER_TEST_IDS.CONTAINER);
213-
absent(BRAZE_BANNER_TEST_IDS.SKELETON);
214212
present(BRAZE_BANNER_TEST_IDS.PRESSABLE);
215213
present(BRAZE_BANNER_TEST_IDS.DISMISS_BUTTON);
216214
} else {
217215
absent(BRAZE_BANNER_TEST_IDS.CONTAINER);
218-
absent(BRAZE_BANNER_TEST_IDS.SKELETON);
219216
absent(BRAZE_BANNER_TEST_IDS.PRESSABLE);
220217
absent(BRAZE_BANNER_TEST_IDS.DISMISS_BUTTON);
221218
}
@@ -380,7 +377,7 @@ describe('BrazeBanner', () => {
380377

381378
expect(mockLogBrazeBannerImpression).toHaveBeenCalledWith(
382379
TEST_PLACEMENT_ID,
383-
{ banner_name: 'campaign-abc' },
380+
{ campaign_name: 'campaign-abc' },
384381
);
385382
expect(mockLogBrazeBannerImpression).toHaveBeenCalledTimes(1);
386383
});
@@ -403,7 +400,7 @@ describe('BrazeBanner', () => {
403400
});
404401

405402
describe('banner tap', () => {
406-
it('calls logBrazeBannerClick and handleDeeplink when banner has a deeplink', () => {
403+
it('calls logBrazeBannerClick and SharedDeeplinkManager.parse when banner has a deeplink', () => {
407404
const { getByTestId } = render(
408405
<BrazeBanner placementId={TEST_PLACEMENT_ID} />,
409406
);
@@ -412,9 +409,8 @@ describe('BrazeBanner', () => {
412409
fireEvent.press(getByTestId(BRAZE_BANNER_TEST_IDS.PRESSABLE));
413410

414411
expect(mockLogBrazeBannerClick).toHaveBeenCalledWith(TEST_PLACEMENT_ID);
415-
expect(mockHandleDeeplink).toHaveBeenCalledWith({
416-
uri: 'metamask://portfolio',
417-
source: 'braze',
412+
expect(mockParse).toHaveBeenCalledWith('metamask://portfolio', {
413+
origin: 'braze',
418414
});
419415
});
420416

@@ -426,11 +422,11 @@ describe('BrazeBanner', () => {
426422
fireBannerEvent([makeBanner()]);
427423
fireEvent.press(getByTestId(BRAZE_BANNER_TEST_IDS.PRESSABLE));
428424

429-
expect(mockHandleDeeplink).not.toHaveBeenCalled();
425+
expect(mockParse).not.toHaveBeenCalled();
430426
expect(mockLogBrazeBannerClick).not.toHaveBeenCalled();
431427
});
432428

433-
it('does not call handleDeeplink or logBrazeBannerClick when deeplink is rejected by the allowlist', () => {
429+
it('does not call SharedDeeplinkManager.parse or logBrazeBannerClick when deeplink is rejected by the allowlist', () => {
434430
mockIsAllowedBrazeDeeplink.mockReturnValueOnce(false);
435431

436432
const { getByTestId } = render(
@@ -442,7 +438,7 @@ describe('BrazeBanner', () => {
442438
]);
443439
fireEvent.press(getByTestId(BRAZE_BANNER_TEST_IDS.PRESSABLE));
444440

445-
expect(mockHandleDeeplink).not.toHaveBeenCalled();
441+
expect(mockParse).not.toHaveBeenCalled();
446442
expect(mockLogBrazeBannerClick).not.toHaveBeenCalled();
447443
});
448444

app/components/UI/BrazeBanner/BrazeBanner.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useCallback, useEffect } from 'react';
22
import { Pressable } from 'react-native';
3-
import { Box, Skeleton } from '@metamask/design-system-react-native';
3+
import { Box } from '@metamask/design-system-react-native';
44
import { useTailwind } from '@metamask/design-system-twrnc-preset';
5-
import { handleDeeplink } from '../../../core/DeeplinkManager/handlers/legacy/handleDeeplink';
5+
import SharedDeeplinkManager from '../../../core/DeeplinkManager/DeeplinkManager';
66
import AppConstants from '../../../core/AppConstants';
77
import Logger from '../../../util/Logger';
88
import {
@@ -61,10 +61,13 @@ const BrazeBanner = ({ placementId }: BrazeBannerProps) => {
6161
return;
6262
}
6363
logBrazeBannerClick(placementId);
64-
handleDeeplink({
65-
uri: deeplink,
66-
source: AppConstants.DEEPLINKS.ORIGIN_BRAZE,
67-
});
64+
SharedDeeplinkManager.getInstance()
65+
.parse(deeplink, {
66+
origin: AppConstants.DEEPLINKS.ORIGIN_BRAZE,
67+
})
68+
.catch((error) => {
69+
Logger.error(error, 'BrazeBanner: failed to handle deeplink');
70+
});
6871
}, [deeplink, placementId]);
6972

7073
if (status === 'empty' || status === 'dismissed') return null;

app/components/UI/BrazeBanner/useBrazeBanner.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function makeRawProperties(props: {
7777
}): Record<string, { type: string; value: unknown }> {
7878
const result: Record<string, { type: string; value: unknown }> = {};
7979
if (props.bannerName !== undefined)
80-
result.banner_name = { type: 'string', value: props.bannerName };
80+
result.campaign_name = { type: 'string', value: props.bannerName };
8181
if (props.dismissable !== undefined)
8282
result.dismissable = { type: 'boolean', value: props.dismissable };
8383
if (props.deeplink !== undefined)
@@ -330,7 +330,7 @@ describe('useBrazeBanner', () => {
330330
});
331331

332332
expect(mockDismissBrazeBanner).toHaveBeenCalledWith({
333-
banner_name: 'campaign-xyz',
333+
campaign_name: 'campaign-xyz',
334334
});
335335
});
336336

0 commit comments

Comments
 (0)