-
Notifications
You must be signed in to change notification settings - Fork 882
/
formSelectorsTest.js
145 lines (116 loc) · 3.56 KB
/
formSelectorsTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import selectorsFactory from "../../../src/redux/selectors/formSelectors";
// Test the selector factory
describe( selectorsFactory, () => {
it( "generates working selectors based on a path", () => {
const testSelectors = selectorsFactory( "just.another.path" );
const facebookData = { title: "facebooktitle" };
const twitterData = { title: "twittertitle" };
const testState = {
just: {
another: {
path: {
facebook: facebookData,
twitter: twitterData,
},
},
},
};
const expectedFacebook = testSelectors.getFacebookData( testState );
const expectedTwitter = testSelectors.getTwitterData( testState );
const expectedTitle = testSelectors.getTwitterTitle( testState );
expect( expectedFacebook ).toEqual( facebookData );
expect( expectedTwitter ).toEqual( twitterData );
expect( expectedTitle ).toEqual( "twittertitle" );
} );
} );
// Create the selectors.
const selectors = selectorsFactory( "socialPreviews" );
const state = {
socialPreviews: {
facebook: {
title: "Facebook Title",
description: "Facebook Description",
errors: [],
imageUrl: "https://facebook-image.png",
image: {
bytes: null,
type: "PNG",
height: null,
width: null,
url: "https://facebook-image.png",
id: null,
},
},
twitter: {
title: "Twitter Title",
description: "Twitter Description",
errors: [],
image: {
bytes: null,
type: "JPG",
height: null,
width: null,
url: "https://twitter-image.jpg",
id: null,
},
},
},
};
// FACEBOOK
describe( "selectors.getFacebookTitle", () => {
it( "selects the facebook title from the state", () => {
const actual = selectors.getFacebookTitle( state );
const expected = "Facebook Title";
expect( actual ).toEqual( expected );
} );
} );
describe( "selectors.getFacebookDescription", () => {
it( "selects the facebook description from the state", () => {
const actual = selectors.getFacebookDescription( state );
const expected = "Facebook Description";
expect( actual ).toEqual( expected );
} );
} );
describe( "selectors.getFacebookImageUrl", () => {
it( "selects the facebook image URL from the state", () => {
const actual = selectors.getFacebookImageUrl( state );
const expected = "https://facebook-image.png";
expect( actual ).toEqual( expected );
} );
} );
describe( "selectors.getFacebookImageType", () => {
it( "selects the facebook image Type from the state", () => {
const actual = selectors.getFacebookImageType( state );
const expected = "PNG";
expect( actual ).toEqual( expected );
} );
} );
// TWITTER
describe( "selectors.getTwitterTitle", () => {
it( "selects the twitter title from the state", () => {
const actual = selectors.getTwitterTitle( state );
const expected = "Twitter Title";
expect( actual ).toEqual( expected );
} );
} );
describe( "selectors.getTwitterDescription", () => {
it( "selects the twitter description from the state", () => {
const actual = selectors.getTwitterDescription( state );
const expected = "Twitter Description";
expect( actual ).toEqual( expected );
} );
} );
describe( "selectors.getTwitterImageUrl", () => {
it( "selects the twitter image URL from the state", () => {
const actual = selectors.getTwitterImageUrl( state );
const expected = "https://twitter-image.jpg";
expect( actual ).toEqual( expected );
} );
} );
describe( "selectors.getTwitterImageType", () => {
it( "selects the twitter image Type from the state", () => {
const actual = selectors.getTwitterImageType( state );
const expected = "JPG";
expect( actual ).toEqual( expected );
} );
} );