@@ -33,34 +33,59 @@ describe("[ Counter.vue ]", () => {
33
33
describe ( "#value" , async ( ) => {
34
34
it ( "renders the final value correctly" , ( done ) => {
35
35
const counterWrapper = factory ( {
36
- legend : 50 ,
36
+ legend : "50.00" ,
37
37
animation : `default 0 0` ,
38
38
} ) . findComponent ( Counter ) ;
39
39
setTimeout ( ( ) => {
40
- expect ( counterWrapper . element . textContent ) . to . equal ( "50" ) ;
40
+ expect ( counterWrapper . element . textContent ) . to . equal ( "50.00 " ) ;
41
41
} , 100 ) ;
42
42
done ( ) ;
43
43
} ) ;
44
44
45
45
const values = [
46
46
{
47
47
legend : - 45.2456 ,
48
- count : 4 ,
48
+ decimalsCount : 4 ,
49
49
start : "0.0000" ,
50
50
} ,
51
51
{
52
52
legend : 56.34 ,
53
- count : 2 ,
53
+ decimalsCount : 2 ,
54
+ start : "0.00" ,
55
+ } ,
56
+ {
57
+ legend : 98.0 ,
58
+ decimalsCount : 0 ,
59
+ start : "0" ,
60
+ } ,
61
+ {
62
+ legend : "98.0" ,
63
+ decimalsCount : 1 ,
64
+ start : "00.0" ,
65
+ } ,
66
+ {
67
+ legend : "100.00" ,
68
+ decimalsCount : 2 ,
69
+ start : "000.00" ,
70
+ } ,
71
+ {
72
+ legend : "00100.00" ,
73
+ decimalsCount : 2 ,
74
+ start : "00000.00" ,
75
+ } ,
76
+ {
77
+ legend : "56.34" ,
78
+ decimalsCount : 2 ,
54
79
start : "00.00" ,
55
80
} ,
56
81
{
57
82
legend : "25,564" ,
58
- count : 3 ,
83
+ decimalsCount : 3 ,
59
84
start : "00,000" ,
60
85
} ,
61
86
{
62
87
legend : "-30,5" ,
63
- count : 1 ,
88
+ decimalsCount : 1 ,
64
89
start : "0,0" ,
65
90
} ,
66
91
] ;
@@ -69,57 +94,60 @@ describe("[ Counter.vue ]", () => {
69
94
delay : 1000 ,
70
95
} ;
71
96
for ( const val of values ) {
72
- const { legend, count , start } = val ;
97
+ const { legend, decimalsCount , start } = val ;
73
98
const wrapper = factory ( {
74
99
legend,
75
100
animation : `default ${ animation . duration } ${ animation . delay } ` ,
76
101
} ) ;
77
- const counterWrapper = wrapper . findComponent ( Counter ) ;
78
102
79
- it ( "counts the decimals correctly" , ( ) => {
80
- expect ( counterWrapper . vm . decimalsCount ) . to . equal ( count ) ;
81
- } ) ;
82
-
83
- it ( "renders the start value with the correct number of decimals places" , ( ) => {
84
- expect ( counterWrapper . element . textContent ) . to . equal ( start ) ;
85
- } ) ;
103
+ describe ( `${ legend } ` , ( ) => {
104
+ const counterWrapper = wrapper . findComponent ( Counter ) ;
86
105
87
- if ( legend . toString ( ) . includes ( "," ) ) {
88
- it ( "accepts `,` as delimiter" , ( ) => {
89
- expect ( counterWrapper . vm . delimiter ) . to . equal ( "," ) ;
106
+ it ( "counts the decimals correctly" , ( ) => {
107
+ expect ( counterWrapper . vm . decimalsCount ) . to . equal ( decimalsCount ) ;
90
108
} ) ;
91
109
92
- it ( "displays the provided # value with `,` as delimiter " , ( ) => {
93
- expect ( counterWrapper . element . textContent ) . to . have . string ( "," ) ;
110
+ it ( "renders the start value with the correct number of decimals and integer places " , ( ) => {
111
+ expect ( counterWrapper . element . textContent ) . to . equal ( start ) ;
94
112
} ) ;
95
113
96
- it ( "converts #value to decimal correctly, if provided with `,` as delimiter" , ( ) => {
97
- expect ( counterWrapper . vm . end ) . to . equal ( parseFloat ( legend . toString ( ) . replace ( ", ", "." ) ) ) ;
98
- } ) ;
99
- }
114
+ if ( legend . toString ( ) . includes ( "," ) ) {
115
+ it ( "accepts `,` as delimiter ", ( ) => {
116
+ expect ( counterWrapper . vm . delimiter ) . to . equal ( "," ) ;
117
+ } ) ;
100
118
101
- it ( "calculates the difference between the start and end values correctly" , ( ) => {
102
- const endValue = parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ;
103
- const startValue = 0 ;
104
- const diff = Math . abs ( endValue - startValue ) ;
105
- expect ( counterWrapper . vm . difference ) . to . equal ( diff ) ;
106
- } ) ;
119
+ it ( "displays the provided #value with `,` as delimiter" , ( ) => {
120
+ expect ( counterWrapper . element . textContent ) . to . have . string ( "," ) ;
121
+ } ) ;
107
122
108
- it ( "calculates the one step count value correctly" , ( ) => {
109
- const endValue = parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ;
110
- const startValue = 0 ;
111
- const diff = Math . abs ( endValue - startValue ) ;
112
- const duration = animation . duration ;
113
- const oneStepCountValue = diff / duration ;
114
- expect ( counterWrapper . vm . oneStepDifference ) . to . equal ( oneStepCountValue ) ;
115
- } ) ;
123
+ it ( "converts #value to decimal correctly, if provided with `,` as delimiter" , ( ) => {
124
+ expect ( counterWrapper . vm . end ) . to . equal ( parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ) ;
125
+ } ) ;
126
+ }
116
127
117
- it ( "calculates the one step count value correctly with 0 duration" , async ( ) => {
118
- await wrapper . setProps ( { animation : "default 0 0" } ) ;
119
- const endValue = parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ;
120
- const startValue = 0 ;
121
- const diff = Math . abs ( endValue - startValue ) ;
122
- expect ( counterWrapper . vm . oneStepDifference ) . to . equal ( diff ) ;
128
+ it ( "calculates the difference between the start and end values correctly" , ( ) => {
129
+ const endValue = parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ;
130
+ const startValue = 0 ;
131
+ const diff = Math . abs ( endValue - startValue ) ;
132
+ expect ( counterWrapper . vm . difference ) . to . equal ( diff ) ;
133
+ } ) ;
134
+
135
+ it ( "calculates the one step count value correctly" , ( ) => {
136
+ const endValue = parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ;
137
+ const startValue = 0 ;
138
+ const diff = Math . abs ( endValue - startValue ) ;
139
+ const duration = animation . duration ;
140
+ const oneStepCountValue = diff / duration ;
141
+ expect ( counterWrapper . vm . oneStepDifference ) . to . equal ( oneStepCountValue ) ;
142
+ } ) ;
143
+
144
+ it ( "calculates the one step count value correctly with 0 duration" , async ( ) => {
145
+ await wrapper . setProps ( { animation : "default 0 0" } ) ;
146
+ const endValue = parseFloat ( legend . toString ( ) . replace ( "," , "." ) ) ;
147
+ const startValue = 0 ;
148
+ const diff = Math . abs ( endValue - startValue ) ;
149
+ expect ( counterWrapper . vm . oneStepDifference ) . to . equal ( diff ) ;
150
+ } ) ;
123
151
} ) ;
124
152
}
125
153
} ) ;
0 commit comments