-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[No QA][TS migration] Migrate react-native-permissions mock #35886
Changes from 3 commits
7114321
deea61e
98e87c6
989a2a7
32d775d
0e0399d
1fdb8fd
8121495
296bd53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,76 @@ | ||||||
import {PERMISSIONS, RESULTS} from 'react-native-permissions/dist/commonjs/permissions'; | ||||||
import type {ValueOf} from 'type-fest'; | ||||||
|
||||||
type Results = ValueOf<typeof RESULTS>; | ||||||
type ResultsCollection = Record<string, Results>; | ||||||
type NotificationSettings = Record<string, boolean>; | ||||||
|
||||||
const openLimitedPhotoLibraryPicker: jest.Mock<void> = jest.fn(() => {}); | ||||||
const openSettings: jest.Mock<void> = jest.fn(() => {}); | ||||||
const check: jest.Mock<Results> = jest.fn(() => RESULTS.GRANTED as string); | ||||||
const request: jest.Mock<Results> = jest.fn(() => RESULTS.GRANTED as string); | ||||||
const checkLocationAccuracy: jest.Mock<string> = jest.fn(() => 'full'); | ||||||
const requestLocationAccuracy: jest.Mock<string> = jest.fn(() => 'full'); | ||||||
|
||||||
const notificationOptions: string[] = ['alert', 'badge', 'sound', 'carPlay', 'criticalAlert', 'provisional']; | ||||||
|
||||||
const notificationSettings: NotificationSettings = { | ||||||
alert: true, | ||||||
badge: true, | ||||||
sound: true, | ||||||
carPlay: true, | ||||||
criticalAlert: true, | ||||||
provisional: true, | ||||||
lockScreen: true, | ||||||
notificationCenter: true, | ||||||
}; | ||||||
|
||||||
const checkNotifications: jest.Mock<{status: Results; settings: typeof notificationSettings}> = jest.fn(() => ({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract |
||||||
status: RESULTS.GRANTED, | ||||||
settings: notificationSettings, | ||||||
})); | ||||||
|
||||||
const requestNotifications: jest.Mock<{status: Results; settings: typeof notificationSettings}> = jest.fn((options: Record<string, string>) => ({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||||||
status: RESULTS.GRANTED, | ||||||
settings: Object.keys(options) | ||||||
.filter((option: string) => notificationOptions.includes(option)) | ||||||
.reduce((acc: ResultsCollection, option: string) => ({...acc, [option]: true}), { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
lockScreen: true, | ||||||
notificationCenter: true, | ||||||
}), | ||||||
})); | ||||||
|
||||||
const checkMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) => | ||||||
permissions.reduce( | ||||||
(acc: ResultsCollection, permission: string) => ({ | ||||||
...acc, | ||||||
[permission]: RESULTS.GRANTED, | ||||||
}), | ||||||
{}, | ||||||
), | ||||||
); | ||||||
|
||||||
const requestMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) => | ||||||
permissions.reduce( | ||||||
(acc: ResultsCollection, permission: string) => ({ | ||||||
...acc, | ||||||
[permission]: RESULTS.GRANTED, | ||||||
}), | ||||||
{}, | ||||||
), | ||||||
); | ||||||
|
||||||
export { | ||||||
PERMISSIONS, | ||||||
RESULTS, | ||||||
check, | ||||||
checkLocationAccuracy, | ||||||
checkMultiple, | ||||||
checkNotifications, | ||||||
openLimitedPhotoLibraryPicker, | ||||||
openSettings, | ||||||
request, | ||||||
requestLocationAccuracy, | ||||||
requestMultiple, | ||||||
requestNotifications, | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'react-native-permissions/dist/commonjs/permissions'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this declaration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blazejkustra This was not expected. I have updated the module declaration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, importing these from react-native-permissions directly are breaking the unit tests, this is the reason why I've added this module declaration.
I've tried that on this commit: 1fdb8fd but had to revert it