Janic Duplessis 5 лет назад
Родитель
Сommit
e9c43a786a
2 измененных файлов: 95 добавлений и 11 удалений
  1. 56
    0
      src/__tests__/__snapshots__/index-test.tsx.snap
  2. 39
    11
      src/__tests__/index-test.tsx

+ 56
- 0
src/__tests__/__snapshots__/index-test.tsx.snap Просмотреть файл

@@ -138,3 +138,59 @@ exports[`SafeAreaProvider uses parent insets when available 1`] = `
138 138
   </RNCSafeAreaView>
139 139
 </RNCSafeAreaView>
140 140
 `;
141
+
142
+exports[`SafeAreaView can override padding styles 1`] = `
143
+<RNCSafeAreaView
144
+  onInsetsChange={[Function]}
145
+  style={
146
+    Object {
147
+      "flex": 1,
148
+    }
149
+  }
150
+>
151
+  <View
152
+    style={
153
+      Array [
154
+        Object {
155
+          "paddingBottom": 4,
156
+          "paddingLeft": 2,
157
+          "paddingRight": 3,
158
+          "paddingTop": 1,
159
+        },
160
+        Object {
161
+          "paddingTop": 0,
162
+        },
163
+      ]
164
+    }
165
+  >
166
+    <View />
167
+  </View>
168
+</RNCSafeAreaView>
169
+`;
170
+
171
+exports[`SafeAreaView renders 1`] = `
172
+<RNCSafeAreaView
173
+  onInsetsChange={[Function]}
174
+  style={
175
+    Object {
176
+      "flex": 1,
177
+    }
178
+  }
179
+>
180
+  <View
181
+    style={
182
+      Array [
183
+        Object {
184
+          "paddingBottom": 4,
185
+          "paddingLeft": 2,
186
+          "paddingRight": 3,
187
+          "paddingTop": 1,
188
+        },
189
+        undefined,
190
+      ]
191
+    }
192
+  >
193
+    <View />
194
+  </View>
195
+</RNCSafeAreaView>
196
+`;

+ 39
- 11
src/__tests__/index-test.tsx Просмотреть файл

@@ -1,7 +1,7 @@
1 1
 import * as React from 'react';
2 2
 import * as ReactTestRenderer from 'react-test-renderer';
3 3
 import { View } from 'react-native';
4
-import { SafeAreaProvider, useSafeArea } from '../index';
4
+import { SafeAreaProvider, SafeAreaView, useSafeArea } from '../index';
5 5
 import NativeSafeAreaView from '../NativeSafeAreaView';
6 6
 
7 7
 const PrintInsetsTestView = () => {
@@ -51,27 +51,23 @@ describe('SafeAreaProvider', () => {
51 51
     expect(component).toMatchSnapshot();
52 52
   });
53 53
 
54
-  it('uses parent insets when available', () => {
54
+  it('supports setting initial insets', () => {
55 55
     const component = ReactTestRenderer.create(
56 56
       <SafeAreaProvider
57 57
         initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
58 58
       >
59
-        <SafeAreaProvider>
60
-          <PrintInsetsTestView />
61
-        </SafeAreaProvider>
59
+        <PrintInsetsTestView />
62 60
       </SafeAreaProvider>,
63 61
     );
64 62
     expect(component).toMatchSnapshot();
65 63
   });
66 64
 
67
-  it('uses inner insets', () => {
65
+  it('uses parent insets when available', () => {
68 66
     const component = ReactTestRenderer.create(
69 67
       <SafeAreaProvider
70 68
         initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
71 69
       >
72
-        <SafeAreaProvider
73
-          initialSafeAreaInsets={{ top: 2, left: 3, right: 4, bottom: 5 }}
74
-        >
70
+        <SafeAreaProvider>
75 71
           <PrintInsetsTestView />
76 72
         </SafeAreaProvider>
77 73
       </SafeAreaProvider>,
@@ -79,12 +75,16 @@ describe('SafeAreaProvider', () => {
79 75
     expect(component).toMatchSnapshot();
80 76
   });
81 77
 
82
-  it('supports setting initial insets', () => {
78
+  it('uses inner insets', () => {
83 79
     const component = ReactTestRenderer.create(
84 80
       <SafeAreaProvider
85 81
         initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
86 82
       >
87
-        <PrintInsetsTestView />
83
+        <SafeAreaProvider
84
+          initialSafeAreaInsets={{ top: 2, left: 3, right: 4, bottom: 5 }}
85
+        >
86
+          <PrintInsetsTestView />
87
+        </SafeAreaProvider>
88 88
       </SafeAreaProvider>,
89 89
     );
90 90
     expect(component).toMatchSnapshot();
@@ -108,3 +108,31 @@ describe('SafeAreaProvider', () => {
108 108
     consoleErrorMock.mockRestore();
109 109
   });
110 110
 });
111
+
112
+describe('SafeAreaView', () => {
113
+  it('renders', () => {
114
+    const component = ReactTestRenderer.create(
115
+      <SafeAreaProvider
116
+        initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
117
+      >
118
+        <SafeAreaView>
119
+          <View />
120
+        </SafeAreaView>
121
+      </SafeAreaProvider>,
122
+    );
123
+    expect(component).toMatchSnapshot();
124
+  });
125
+
126
+  it('can override padding styles', () => {
127
+    const component = ReactTestRenderer.create(
128
+      <SafeAreaProvider
129
+        initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
130
+      >
131
+        <SafeAreaView style={{ paddingTop: 0 }}>
132
+          <View />
133
+        </SafeAreaView>
134
+      </SafeAreaProvider>,
135
+    );
136
+    expect(component).toMatchSnapshot();
137
+  });
138
+});