Skip to content

Commit 8b7a7fc

Browse files
authored
Merge pull request #7100 from StoDevX/noticeview-snapshot-tests
Add basic snapshot tests to `notice` module using react-test-renderer
2 parents 6ee123f + 647dbd4 commit 8b7a7fc

File tree

6 files changed

+545
-3
lines changed

6 files changed

+545
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import {describe, expect, test} from '@jest/globals'
3+
4+
import TestRenderer from 'react-test-renderer'
5+
import {LoadingView} from '../loading'
6+
7+
describe('LoadingView', () => {
8+
test('it displays "Loading…" when no text is supplied', () => {
9+
const tree = TestRenderer.create(<LoadingView />).toJSON()
10+
expect(tree).toMatchSnapshot()
11+
})
12+
13+
test('it displays text when text is supplied', () => {
14+
const tree = TestRenderer.create(<LoadingView text="foo bar" />).toJSON()
15+
expect(tree).toMatchSnapshot()
16+
})
17+
})
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react'
2+
import {StyleSheet} from 'react-native'
3+
import {describe, expect, it} from '@jest/globals'
4+
5+
import TestRenderer from 'react-test-renderer'
6+
import {NoticeView} from '../notice'
7+
8+
describe('NoticeView', () => {
9+
describe('when given no text to display', () => {
10+
it('displays "Notice!" as its text', () => {
11+
const tree = TestRenderer.create(<NoticeView />).toJSON()
12+
expect(tree).toMatchSnapshot()
13+
})
14+
})
15+
16+
describe('when given text to display', () => {
17+
it('displays the text', () => {
18+
const tree = TestRenderer.create(<NoticeView text="foo bar" />).toJSON()
19+
expect(tree).toMatchSnapshot()
20+
})
21+
})
22+
23+
describe('when given view style overrides', () => {
24+
it('applies view style overrides', () => {
25+
const styleOverride = StyleSheet.create({
26+
view: {
27+
padding: 31,
28+
},
29+
})
30+
const tree = TestRenderer.create(
31+
<NoticeView style={styleOverride.view} text="foo bar" />,
32+
).toJSON()
33+
expect(tree).toMatchSnapshot()
34+
})
35+
})
36+
37+
describe('when instructed to display a spinner', () => {
38+
it('displays a spinner', () => {
39+
const tree = TestRenderer.create(
40+
<NoticeView spinner={true} text="foo bar" />,
41+
).toJSON()
42+
expect(tree).toMatchSnapshot()
43+
})
44+
})
45+
46+
describe('when header text is given', () => {
47+
it('displays the header text', () => {
48+
const tree = TestRenderer.create(
49+
<NoticeView header="blammo" text="foo bar" />,
50+
).toJSON()
51+
expect(tree).toMatchSnapshot()
52+
})
53+
})
54+
55+
describe('when buttonText is given', () => {
56+
it('displays a button with the buttonText in its title', () => {
57+
const tree = TestRenderer.create(
58+
<NoticeView buttonText="button text" text="foo bar" />,
59+
).toJSON()
60+
expect(tree).toMatchSnapshot()
61+
})
62+
})
63+
})
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`LoadingView it displays "Loading…" when no text is supplied 1`] = `
4+
<View
5+
style={
6+
[
7+
{
8+
"alignItems": "center",
9+
"backgroundColor": {
10+
"semantic": [
11+
"systemBackground",
12+
],
13+
},
14+
"flex": 1,
15+
"justifyContent": "center",
16+
"paddingHorizontal": 30,
17+
},
18+
undefined,
19+
]
20+
}
21+
>
22+
<ActivityIndicator
23+
style={
24+
{
25+
"alignItems": "center",
26+
"justifyContent": "center",
27+
"padding": 8,
28+
}
29+
}
30+
/>
31+
<Text
32+
selectable={true}
33+
style={
34+
[
35+
{
36+
"color": {
37+
"semantic": [
38+
"label",
39+
],
40+
},
41+
"textAlign": "center",
42+
},
43+
undefined,
44+
]
45+
}
46+
>
47+
Loading…
48+
</Text>
49+
</View>
50+
`;
51+
52+
exports[`LoadingView it displays text when text is supplied 1`] = `
53+
<View
54+
style={
55+
[
56+
{
57+
"alignItems": "center",
58+
"backgroundColor": {
59+
"semantic": [
60+
"systemBackground",
61+
],
62+
},
63+
"flex": 1,
64+
"justifyContent": "center",
65+
"paddingHorizontal": 30,
66+
},
67+
undefined,
68+
]
69+
}
70+
>
71+
<ActivityIndicator
72+
style={
73+
{
74+
"alignItems": "center",
75+
"justifyContent": "center",
76+
"padding": 8,
77+
}
78+
}
79+
/>
80+
<Text
81+
selectable={true}
82+
style={
83+
[
84+
{
85+
"color": {
86+
"semantic": [
87+
"label",
88+
],
89+
},
90+
"textAlign": "center",
91+
},
92+
undefined,
93+
]
94+
}
95+
>
96+
foo bar
97+
</Text>
98+
</View>
99+
`;

0 commit comments

Comments
 (0)