Browse Source

Run unit tests on CI, fix InitialWindowSafeAreaInsets with jest and add tests for it

Janic Duplessis 4 years ago
parent
commit
c13fbc94a9
3 changed files with 35 additions and 3 deletions
  1. 1
    1
      package.json
  2. 2
    1
      src/InitialWindowSafeAreaInsets.ts
  3. 32
    1
      src/__tests__/index-test.tsx

+ 1
- 1
package.json View File

@@ -22,7 +22,7 @@
22 22
   "license": "MIT",
23 23
   "scripts": {
24 24
     "start": "react-native start",
25
-    "test": "yarn validate:prettier && yarn validate:eslint && yarn validate:typescript",
25
+    "test": "yarn validate:prettier && yarn validate:eslint && yarn validate:typescript && yarn validate:jest",
26 26
     "validate:eslint": "eslint \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\"",
27 27
     "validate:typescript": "tsc --project ./ --noEmit",
28 28
     "validate:prettier": "prettier \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\" --check",

+ 2
- 1
src/InitialWindowSafeAreaInsets.ts View File

@@ -6,6 +6,7 @@ const RNCSafeAreaViewConfig = UIManager.getViewManagerConfig(
6 6
   // eslint-disable-next-line @typescript-eslint/no-explicit-any
7 7
 ) as any;
8 8
 
9
-export default (RNCSafeAreaViewConfig.Constants != null
9
+export default (RNCSafeAreaViewConfig != null &&
10
+RNCSafeAreaViewConfig.Constants != null
10 11
   ? RNCSafeAreaViewConfig.Constants.initialWindowSafeAreaInsets
11 12
   : null) as EdgeInsets | null;

+ 32
- 1
src/__tests__/index-test.tsx View File

@@ -1,6 +1,6 @@
1 1
 import * as React from 'react';
2 2
 import * as ReactTestRenderer from 'react-test-renderer';
3
-import { View } from 'react-native';
3
+import { View, UIManager } from 'react-native';
4 4
 import { SafeAreaProvider, SafeAreaView, useSafeArea } from '../index';
5 5
 import NativeSafeAreaView from '../NativeSafeAreaView';
6 6
 
@@ -136,3 +136,34 @@ describe('SafeAreaView', () => {
136 136
     expect(component).toMatchSnapshot();
137 137
   });
138 138
 });
139
+
140
+describe('initialWindowSafeAreaInsets', () => {
141
+  it('is null when no view config is available', () => {
142
+    jest.resetModules();
143
+    expect(require('../index').initialWindowSafeAreaInsets).toBe(null);
144
+  });
145
+
146
+  it('it uses the constant provided by the view config', () => {
147
+    jest.resetModules();
148
+    const testInsets = {
149
+      top: 20,
150
+      left: 0,
151
+      right: 0,
152
+      bottom: 0,
153
+    };
154
+    UIManager.getViewManagerConfig = jest.fn(name => {
155
+      if (name === 'RNCSafeAreaView') {
156
+        return {
157
+          Commands: {},
158
+          Constants: {
159
+            initialWindowSafeAreaInsets: testInsets,
160
+          },
161
+        };
162
+      }
163
+      return { Commands: {} };
164
+    });
165
+
166
+    expect(require('../index').initialWindowSafeAreaInsets).toBe(testInsets);
167
+    expect(UIManager.getViewManagerConfig).toBeCalledWith('RNCSafeAreaView');
168
+  });
169
+});