瀏覽代碼

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

Janic Duplessis 4 年之前
父節點
當前提交
c13fbc94a9
共有 3 個文件被更改,包括 35 次插入3 次删除
  1. 1
    1
      package.json
  2. 2
    1
      src/InitialWindowSafeAreaInsets.ts
  3. 32
    1
      src/__tests__/index-test.tsx

+ 1
- 1
package.json 查看文件

22
   "license": "MIT",
22
   "license": "MIT",
23
   "scripts": {
23
   "scripts": {
24
     "start": "react-native start",
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
     "validate:eslint": "eslint \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\"",
26
     "validate:eslint": "eslint \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\"",
27
     "validate:typescript": "tsc --project ./ --noEmit",
27
     "validate:typescript": "tsc --project ./ --noEmit",
28
     "validate:prettier": "prettier \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\" --check",
28
     "validate:prettier": "prettier \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\" --check",

+ 2
- 1
src/InitialWindowSafeAreaInsets.ts 查看文件

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

+ 32
- 1
src/__tests__/index-test.tsx 查看文件

1
 import * as React from 'react';
1
 import * as React from 'react';
2
 import * as ReactTestRenderer from 'react-test-renderer';
2
 import * as ReactTestRenderer from 'react-test-renderer';
3
-import { View } from 'react-native';
3
+import { View, UIManager } from 'react-native';
4
 import { SafeAreaProvider, SafeAreaView, useSafeArea } from '../index';
4
 import { SafeAreaProvider, SafeAreaView, useSafeArea } from '../index';
5
 import NativeSafeAreaView from '../NativeSafeAreaView';
5
 import NativeSafeAreaView from '../NativeSafeAreaView';
6
 
6
 
136
     expect(component).toMatchSnapshot();
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
+});