Repository navigation
Expand file tree
/
Copy pathsmoke.js
More file actions
185 lines (141 loc) · 5.79 KB
/
Copy pathsmoke.js
File metadata and controls
185 lines (141 loc) · 5.79 KB
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
/*global describe, it, expect, React, ReactIntl*/
describe('React Intl', function () {
var IntlMixin = ReactIntl.IntlMixin;
var FormattedNumber = React.createFactory(ReactIntl.FormattedNumber);
var FormattedDate = React.createFactory(ReactIntl.FormattedDate);
var FormattedTime = React.createFactory(ReactIntl.FormattedTime);
var FormattedRelative = React.createFactory(ReactIntl.FormattedRelative);
var FormattedMessage = React.createFactory(ReactIntl.FormattedMessage);
var FormattedHTMLMessage = React.createFactory(ReactIntl.FormattedHTMLMessage);
it('Formats numbers correctly', function () {
var FormattedNumberComponent = React.createClass({
displayName: 'FormattedNumber',
mixins: [IntlMixin],
render: function () {
return React.DOM.div(null, this.formatNumber(1000));
}
});
var FormattedNumber = React.createFactory(FormattedNumberComponent);
var testNode = document.getElementById('test1');
React.render(FormattedNumber({
locales: ['es-AR']
}), testNode);
expect(testNode.firstChild.innerHTML).to.equal('1.000');
});
it('Formats numbers correctly using FormattedNumber component', function () {
var testNode = document.getElementById('test1');
React.render(FormattedNumber({
locales: ['es-AR'],
value: 1000
}), testNode);
expect(testNode.firstChild.innerHTML).to.equal('1.000');
});
it('Formats numbers correctly using named formats', function () {
var testNode = document.getElementById('test1');
var price = {
value: 99.95,
currency: 'USD'
};
React.render(FormattedNumber({
locales: ['en-US'],
formats: {
number: {
currency: {
style: 'currency',
minimumFractionDigits: 2
}
}
},
value: price.value,
format: 'currency',
currency: price.currency
}), testNode);
expect(testNode.firstChild.innerHTML).to.equal('$99.95');
});
it('Formats dates correctly', function () {
var FormattedDateComponent = React.createClass({
displayName: 'FormattedDate',
mixins: [IntlMixin],
render: function () {
return React.DOM.div(null, this.formatDate(this.props.date, {
weekday: 'long',
timeZone: 'UTC'
}));
}
});
var FormattedDate = React.createFactory(FormattedDateComponent);
var testNode = document.getElementById('test2');
React.render(FormattedDate({
locales: ['es-AR'],
date: Date.UTC(2014, 8, 22, 0, 0, 0, 0)
}), testNode);
expect(testNode.firstChild.innerHTML).to.contain('lunes');
React.render(FormattedDate({
locales: ['en-US'],
date: 0
}), testNode);
expect(testNode.firstChild.innerHTML).to.contain('Thursday');
});
it('Formats dates correctly using FormattedDate component', function () {
var testNode = document.getElementById('test2');
React.render(FormattedDate({
locales: ['es-AR'],
value: Date.UTC(2014, 8, 22, 0, 0, 0, 0),
weekday: 'long',
timeZone: 'UTC'
}), testNode);
expect(testNode.firstChild.innerHTML).to.contain('lunes');
React.render(FormattedDate({
locales: ['en-US'],
value: 0,
weekday: 'long',
timeZone: 'UTC'
}), testNode);
expect(testNode.firstChild.innerHTML).to.contain('Thursday');
});
it('Formats messages correctly', function () {
var FormattedMessageComponent = React.createClass({
displayName: 'FormattedMessage',
mixins: [IntlMixin],
getMyMessage: function () {
return 'You have {numPhotos, plural, =0 {no photos} =1 {one photo} other {# photos}}.';
},
render: function () {
return React.DOM.div(null, this.formatMessage(this.getMyMessage(), {
numPhotos: this.props.numPhotos
}));
}
});
var FormattedMessage = React.createFactory(FormattedMessageComponent);
var testNode = document.getElementById('test3');
React.render(FormattedMessage({
locales: ['en-US'],
numPhotos: 1
}), testNode);
expect(testNode.firstChild.innerHTML).to.equal('You have one photo.');
});
it('Formats messages correctly using FormattedMessage component', function () {
var testNode = document.getElementById('test3');
React.render(FormattedMessage({
locales: ['en-US'],
message: 'You have {numPhotos, plural, =0 {no photos} =1 {one photo} other {# photos}}.',
numPhotos: 1
}), testNode);
expect(testNode.firstChild.innerHTML).to.equal('You have one photo.');
});
it('Formats relative times correctly using FormattedRelative component', function () {
var testNode = document.getElementById('test4');
React.render(FormattedRelative({
value: new Date().getTime()
}), testNode);
expect(testNode.firstChild.innerHTML).to.contain('now');
});
it('Supports passing `now` to the FormattedRelative component', function () {
var testNode = document.getElementById('test4');
React.render(FormattedRelative({
value: 2000,
now : 0
}), testNode);
expect(testNode.firstChild.innerHTML).to.contain('in 2 seconds');
});
});