@sproutsocial/seeds-react-numeral 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ import testNumeral from "./testNumeral";
2
+ const options = {
3
+ currency: "USD",
4
+ };
5
+
6
+ describe("When using the default props...", () => {
7
+ describe("... with small numbers it should not abbreviate the text", () => {
8
+ // positive values
9
+ testNumeral(1, options, {
10
+ text: "$1.00",
11
+ });
12
+ testNumeral(12, options, {
13
+ text: "$12.00",
14
+ });
15
+ testNumeral(123, options, {
16
+ text: "$123.00",
17
+ });
18
+ testNumeral(1234, options, {
19
+ text: "$1,234.00",
20
+ });
21
+ // negative values
22
+ testNumeral(-1, options, {
23
+ text: "-$1.00",
24
+ });
25
+ testNumeral(-12, options, {
26
+ text: "-$12.00",
27
+ });
28
+ testNumeral(-123, options, {
29
+ text: "-$123.00",
30
+ });
31
+ testNumeral(-1234, options, {
32
+ text: "-$1,234.00",
33
+ });
34
+ });
35
+
36
+ describe("... with big numbers it should round and abbreviate the text", () => {
37
+ // positive values
38
+ testNumeral(12345.67, options, {
39
+ text: "$12.35K",
40
+ tip: "$12,345.67",
41
+ });
42
+ testNumeral(123456.7, options, {
43
+ text: "$123.46K",
44
+ tip: "$123,456.70",
45
+ });
46
+ testNumeral(1225000, options, {
47
+ text: "$1.23M",
48
+ tip: "$1,225,000.00",
49
+ });
50
+ testNumeral(1225000000, options, {
51
+ text: "$1.23B",
52
+ tip: "$1,225,000,000.00",
53
+ });
54
+ testNumeral(1225000000000, options, {
55
+ text: "$1.23T",
56
+ tip: "$1,225,000,000,000.00",
57
+ });
58
+ testNumeral(12250000000000000, options, {
59
+ text: "$12,250.00T",
60
+ tip: "$12,250,000,000,000,000.00",
61
+ });
62
+ // negative values
63
+ testNumeral(-12345.67, options, {
64
+ text: "-$12.35K",
65
+ tip: "-$12,345.67",
66
+ });
67
+ testNumeral(-123456.7, options, {
68
+ text: "-$123.46K",
69
+ tip: "-$123,456.70",
70
+ });
71
+ testNumeral(-1225000, options, {
72
+ text: "-$1.23M",
73
+ tip: "-$1,225,000.00",
74
+ });
75
+ testNumeral(-1225000000, options, {
76
+ text: "-$1.23B",
77
+ tip: "-$1,225,000,000.00",
78
+ });
79
+ testNumeral(-1225000000000, options, {
80
+ text: "-$1.23T",
81
+ tip: "-$1,225,000,000,000.00",
82
+ });
83
+ testNumeral(-12250000000000000, options, {
84
+ text: "-$12,250.00T",
85
+ tip: "-$12,250,000,000,000,000.00",
86
+ });
87
+ });
88
+
89
+ describe("... with short decimals it should not abbreviate the text", () => {
90
+ // positive values
91
+ testNumeral(1.2, options, {
92
+ text: "$1.20",
93
+ });
94
+ testNumeral(1.23, options, {
95
+ text: "$1.23",
96
+ });
97
+ // negative values
98
+ testNumeral(-1.2, options, {
99
+ text: "-$1.20",
100
+ });
101
+ testNumeral(-1.23, options, {
102
+ text: "-$1.23",
103
+ });
104
+ });
105
+
106
+ describe("... with long decimals it should round and abbreviate the text", () => {
107
+ // positive values
108
+ testNumeral(1.234, options, {
109
+ text: "$1.23",
110
+ });
111
+ testNumeral(1.2355, options, {
112
+ text: "$1.24",
113
+ });
114
+ // negative values
115
+ testNumeral(-1.234, options, {
116
+ text: "-$1.23",
117
+ });
118
+ testNumeral(-1.2355, options, {
119
+ text: "-$1.24",
120
+ });
121
+ });
122
+ });
@@ -0,0 +1,231 @@
1
+ import testNumeral from "./testNumeral";
2
+
3
+ describe("When using the default props...", () => {
4
+ describe("... with small numbers it should not abbreviate the text", () => {
5
+ // positive values
6
+ testNumeral(
7
+ 1,
8
+ {},
9
+ {
10
+ text: "1",
11
+ }
12
+ );
13
+ testNumeral(
14
+ 12,
15
+ {},
16
+ {
17
+ text: "12",
18
+ }
19
+ );
20
+ testNumeral(
21
+ 123,
22
+ {},
23
+ {
24
+ text: "123",
25
+ }
26
+ );
27
+ testNumeral(
28
+ 1234,
29
+ {},
30
+ {
31
+ text: "1,234",
32
+ }
33
+ );
34
+ // negative values
35
+ testNumeral(
36
+ -1,
37
+ {},
38
+ {
39
+ text: "-1",
40
+ }
41
+ );
42
+ testNumeral(
43
+ -12,
44
+ {},
45
+ {
46
+ text: "-12",
47
+ }
48
+ );
49
+ testNumeral(
50
+ -123,
51
+ {},
52
+ {
53
+ text: "-123",
54
+ }
55
+ );
56
+ testNumeral(
57
+ -1234,
58
+ {},
59
+ {
60
+ text: "-1,234",
61
+ }
62
+ );
63
+ });
64
+
65
+ describe("... with big numbers it should round and abbreviate the text", () => {
66
+ // positive values
67
+ testNumeral(
68
+ 12345,
69
+ {},
70
+ {
71
+ text: "12.35K",
72
+ tip: "12,345",
73
+ }
74
+ );
75
+ testNumeral(
76
+ 123456,
77
+ {},
78
+ {
79
+ text: "123.46K",
80
+ tip: "123,456",
81
+ }
82
+ );
83
+ testNumeral(
84
+ 1225000,
85
+ {},
86
+ {
87
+ text: "1.23M",
88
+ tip: "1,225,000",
89
+ }
90
+ );
91
+ testNumeral(
92
+ 1225000000,
93
+ {},
94
+ {
95
+ text: "1.23B",
96
+ tip: "1,225,000,000",
97
+ }
98
+ );
99
+ testNumeral(
100
+ 1225000000000,
101
+ {},
102
+ {
103
+ text: "1.23T",
104
+ tip: "1,225,000,000,000",
105
+ }
106
+ );
107
+ testNumeral(
108
+ 12250000000000000,
109
+ {},
110
+ {
111
+ text: "12,250.00T",
112
+ tip: "12,250,000,000,000,000",
113
+ }
114
+ );
115
+ // negative values
116
+ testNumeral(
117
+ -12345,
118
+ {},
119
+ {
120
+ text: "-12.35K",
121
+ tip: "-12,345",
122
+ }
123
+ );
124
+ testNumeral(
125
+ -123456,
126
+ {},
127
+ {
128
+ text: "-123.46K",
129
+ tip: "-123,456",
130
+ }
131
+ );
132
+ testNumeral(
133
+ -1225000,
134
+ {},
135
+ {
136
+ text: "-1.23M",
137
+ tip: "-1,225,000",
138
+ }
139
+ );
140
+ testNumeral(
141
+ -1225000000,
142
+ {},
143
+ {
144
+ text: "-1.23B",
145
+ tip: "-1,225,000,000",
146
+ }
147
+ );
148
+ testNumeral(
149
+ -1225000000000,
150
+ {},
151
+ {
152
+ text: "-1.23T",
153
+ tip: "-1,225,000,000,000",
154
+ }
155
+ );
156
+ testNumeral(
157
+ -12250000000000000,
158
+ {},
159
+ {
160
+ text: "-12,250.00T",
161
+ tip: "-12,250,000,000,000,000",
162
+ }
163
+ );
164
+ });
165
+
166
+ describe("... with short decimals it should not abbreviate the text", () => {
167
+ // positive values
168
+ testNumeral(
169
+ 1.2,
170
+ {},
171
+ {
172
+ text: "1.2",
173
+ }
174
+ );
175
+ testNumeral(
176
+ 1.23,
177
+ {},
178
+ {
179
+ text: "1.23",
180
+ }
181
+ );
182
+ // negative values
183
+ testNumeral(
184
+ -1.2,
185
+ {},
186
+ {
187
+ text: "-1.2",
188
+ }
189
+ );
190
+ testNumeral(
191
+ -1.23,
192
+ {},
193
+ {
194
+ text: "-1.23",
195
+ }
196
+ );
197
+ });
198
+
199
+ describe("... with long decimals it should round and abbreviate the text", () => {
200
+ // positive values
201
+ testNumeral(
202
+ 1.234,
203
+ {},
204
+ {
205
+ text: "1.23",
206
+ }
207
+ );
208
+ testNumeral(
209
+ 1.2355,
210
+ {},
211
+ {
212
+ text: "1.24",
213
+ }
214
+ );
215
+ // negative values
216
+ testNumeral(
217
+ -1.234,
218
+ {},
219
+ {
220
+ text: "-1.23",
221
+ }
222
+ );
223
+ testNumeral(
224
+ -1.2355,
225
+ {},
226
+ {
227
+ text: "-1.24",
228
+ }
229
+ );
230
+ });
231
+ });
@@ -0,0 +1,47 @@
1
+ import { EM_DASH } from "../../constants";
2
+ import testNumeral from "./testNumeral";
3
+
4
+ describe("When using an invalid value...", () => {
5
+ describe("... it renders a dash", () => {
6
+ testNumeral(
7
+ undefined,
8
+ { invalidNumberLabel: "Not available" },
9
+ {
10
+ text: EM_DASH,
11
+ label: "Not available",
12
+ }
13
+ );
14
+ testNumeral(
15
+ null,
16
+ { invalidNumberLabel: "Not available" },
17
+ {
18
+ text: EM_DASH,
19
+ label: "Not available",
20
+ }
21
+ );
22
+ testNumeral(
23
+ NaN,
24
+ { invalidNumberLabel: "Not available" },
25
+ {
26
+ text: EM_DASH,
27
+ label: "Not available",
28
+ }
29
+ );
30
+ testNumeral(
31
+ Infinity,
32
+ { invalidNumberLabel: "Not available" },
33
+ {
34
+ text: EM_DASH,
35
+ label: "Not available",
36
+ }
37
+ );
38
+ testNumeral(
39
+ -Infinity,
40
+ { invalidNumberLabel: "Not available" },
41
+ {
42
+ text: EM_DASH,
43
+ label: "Not available",
44
+ }
45
+ );
46
+ });
47
+ });