-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: notifications first round of tests (#10668)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR introduces smalls fixes on Notifications feature after the first round of tests. [x] - Error when enabling Notifications due embedded Snap Execution Environment. Changed to use external URL. [x] - Misalignment on UI components like Loading and Notifications Header. [x] - Bug `Cannot update a component while rendering a different component` due unnecessary usage of navigationsOptions on Notifications Details page. [x] - Fix async dependency on Notification Enable toggle & Alert. ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
- Loading branch information
1 parent
e7098a8
commit d05aeb1
Showing
13 changed files
with
229 additions
and
111 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
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,114 @@ | ||
import notifee, { | ||
NotificationSettings, | ||
AuthorizationStatus, | ||
IOSNotificationSetting, | ||
IOSNotificationSettings, | ||
AndroidNotificationSettings, | ||
AndroidNotificationSetting, | ||
} from '@notifee/react-native'; | ||
|
||
import { strings } from '../../../locales/i18n'; | ||
import { requestPushNotificationsPermission } from './pushPermissions'; | ||
|
||
jest.mock('@notifee/react-native', () => ({ | ||
getNotificationSettings: jest.fn(), | ||
AuthorizationStatus: { | ||
AUTHORIZED: 1, | ||
DENIED: 2, | ||
}, | ||
IOSNotificationSetting: { | ||
ENABLED: 1, | ||
DISABLED: 2, | ||
}, | ||
AndroidNotificationSetting: { | ||
ENABLED: 1, | ||
DISABLED: 2, | ||
}, | ||
})); | ||
|
||
jest.mock('../Logger', () => ({ | ||
error: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../../locales/i18n', () => ({ | ||
strings: jest.fn(), | ||
})); | ||
|
||
jest.mock('./pushPermissions', () => ({ | ||
...jest.requireActual('./pushPermissions'), | ||
AsyncAlert: jest.fn(), | ||
})); | ||
|
||
describe('requestPushNotificationsPermission', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const mockIOSSettings: IOSNotificationSettings = { | ||
authorizationStatus: AuthorizationStatus.AUTHORIZED, | ||
alert: IOSNotificationSetting.ENABLED, | ||
badge: IOSNotificationSetting.ENABLED, | ||
sound: IOSNotificationSetting.ENABLED, | ||
carPlay: IOSNotificationSetting.DISABLED, | ||
criticalAlert: IOSNotificationSetting.DISABLED, | ||
inAppNotificationSettings: IOSNotificationSetting.DISABLED, | ||
lockScreen: IOSNotificationSetting.ENABLED, | ||
notificationCenter: IOSNotificationSetting.ENABLED, | ||
showPreviews: 1, | ||
announcement: 1, | ||
}; | ||
|
||
const mockAndroidSettings: AndroidNotificationSettings = { | ||
alarm: AndroidNotificationSetting.ENABLED, | ||
}; | ||
|
||
it('should return notification settings if already authorized', async () => { | ||
const mockSettings: NotificationSettings = { | ||
authorizationStatus: AuthorizationStatus.AUTHORIZED, | ||
ios: mockIOSSettings, | ||
android: mockAndroidSettings, | ||
web: {}, | ||
}; | ||
|
||
(notifee.getNotificationSettings as jest.Mock).mockResolvedValue( | ||
mockSettings, | ||
); | ||
|
||
const result = await requestPushNotificationsPermission(); | ||
|
||
expect(notifee.getNotificationSettings).toHaveBeenCalledTimes(1); | ||
expect(result).toBe(mockSettings); | ||
}); | ||
|
||
it('should prompt the user with AsyncAlert and simulate a click', async () => { | ||
const mockSettings: NotificationSettings = { | ||
authorizationStatus: AuthorizationStatus.DENIED, | ||
ios: mockIOSSettings, | ||
android: mockAndroidSettings, | ||
web: {}, | ||
}; | ||
|
||
const updatedSettings: NotificationSettings = { | ||
...mockSettings, | ||
authorizationStatus: AuthorizationStatus.AUTHORIZED, | ||
}; | ||
|
||
(notifee.getNotificationSettings as jest.Mock) | ||
.mockResolvedValueOnce(mockSettings) | ||
.mockResolvedValueOnce(updatedSettings); | ||
(strings as jest.Mock).mockImplementation((key: string) => key); | ||
|
||
const mockAsyncAlert = jest.fn().mockResolvedValue(true); | ||
|
||
const result = await requestPushNotificationsPermission(mockAsyncAlert); | ||
|
||
expect(mockAsyncAlert).toHaveBeenCalledWith( | ||
'notifications.prompt_title', | ||
'notifications.prompt_desc', | ||
); | ||
expect(notifee.getNotificationSettings).toHaveBeenCalledTimes(2); | ||
expect(strings).toHaveBeenCalledWith('notifications.prompt_title'); | ||
expect(strings).toHaveBeenCalledWith('notifications.prompt_desc'); | ||
expect(result).toBe(updatedSettings); | ||
}); | ||
}); |
Oops, something went wrong.