Browse Source

Add mock file

Mathieu Acthernoene 4 years ago
parent
commit
990641e726
4 changed files with 59 additions and 4 deletions
  1. 4
    0
      .eslintrc.js
  2. 50
    0
      mock.js
  3. 2
    1
      package.json
  4. 3
    3
      src/types.ts

+ 4
- 0
.eslintrc.js View File

@@ -4,6 +4,10 @@ const typescriptEslintPrettier = require('eslint-config-prettier/@typescript-esl
4 4
 module.exports = {
5 5
   extends: ['@react-native-community'],
6 6
   overrides: [
7
+    {
8
+      files: ['./mock.js'],
9
+      env: {jest: true},
10
+    },
7 11
     {
8 12
       files: ['*.ts', '*.tsx'],
9 13
       // Apply the recommended Typescript defaults and the prettier overrides to all Typescript files

+ 50
- 0
mock.js View File

@@ -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
+};

+ 2
- 1
package.json View File

@@ -25,7 +25,8 @@
25 25
     "/ios",
26 26
     "/src",
27 27
     "/lib",
28
-    "/*.podspec"
28
+    "/*.podspec",
29
+    "./mock.js"
29 30
   ],
30 31
   "scripts": {
31 32
     "start": "react-native start",

+ 3
- 3
src/types.ts View File

@@ -12,18 +12,18 @@ export type NotificationOption =
12 12
   | 'alert'
13 13
   | 'badge'
14 14
   | 'sound'
15
-  | 'criticalAlert'
16 15
   | 'carPlay'
16
+  | 'criticalAlert'
17 17
   | 'provisional';
18 18
 
19 19
 export interface NotificationSettings {
20 20
   alert?: boolean;
21 21
   badge?: boolean;
22 22
   sound?: boolean;
23
-  lockScreen?: boolean;
24 23
   carPlay?: boolean;
25
-  notificationCenter?: boolean;
26 24
   criticalAlert?: boolean;
25
+  lockScreen?: boolean;
26
+  notificationCenter?: boolean;
27 27
 }
28 28
 
29 29
 export interface NotificationsResponse {