1
1
/**
2
- * Copyright 2023-2024 Shift Crypto AG
2
+ * Copyright 2023-2025 Shift Crypto AG
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
import { useContext } from 'react' ;
18
18
import { Mock , afterEach , beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
19
19
import { render } from '@testing-library/react' ;
20
+ import type { CoinUnit , ConversionUnit } from '@/api/account' ;
20
21
import { Amount } from './amount' ;
21
- import { CoinUnit , ConversionUnit } from '@/api/account' ;
22
22
23
23
vi . mock ( 'react' , async ( ) => ( {
24
24
...( await vi . importActual ( 'react' ) ) ,
@@ -90,8 +90,8 @@ describe('Amount formatting', () => {
90
90
describe ( 'sat amounts' , ( ) => {
91
91
let coins : CoinUnit [ ] = [ 'sat' , 'tsat' ] ;
92
92
coins . forEach ( ( coin ) => {
93
- it ( '12345678901234 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced' , ( ) => {
94
- const { getByTestId } = render ( < Amount amount = "12345678901234" unit = { coin } removeBtcTrailingZeroes /> ) ;
93
+ it ( '12345678901234 ' + coin + ' gets spaced' , ( ) => {
94
+ const { getByTestId } = render ( < Amount amount = "12345678901234" unit = { coin } /> ) ;
95
95
const blocks = getByTestId ( 'amountBlocks' ) ;
96
96
97
97
const values = [
@@ -105,8 +105,8 @@ describe('Amount formatting', () => {
105
105
expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
106
106
} ) ;
107
107
108
- it ( '1234567 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced' , ( ) => {
109
- const { getByTestId } = render ( < Amount amount = "1234567" unit = { coin } removeBtcTrailingZeroes /> ) ;
108
+ it ( '1234567 ' + coin + ' gets spaced' , ( ) => {
109
+ const { getByTestId } = render ( < Amount amount = "1234567" unit = { coin } /> ) ;
110
110
const blocks = getByTestId ( 'amountBlocks' ) ;
111
111
const values = [
112
112
'1' ,
@@ -117,9 +117,8 @@ describe('Amount formatting', () => {
117
117
expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
118
118
} ) ;
119
119
120
-
121
- it ( '12345 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced' , ( ) => {
122
- const { getByTestId } = render ( < Amount amount = "12345" unit = { coin } removeBtcTrailingZeroes /> ) ;
120
+ it ( '12345 ' + coin + ' gets spaced' , ( ) => {
121
+ const { getByTestId } = render ( < Amount amount = "12345" unit = { coin } /> ) ;
123
122
const blocks = getByTestId ( 'amountBlocks' ) ;
124
123
const values = [
125
124
'12' ,
@@ -129,56 +128,8 @@ describe('Amount formatting', () => {
129
128
expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
130
129
} ) ;
131
130
132
- it ( '21 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced' , ( ) => {
133
- const { getByTestId } = render ( < Amount amount = "21" unit = { coin } removeBtcTrailingZeroes /> ) ;
134
- const blocks = getByTestId ( 'amountBlocks' ) ;
135
- const values = [
136
- '21' ,
137
- ] ;
138
- const allSpacedElements = [ ...blocks . children ] ;
139
- expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
140
- } ) ;
141
-
142
- it ( '12345678901234 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
143
- const { getByTestId } = render ( < Amount amount = "12345678901234" unit = { coin } /> ) ;
144
- const blocks = getByTestId ( 'amountBlocks' ) ;
145
- const values = [
146
- '12' ,
147
- '345' ,
148
- '678' ,
149
- '901' ,
150
- '234' ,
151
- ] ;
152
- const allSpacedElements = [ ...blocks . children ] ;
153
- expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
154
- } ) ;
155
-
156
-
157
- it ( '1234567 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
158
- const { getByTestId } = render ( < Amount amount = "1234567" unit = { coin } /> ) ;
159
- const blocks = getByTestId ( 'amountBlocks' ) ;
160
- const values = [
161
- '1' ,
162
- '234' ,
163
- '567' ,
164
- ] ;
165
- const allSpacedElements = [ ...blocks . children ] ;
166
- expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
167
- } ) ;
168
-
169
- it ( '12345 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
170
- const { getByTestId } = render ( < Amount amount = "12345" unit = { coin } /> ) ;
171
- const blocks = getByTestId ( 'amountBlocks' ) ;
172
- const values = [
173
- '12' ,
174
- '345' ,
175
- ] ;
176
- const allSpacedElements = [ ...blocks . children ] ;
177
- expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
178
- } ) ;
179
-
180
- it ( '21 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
181
- const { getByTestId } = render ( < Amount amount = "21" unit = { coin } /> ) ;
131
+ it ( '21 ' + coin + ' gets spaced' , ( ) => {
132
+ const { getByTestId } = render ( < Amount amount = "21" unit = { coin } /> ) ;
182
133
const blocks = getByTestId ( 'amountBlocks' ) ;
183
134
const values = [
184
135
'21' ,
@@ -193,23 +144,8 @@ describe('Amount formatting', () => {
193
144
describe ( 'BTC/LTC coins amounts' , ( ) => {
194
145
let coins : CoinUnit [ ] = [ 'BTC' , 'TBTC' , 'LTC' , 'TLTC' ] ;
195
146
coins . forEach ( coin => {
196
- it ( '10.00000000 ' + coin + ' with removeBtcTrailingZeroes enabled becomes 10' , ( ) => {
197
- const { container } = render ( < Amount amount = "10.00000000" unit = { coin } removeBtcTrailingZeroes /> ) ;
198
- expect ( container ) . toHaveTextContent ( '10' ) ;
199
- } ) ;
200
- it ( '12345.12300000 ' + coin + ' with removeBtcTrailingZeroes enabled becomes 12345.123' , ( ) => {
201
- const { container } = render ( < Amount amount = "12345.12300000" unit = { coin } removeBtcTrailingZeroes /> ) ;
202
- expect ( container ) . toHaveTextContent ( '12345.123' ) ;
203
- } ) ;
204
- it ( '42 ' + coin + ' with removeBtcTrailingZeroes enabled stays 42' , ( ) => {
205
- const { container } = render ( < Amount amount = "42" unit = { coin } removeBtcTrailingZeroes /> ) ;
206
- expect ( container ) . toHaveTextContent ( '42' ) ;
207
- } ) ;
208
- it ( '0.12345678 ' + coin + ' with removeBtcTrailingZeroes enabled stays 0.12345678' , ( ) => {
209
- const { container } = render ( < Amount amount = "0.12345678" unit = { coin } removeBtcTrailingZeroes /> ) ;
210
- expect ( container ) . toHaveTextContent ( '0.12345678' ) ;
211
- } ) ;
212
- it ( '10.00000000 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
147
+
148
+ it ( '10.00000000 ' + coin + ' gets spaced' , ( ) => {
213
149
const { getByTestId } = render ( < Amount amount = "10.00000000" unit = { coin } /> ) ;
214
150
const blocks = getByTestId ( 'amountBlocks' ) ;
215
151
const values = [
@@ -220,7 +156,8 @@ describe('Amount formatting', () => {
220
156
const allSpacedElements = [ ...blocks . children ] ;
221
157
expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
222
158
} ) ;
223
- it ( '12345.12300000 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
159
+
160
+ it ( '12345.12300000 ' + coin + ' gets spaced' , ( ) => {
224
161
const { getByTestId } = render ( < Amount amount = "12345.12300000" unit = { coin } /> ) ;
225
162
const blocks = getByTestId ( 'amountBlocks' ) ;
226
163
const values = [
@@ -231,11 +168,13 @@ describe('Amount formatting', () => {
231
168
const allSpacedElements = [ ...blocks . children ] ;
232
169
expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
233
170
} ) ;
234
- it ( '42 ' + coin + ' with removeBtcTrailingZeroes disabled stays 42' , ( ) => {
171
+
172
+ it ( '42 ' + coin + ' stays 42' , ( ) => {
235
173
const { container } = render ( < Amount amount = "42" unit = { coin } /> ) ;
236
174
expect ( container ) . toHaveTextContent ( '42' ) ;
237
175
} ) ;
238
- it ( '0.12345678 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced' , ( ) => {
176
+
177
+ it ( '0.12345678 ' + coin + ' gets spaced' , ( ) => {
239
178
const { getByTestId } = render ( < Amount amount = "0.12345678" unit = { coin } /> ) ;
240
179
const blocks = getByTestId ( 'amountBlocks' ) ;
241
180
const values = [
@@ -246,33 +185,22 @@ describe('Amount formatting', () => {
246
185
const allSpacedElements = [ ...blocks . children ] ;
247
186
expect ( validateSpacing ( values , allSpacedElements ) ) . toBeTruthy ( ) ;
248
187
} ) ;
188
+
249
189
} ) ;
250
190
} ) ;
251
191
252
192
describe ( 'non BTC coins amounts' , ( ) => {
253
193
let coins : CoinUnit [ ] = [ 'ETH' , 'SEPETH' ] ;
254
194
coins . forEach ( coin => {
255
- it ( '10.00000000 ' + coin + ' with removeBtcTrailingZeroes enabled stays 10.00000000' , ( ) => {
256
- const { container } = render ( < Amount amount = "10.00000000" unit = { coin } removeBtcTrailingZeroes /> ) ;
257
- expect ( container ) . toHaveTextContent ( '10.00000000' ) ;
258
- } ) ;
259
- it ( '10.12300000 ' + coin + ' with removeBtcTrailingZeroes enabled stays 10.12300000' , ( ) => {
260
- const { container } = render ( < Amount amount = "10.12300000" unit = { coin } removeBtcTrailingZeroes /> ) ;
261
- expect ( container ) . toHaveTextContent ( '10.12300000' ) ;
262
- } ) ;
263
- it ( '42 ' + coin + ' with removeBtcTrailingZeroes enabled stays 42' , ( ) => {
264
- const { container } = render ( < Amount amount = "42" unit = { coin } removeBtcTrailingZeroes /> ) ;
265
- expect ( container ) . toHaveTextContent ( '42' ) ;
266
- } ) ;
267
- it ( '10.00000000 ' + coin + ' with removeBtcTrailingZeroes disabled stays 10.00000000' , ( ) => {
195
+ it ( '10.00000000 ' + coin + ' stays 10.00000000' , ( ) => {
268
196
const { container } = render ( < Amount amount = "10.00000000" unit = { coin } /> ) ;
269
197
expect ( container ) . toHaveTextContent ( '10.00000000' ) ;
270
198
} ) ;
271
- it ( '10.12300000 ' + coin + ' with removeBtcTrailingZeroes disabled stays 10.12300000' , ( ) => {
199
+ it ( '10.12300000 ' + coin + ' stays 10.12300000' , ( ) => {
272
200
const { container } = render ( < Amount amount = "10.12300000" unit = { coin } /> ) ;
273
201
expect ( container ) . toHaveTextContent ( '10.12300000' ) ;
274
202
} ) ;
275
- it ( '42 ' + coin + ' with removeBtcTrailingZeroes disabled stays 42' , ( ) => {
203
+ it ( '42 ' + coin + ' stays 42' , ( ) => {
276
204
const { container } = render ( < Amount amount = "42" unit = { coin } /> ) ;
277
205
expect ( container ) . toHaveTextContent ( '42' ) ;
278
206
} ) ;
@@ -282,19 +210,11 @@ describe('Amount formatting', () => {
282
210
describe ( 'fiat amounts' , ( ) => {
283
211
let fiatCoins : ConversionUnit [ ] = [ 'USD' , 'EUR' , 'CHF' ] ;
284
212
fiatCoins . forEach ( coin => {
285
- it ( '1\'340.25 ' + coin + ' with removeBtcTrailingZeroes enabled stays 1\'340.25' , ( ) => {
286
- const { container } = render ( < Amount amount = "1'340.25" unit = { coin } removeBtcTrailingZeroes /> ) ;
287
- expect ( container ) . toHaveTextContent ( '1’340.25' ) ;
288
- } ) ;
289
- it ( '218.00 ' + coin + ' with removeBtcTrailingZeroes enabled stays 218.00' , ( ) => {
290
- const { container } = render ( < Amount amount = "218.00" unit = { coin } removeBtcTrailingZeroes /> ) ;
291
- expect ( container ) . toHaveTextContent ( '218.00' ) ;
292
- } ) ;
293
- it ( '1\'340.25 ' + coin + ' with removeBtcTrailingZeroes disabled stays 1\'340.25' , ( ) => {
213
+ it ( '1\'340.25 ' + coin + ' stays 1\'340.25' , ( ) => {
294
214
const { container } = render ( < Amount amount = "1'340.25" unit = { coin } /> ) ;
295
215
expect ( container ) . toHaveTextContent ( '1’340.25' ) ;
296
216
} ) ;
297
- it ( '218.00 ' + coin + ' with removeBtcTrailingZeroes disabled stays 218.00' , ( ) => {
217
+ it ( '218.00 ' + coin + ' stays 218.00' , ( ) => {
298
218
const { container } = render ( < Amount amount = "218.00" unit = { coin } /> ) ;
299
219
expect ( container ) . toHaveTextContent ( '218.00' ) ;
300
220
} ) ;
0 commit comments