forked from FormidableLabs/radium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
radium-test.js
181 lines (160 loc) · 4.85 KB
/
radium-test.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
'use strict';
const React = require('react');
const Radium = require('..');
const render = require('./utils').render;
describe('Radium blackbox SSR tests', () => {
describe('inline prefixes', () => {
let Wrapped;
beforeEach(() => {
class Composed extends React.Component {
render() {
return React.createElement('div', {
style: {
display: 'flex'
}
});
}
}
Wrapped = Radium(Composed);
});
// Regression test: https://github.com/FormidableLabs/radium/issues/958
it('handles no user agent', () => {
const rendered = render(Wrapped);
expect(rendered).to.contain(
'style="display:-webkit-box;display:-moz-box;display:-ms-flexbox;' +
'display:-webkit-flex;display:flex"'
);
});
// Regression test: https://github.com/FormidableLabs/radium/issues/958
it('handles non-matching user agent', () => {
const rendered = render(Wrapped, {
userAgent: 'testy-mctestface'
});
expect(rendered).to.contain(
'style="display:-webkit-box;display:-moz-box;display:-ms-flexbox;' +
'display:-webkit-flex;display:flex"'
);
});
it('handles matching user agent', () => {
const rendered = render(Wrapped, {
userAgent:
'Mozilla/5.0 (iPad; CPU OS 8_0_0 like Mac OS X) AppleWebKit/600.1.4' +
' (KHTML, like Gecko) CriOS/47.0.2526.107 Mobile/12H321 Safari/600.1.4'
});
expect(rendered).to.contain('style="display:-webkit-flex"');
});
});
describe('keyframes', () => {
let getComponent;
beforeEach(() => {
const testKeyFrames = Radium.keyframes(
{
'0%': {width: '10%'},
'50%': {width: '50%'},
'100%': {width: '10%'}
},
'test'
);
const style = {
animation: 'x 3s ease 0s infinite',
animationName: testKeyFrames,
background: 'blue'
};
getComponent = radiumConfig => {
class Component extends React.Component {
render() {
return React.createElement(
Radium.StyleRoot,
{radiumConfig},
React.createElement('div', {
style
})
);
}
}
return Component;
};
});
// Regression test: https://github.com/FormidableLabs/radium/issues/973
it('handles no user agent', () => {
const rendered = render(getComponent());
expect(rendered).to.contain('<style>@keyframes test-radium-animation-');
});
// Regression test: https://github.com/FormidableLabs/radium/issues/973
it('handles non-matching user agent', () => {
const rendered = render(
getComponent({
userAgent: 'testy-mctestface'
})
);
expect(rendered).to.contain('<style>@keyframes test-radium-animation-');
});
it('handles matching user agent', () => {
const rendered = render(
getComponent({
userAgent:
'Mozilla/5.0 (iPad; CPU OS 8_0_0 like Mac OS X) AppleWebKit/600.1.4' +
' (KHTML, like Gecko) CriOS/47.0.2526.107 Mobile/12H321 Safari/600.1.4'
})
);
expect(rendered).to.contain(
'<style>@-webkit-keyframes test-radium-animation-'
);
});
});
describe('render scenarios', () => {
// Regression test: https://github.com/FormidableLabs/radium/issues/950
it('handles rendered child array', () => {
class Composed extends React.Component {
render() {
return [
React.createElement('div', {
key: 0,
style: {
color: 'blue'
}
}),
React.createElement('div', {
key: 1,
style: {
color: 'red'
}
})
];
}
}
const rendered = render(Radium(Composed));
expect(rendered).to.contain(
'<div style="color:blue" data-radium="true"></div>' +
'<div style="color:red" data-radium="true"></div>'
);
});
it('handles rendered Fragments', () => {
class Composed extends React.Component {
render() {
return React.createElement(React.Fragment, {
children: [
React.createElement('div', {
key: 0,
style: {
color: 'blue'
}
}),
React.createElement('div', {
key: 1,
style: {
color: 'red'
}
})
]
});
}
}
const rendered = render(Radium(Composed));
expect(rendered).to.contain(
'<div style="color:blue" data-radium="true"></div>' +
'<div style="color:red" data-radium="true"></div>'
);
});
});
});