Skip to content

Commit 60a55df

Browse files
author
Igor Canedo
committed
improving test coverage
1 parent e0cae0d commit 60a55df

File tree

9 files changed

+332
-14
lines changed

9 files changed

+332
-14
lines changed

sample/__tests__/components/BlockQuote.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ it('renders correctly with a blockquote', () => {
2222
inlineStyles={[]}
2323
entityRanges={[]}
2424
entityMap={{}}
25-
/>
25+
/>,
2626
).toJSON();
2727
expect(tree).toMatchSnapshot();
2828
});
2929

3030
it('renders null without a blockquote', () => {
3131
const tree = renderer.create(
32-
<BlockQuote />
32+
<BlockQuote />,
3333
).toJSON();
3434
expect(tree).toMatchSnapshot();
3535
});
@@ -53,7 +53,7 @@ it('extends a style with a customStyle', () => {
5353
entityRanges={[]}
5454
entityMap={{}}
5555
navigate={() => null}
56-
/>
56+
/>,
5757
).toJSON();
5858
expect(tree).toMatchSnapshot();
5959
});

sample/__tests__/components/DraftJsText.test.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ it('renders correctly with a text', () => {
2222
inlineStyles={[]}
2323
entityRanges={[]}
2424
entityMap={{}}
25-
/>
25+
/>,
2626
).toJSON();
2727
expect(tree).toMatchSnapshot();
2828
});
2929

3030
it('renders null without a text', () => {
3131
const tree = renderer.create(
32-
<DraftJsText />
32+
<DraftJsText />,
3333
).toJSON();
3434
expect(tree).toMatchSnapshot();
3535
});
@@ -53,7 +53,31 @@ it('extends a style with a customStyle', () => {
5353
entityRanges={[]}
5454
entityMap={{}}
5555
navigate={() => null}
56-
/>
56+
/>,
57+
).toJSON();
58+
expect(tree).toMatchSnapshot();
59+
});
60+
61+
it('extends a style with a customStyle from another type', () => {
62+
const text = 'Hello World';
63+
const customStyles = {
64+
blockquote: {
65+
fontSize: 18,
66+
fontWeight: 'normal',
67+
letterSpacing: -0.75,
68+
lineHeight: 32,
69+
},
70+
};
71+
const tree = renderer.create(
72+
<DraftJsText
73+
type="paragraph"
74+
text={text}
75+
customStyles={customStyles}
76+
inlineStyles={[]}
77+
entityRanges={[]}
78+
entityMap={{}}
79+
navigate={() => null}
80+
/>,
5781
).toJSON();
5882
expect(tree).toMatchSnapshot();
5983
});

sample/__tests__/components/OrderedListItem.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ it('renders correctly with a ordered-list-item', () => {
2222
inlineStyles={[]}
2323
entityRanges={[]}
2424
entityMap={{}}
25-
/>
25+
/>,
2626
).toJSON();
2727
expect(tree).toMatchSnapshot();
2828
});
2929

3030
it('renders null without a ordered-list-item', () => {
3131
const tree = renderer.create(
32-
<OrderedListItem />
32+
<OrderedListItem />,
3333
).toJSON();
3434
expect(tree).toMatchSnapshot();
3535
});
@@ -43,6 +43,12 @@ it('extends a style with a customStyle', () => {
4343
letterSpacing: -0.75,
4444
lineHeight: 32,
4545
},
46+
orderedListItemContainer: {
47+
flex: 2,
48+
},
49+
orderedListItemNumber: {
50+
fontSize: 14,
51+
},
4652
};
4753
const tree = renderer.create(
4854
<OrderedListItem
@@ -53,7 +59,7 @@ it('extends a style with a customStyle', () => {
5359
entityRanges={[]}
5460
entityMap={{}}
5561
navigate={() => null}
56-
/>
62+
/>,
5763
).toJSON();
5864
expect(tree).toMatchSnapshot();
5965
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2017, Globo.com (https://github.com/globocom)
3+
*
4+
* License: MIT
5+
*/
6+
7+
/* eslint-env jest */
8+
9+
import 'react-native';
10+
11+
import React from 'react';
12+
import renderer from 'react-test-renderer';
13+
14+
import TextStyled from '../../../src/components/TextStyled';
15+
16+
it('renders correctly without onPress', () => {
17+
const tree = renderer.create(
18+
<TextStyled
19+
type="paragraph"
20+
/>,
21+
).toJSON();
22+
expect(tree).toMatchSnapshot();
23+
});
24+
25+
it('renders correctly with onPress', () => {
26+
const tree = renderer.create(
27+
<TextStyled
28+
type="paragraph"
29+
onPress={() => null}
30+
/>,
31+
).toJSON();
32+
expect(tree).toMatchSnapshot();
33+
});
34+
35+
it('renders correctly with customStyles and multiple types', () => {
36+
const customStyles = {
37+
bold: {
38+
fontWeight: 'bold',
39+
},
40+
italic: {
41+
fontStyle: 'italic',
42+
},
43+
link: {
44+
textDecorationLine: 'underline',
45+
},
46+
underline: {
47+
textDecorationLine: 'underline',
48+
},
49+
strikethrough: {
50+
textDecorationLine: 'line-through',
51+
},
52+
};
53+
const typeArray = ['bold', 'italic'];
54+
const tree = renderer.create(
55+
<TextStyled
56+
type={typeArray}
57+
customStyles={customStyles}
58+
/>,
59+
).toJSON();
60+
expect(tree).toMatchSnapshot();
61+
});
62+
63+
it('renders correctly with customStyles and single type', () => {
64+
const customStyles = {
65+
bold: {
66+
fontWeight: 'bold',
67+
},
68+
};
69+
const type = 'bold';
70+
const tree = renderer.create(
71+
<TextStyled
72+
type={type}
73+
customStyles={customStyles}
74+
/>,
75+
).toJSON();
76+
expect(tree).toMatchSnapshot();
77+
});

sample/__tests__/components/UnorderedListItem.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ it('renders correctly with a unordered-list-item', () => {
2222
inlineStyles={[]}
2323
entityRanges={[]}
2424
entityMap={{}}
25-
/>
25+
/>,
2626
).toJSON();
2727
expect(tree).toMatchSnapshot();
2828
});
2929

3030
it('renders null without a unordered-list-item', () => {
3131
const tree = renderer.create(
32-
<UnorderedListItem />
32+
<UnorderedListItem />,
3333
).toJSON();
3434
expect(tree).toMatchSnapshot();
3535
});
@@ -53,7 +53,7 @@ it('extends a style with a customStyle', () => {
5353
entityRanges={[]}
5454
entityMap={{}}
5555
navigate={() => null}
56-
/>
56+
/>,
5757
).toJSON();
5858
expect(tree).toMatchSnapshot();
5959
});

sample/__tests__/components/__snapshots__/DraftJsText.test.js.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ exports[`extends a style with a customStyle 1`] = `
2525
</Text>
2626
`;
2727

28+
exports[`extends a style with a customStyle from another type 1`] = `
29+
<Text
30+
accessible={true}
31+
allowFontScaling={true}
32+
disabled={false}
33+
ellipsizeMode="tail"
34+
style={
35+
Array [
36+
Object {
37+
"fontSize": 14,
38+
"fontWeight": "normal",
39+
},
40+
undefined,
41+
]
42+
}
43+
>
44+
Hello World
45+
</Text>
46+
`;
47+
2848
exports[`renders correctly with a text 1`] = `
2949
<Text
3050
accessible={true}

sample/__tests__/components/__snapshots__/OrderedListItem.test.js.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ exports[`extends a style with a customStyle 1`] = `
99
"flex": 1,
1010
"flexDirection": "row",
1111
},
12-
undefined,
12+
Object {
13+
"flex": 2,
14+
},
1315
]
1416
}
1517
>
@@ -26,7 +28,9 @@ exports[`extends a style with a customStyle 1`] = `
2628
"fontWeight": "bold",
2729
"marginRight": 8,
2830
},
29-
undefined,
31+
Object {
32+
"fontSize": 14,
33+
},
3034
]
3135
}
3236
>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`renders correctly with customStyles and multiple types 1`] = `
4+
<Text
5+
accessible={true}
6+
allowFontScaling={true}
7+
disabled={false}
8+
ellipsizeMode="tail"
9+
style={
10+
Array [
11+
Object {
12+
"fontStyle": "italic",
13+
"fontWeight": "bold",
14+
},
15+
Object {
16+
"fontStyle": "italic",
17+
"fontWeight": "bold",
18+
},
19+
]
20+
}
21+
>
22+
23+
</Text>
24+
`;
25+
26+
exports[`renders correctly with customStyles and single type 1`] = `
27+
<Text
28+
accessible={true}
29+
allowFontScaling={true}
30+
disabled={false}
31+
ellipsizeMode="tail"
32+
style={
33+
Array [
34+
Object {
35+
"fontWeight": "bold",
36+
},
37+
Object {
38+
"fontWeight": "bold",
39+
},
40+
]
41+
}
42+
>
43+
44+
</Text>
45+
`;
46+
47+
exports[`renders correctly with onPress 1`] = `
48+
<Text
49+
accessible={true}
50+
allowFontScaling={true}
51+
disabled={false}
52+
ellipsizeMode="tail"
53+
onPress={[Function]}
54+
style={
55+
Array [
56+
undefined,
57+
]
58+
}
59+
>
60+
61+
</Text>
62+
`;
63+
64+
exports[`renders correctly without onPress 1`] = `
65+
<Text
66+
accessible={true}
67+
allowFontScaling={true}
68+
disabled={false}
69+
ellipsizeMode="tail"
70+
style={
71+
Array [
72+
undefined,
73+
]
74+
}
75+
>
76+
77+
</Text>
78+
`;

0 commit comments

Comments
 (0)