Skip to content

Commit 990641e

Browse files
committed
Add mock file
1 parent ece99e3 commit 990641e

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const typescriptEslintPrettier = require('eslint-config-prettier/@typescript-esl
44
module.exports = {
55
extends: ['@react-native-community'],
66
overrides: [
7+
{
8+
files: ['./mock.js'],
9+
env: {jest: true},
10+
},
711
{
812
files: ['*.ts', '*.tsx'],
913
// Apply the recommended Typescript defaults and the prettier overrides to all Typescript files

mock.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const {PERMISSIONS, RESULTS} = require('./lib/commonjs/constants');
2+
export {PERMISSIONS, RESULTS};
3+
4+
export const openSettings = jest.fn(async () => {});
5+
export const check = jest.fn(async permission => RESULTS.GRANTED);
6+
export const request = jest.fn(async permission => RESULTS.GRANTED);
7+
8+
const notificationOptions = [
9+
'alert',
10+
'badge',
11+
'sound',
12+
'criticalAlert',
13+
'carPlay',
14+
// 'provisional', // excluded as it's not included in NotificationSettings
15+
];
16+
17+
const notificationSettings = {
18+
alert: true,
19+
badge: true,
20+
sound: true,
21+
carPlay: true,
22+
criticalAlert: true,
23+
lockScreen: true,
24+
notificationCenter: true,
25+
};
26+
27+
export const checkNotifications = jest.fn(async () => ({
28+
status: RESULTS.GRANTED,
29+
settings: notificationSettings,
30+
}));
31+
32+
export const requestNotifications = jest.fn(async options => ({
33+
status: RESULTS.GRANTED,
34+
settings: options
35+
.filter(option => notificationOptions.includes(option))
36+
.reduce((acc, option) => ({...acc, [option]: true}), {
37+
lockScreen: true,
38+
notificationCenter: true,
39+
}),
40+
}));
41+
42+
export default {
43+
PERMISSIONS,
44+
RESULTS,
45+
openSettings,
46+
check,
47+
request,
48+
checkNotifications,
49+
requestNotifications,
50+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"/ios",
2626
"/src",
2727
"/lib",
28-
"/*.podspec"
28+
"/*.podspec",
29+
"./mock.js"
2930
],
3031
"scripts": {
3132
"start": "react-native start",

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ export type NotificationOption =
1212
| 'alert'
1313
| 'badge'
1414
| 'sound'
15-
| 'criticalAlert'
1615
| 'carPlay'
16+
| 'criticalAlert'
1717
| 'provisional';
1818

1919
export interface NotificationSettings {
2020
alert?: boolean;
2121
badge?: boolean;
2222
sound?: boolean;
23-
lockScreen?: boolean;
2423
carPlay?: boolean;
25-
notificationCenter?: boolean;
2624
criticalAlert?: boolean;
25+
lockScreen?: boolean;
26+
notificationCenter?: boolean;
2727
}
2828

2929
export interface NotificationsResponse {

0 commit comments

Comments
 (0)