forked from RangerMauve/react-native-responsive-stylesheet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.js
199 lines (152 loc) · 3.79 KB
/
tests.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"use strict";
var tape = require("tape");
var mockRN = require("./mock-rn");
var ResponsiveStylesheet = require("./");
tape("ResponsiveStylesheet.create() should act as pass-through", function (t) {
t.plan(2);
var styles = {
foo: {
width: 420
}
};
var created = ResponsiveStylesheet.create(styles);
t.ok(created.$$created, "Got passed through StyleSheet.create");
t.equal(created.foo, styles.foo, "Didn't modify style");
});
tape("ResponsiveStylesheet.createOriented() should support empty styles", function (t) {
t.plan(1);
var styles = {};
ResponsiveStylesheet.createOriented(styles);
t.pass("Created without error");
});
tape("ResponsiveStylesheet.createOriented() should support landscape and portrait", function (t) {
var styles = {
landscape: {
foo: {
width: 420
}
},
portrait: {
foo: {
height: 420
},
bar: {
color: "red"
}
}
};
var created = ResponsiveStylesheet.createOriented(styles);
// Test for landscape
mockRN.setDimensions(100, 0);
t.equal(created.foo, styles.landscape.foo, "Loaded foo style from landscape styles");
t.notOk(created.bar, "Didn't load bar style");
// Test for portrait
mockRN.setDimensions(0, 100);
t.equal(created.foo, styles.portrait.foo, "Loaded foo style from portrait styles");
t.equal(created.bar, styles.portrait.bar, "Loaded bar style from portrait styles");
t.end();
});
tape("ResponsiveStylesheet.createOriented() should support defined orientations", function (t) {
var styles = {
landscape: {
foo: {
width: 420
}
}
};
var created = ResponsiveStylesheet.createOriented(styles);
mockRN.setDimensions(0, 100);
t.notOk(created.foo, "Foo was not defined");
t.end();
});
tape("ResponsiveStylesheet.createSized() should support min-width", function (t) {
var styles = {
100: {
foo: {
width: 100
},
bar: {
height: 100
}
},
10: {
foo: {
width: 10
}
}
};
var created = ResponsiveStylesheet.createSized("min-width", styles);
mockRN.setDimensions(0, 0);
t.deepEqual(created.foo, [], "Got empty array when no sizes matched");
t.deepEqual(created.bar, [], "Got empty array for other style");
mockRN.setDimensions(10, 0);
t.deepEqual(created.foo, [{
width: 10
}], "Got matching style");
t.deepEqual(created.bar, [], "Got empty array for other style");
mockRN.setDimensions(99, 0);
t.deepEqual(created.foo, [{
width: 10
}], "Check for off by one error");
mockRN.setDimensions(100, 0);
t.deepEqual(created.foo, [{
width: 10
}, {
width: 100
}], "Got expected styles in correct order");
t.deepEqual(created.bar, [{
height: 100
}], "Got expected other style");
t.end();
});
tape("ResponsiveStylesheet.createSized() should support max-height", function (t) {
var styles = {
100: {
foo: {
width: 100
},
bar: {
height: 100
}
},
10: {
foo: {
width: 10
}
}
};
var created = ResponsiveStylesheet.createSized("max-height", styles);
mockRN.setDimensions(0, 0);
t.deepEqual(created.foo, [{
width: 100
}, {
width: 10
}], "Got expected styles in correct order");
t.deepEqual(created.bar, [{
height: 100
}], "Got expected other style");
mockRN.setDimensions(0, 10);
t.deepEqual(created.foo, [{
width: 100
}, {
width: 10
}], "Got expected styles in correct order");
t.deepEqual(created.bar, [{
height: 100
}], "Got expected other style");
mockRN.setDimensions(0, 11);
t.deepEqual(created.foo, [{
width: 100
}], "Got only the largest");
t.deepEqual(created.bar, [{
height: 100
}], "Got expected other style");
mockRN.setDimensions(0, 99);
t.deepEqual(created.foo, [{
width: 100
}], "Check for off by one error");
mockRN.setDimensions(0, 200);
t.deepEqual(created.foo, [], "Got empty array when no sizes matched");
t.deepEqual(created.bar, [], "Got empty array for other style");
t.end();
});