Skip to content

Commit

Permalink
Add SafeAreaView tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Nov 4, 2019
1 parent 71763ac commit e9c43a7
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 11 deletions.
56 changes: 56 additions & 0 deletions src/__tests__/__snapshots__/index-test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,59 @@ exports[`SafeAreaProvider uses parent insets when available 1`] = `
</RNCSafeAreaView>
</RNCSafeAreaView>
`;

exports[`SafeAreaView can override padding styles 1`] = `
<RNCSafeAreaView
onInsetsChange={[Function]}
style={
Object {
"flex": 1,
}
}
>
<View
style={
Array [
Object {
"paddingBottom": 4,
"paddingLeft": 2,
"paddingRight": 3,
"paddingTop": 1,
},
Object {
"paddingTop": 0,
},
]
}
>
<View />
</View>
</RNCSafeAreaView>
`;

exports[`SafeAreaView renders 1`] = `
<RNCSafeAreaView
onInsetsChange={[Function]}
style={
Object {
"flex": 1,
}
}
>
<View
style={
Array [
Object {
"paddingBottom": 4,
"paddingLeft": 2,
"paddingRight": 3,
"paddingTop": 1,
},
undefined,
]
}
>
<View />
</View>
</RNCSafeAreaView>
`;
50 changes: 39 additions & 11 deletions src/__tests__/index-test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactTestRenderer from 'react-test-renderer';
import { View } from 'react-native';
import { SafeAreaProvider, useSafeArea } from '../index';
import { SafeAreaProvider, SafeAreaView, useSafeArea } from '../index';
import NativeSafeAreaView from '../NativeSafeAreaView';

const PrintInsetsTestView = () => {
Expand Down Expand Up @@ -51,40 +51,40 @@ describe('SafeAreaProvider', () => {
expect(component).toMatchSnapshot();
});

it('uses parent insets when available', () => {
it('supports setting initial insets', () => {
const component = ReactTestRenderer.create(
<SafeAreaProvider
initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
>
<SafeAreaProvider>
<PrintInsetsTestView />
</SafeAreaProvider>
<PrintInsetsTestView />
</SafeAreaProvider>,
);
expect(component).toMatchSnapshot();
});

it('uses inner insets', () => {
it('uses parent insets when available', () => {
const component = ReactTestRenderer.create(
<SafeAreaProvider
initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
>
<SafeAreaProvider
initialSafeAreaInsets={{ top: 2, left: 3, right: 4, bottom: 5 }}
>
<SafeAreaProvider>
<PrintInsetsTestView />
</SafeAreaProvider>
</SafeAreaProvider>,
);
expect(component).toMatchSnapshot();
});

it('supports setting initial insets', () => {
it('uses inner insets', () => {
const component = ReactTestRenderer.create(
<SafeAreaProvider
initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
>
<PrintInsetsTestView />
<SafeAreaProvider
initialSafeAreaInsets={{ top: 2, left: 3, right: 4, bottom: 5 }}
>
<PrintInsetsTestView />
</SafeAreaProvider>
</SafeAreaProvider>,
);
expect(component).toMatchSnapshot();
Expand All @@ -108,3 +108,31 @@ describe('SafeAreaProvider', () => {
consoleErrorMock.mockRestore();
});
});

describe('SafeAreaView', () => {
it('renders', () => {
const component = ReactTestRenderer.create(
<SafeAreaProvider
initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
>
<SafeAreaView>
<View />
</SafeAreaView>
</SafeAreaProvider>,
);
expect(component).toMatchSnapshot();
});

it('can override padding styles', () => {
const component = ReactTestRenderer.create(
<SafeAreaProvider
initialSafeAreaInsets={{ top: 1, left: 2, right: 3, bottom: 4 }}
>
<SafeAreaView style={{ paddingTop: 0 }}>
<View />
</SafeAreaView>
</SafeAreaProvider>,
);
expect(component).toMatchSnapshot();
});
});

0 comments on commit e9c43a7

Please sign in to comment.