1
1
import { expect } from "chai" ;
2
- import Vue from "vue" ;
3
2
import Circle from "@/components/Circle/Circle.vue" ;
4
3
import HalfCircle from "@/components/Circle/HalfCircle.vue" ;
5
4
import VueEllipseProgress from "@/components/VueEllipseProgress.vue" ;
6
- import { dotParser } from "@/components/optionsParser" ;
7
- import { factory } from "@/../tests/helper" ;
5
+ import { dotParser , calcThickness } from "@/components/optionsParser" ;
6
+ import { factory , setCircleProps } from "@/../tests/helper" ;
8
7
9
8
const localFactory = ( props , container = Circle ) => factory ( { container, props } ) ;
10
9
@@ -50,6 +49,7 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
50
49
it ( "lets progress circle visible for -1 < progress < 1" , async ( ) => {
51
50
progress = 0 ;
52
51
await wrapper . setProps ( { options : { ...wrapper . props ( ) . options , half : true } } ) ;
52
+ await setCircleProps ( wrapper , { half : true } ) ;
53
53
const radius = size / 2 - thickness / 2 ;
54
54
const circumference = radius * 2 * Math . PI ;
55
55
@@ -126,16 +126,12 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
126
126
} ) ;
127
127
128
128
it ( "calculates and sets the position of the half circles correctly" , ( ) => {
129
- expect ( wrapper . vm . position ) . to . equal ( position ) ;
130
- expect ( wrapper . vm . path ) . to . equal ( expectedPath ) ;
131
-
132
129
expect ( circleProgressWrapper . element . getAttribute ( "d" ) ) . to . equal ( `${ expectedPath } ` ) ;
133
130
expect ( circleEmptyWrapper . element . getAttribute ( "d" ) ) . to . equal ( `${ expectedPath } ` ) ;
134
131
} ) ;
135
132
it ( "calculates the progress circle stroke offset correctly" , async ( ) => {
136
133
const circumference = ( radius * 2 * Math . PI ) / 2 ;
137
134
const expectedOffset = circumference - ( progress / 100 ) * circumference ;
138
- expect ( wrapper . vm . progressOffset ) . to . equal ( expectedOffset ) ;
139
135
expect ( circleProgressWrapper . element . style . strokeDashoffset ) . to . equal ( `${ expectedOffset } ` ) ;
140
136
} ) ;
141
137
} ) ;
@@ -235,21 +231,19 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
235
231
it ( "sets the rotation of the svg container correctly" , async ( ) => {
236
232
const angle = 80 ;
237
233
await circleWrapper . setProps ( { options : { ...circleWrapper . props ( ) . options , angle } } ) ;
238
- await Vue . nextTick ( ) ;
239
234
expect ( circleWrapper . element . style . transform ) . to . equal ( `rotate(${ angle } deg)` ) ;
240
235
} ) ;
241
236
it ( "sets @0 value as the rotation of the svg container correctly" , async ( ) => {
242
237
const angle = 0 ;
243
238
await circleWrapper . setProps ( { options : { ...circleWrapper . props ( ) . options , angle } } ) ;
244
- await Vue . nextTick ( ) ;
245
239
expect ( circleWrapper . element . style . transform ) . to . equal ( `rotate(${ angle } deg)` ) ;
246
240
} ) ;
247
241
} ) ;
248
242
describe ( "#data" , ( ) => {
249
243
const size = 600 ;
250
244
const globalThickness = 5 ;
251
245
const globalGap = 5 ;
252
- const globalDot = "2%" ;
246
+ const globalDot = dotParser ( "2%" , size ) ;
253
247
254
248
const data = [ ] ;
255
249
// generate random test data
@@ -273,22 +267,29 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
273
267
274
268
const wrapper = factory ( {
275
269
container : VueEllipseProgress ,
276
- props : { data, gap : globalGap , thickness : globalThickness , size, dot : globalDot } ,
270
+ props : {
271
+ data,
272
+ gap : globalGap ,
273
+ thickness : globalThickness ,
274
+ size,
275
+ dot : globalDot ,
276
+ } ,
277
277
isCircleFactory : false ,
278
278
} ) ;
279
279
const circleWrappers = wrapper . findAllComponents ( Circle ) ;
280
280
281
- const calculateThickness = ( t ) => ( t . toString ( ) . includes ( "%" ) ? ( parseFloat ( t ) * size ) / 100 : t ) ;
281
+ // const calculateThickness = (t) => (t.toString().includes("%") ? (parseFloat(t) * size) / 100 : t);
282
282
283
283
for ( let i = 0 ; i < data . length ; i ++ ) {
284
284
const circleData = data [ i ] ;
285
285
it ( `calculates the radius of circle #${ i } correctly
286
286
#thickness ${ circleData . thickness } | #gap ${ circleData . gap } | #dot ${ circleData . dot } ` , ( ) => {
287
287
const circleGap = circleData . gap !== undefined ? circleData . gap : globalGap ;
288
- const circleThickness = calculateThickness (
289
- circleData . thickness !== undefined ? circleData . thickness : globalThickness
288
+ const circleThickness = calcThickness (
289
+ circleData . thickness !== undefined ? circleData . thickness : globalThickness ,
290
+ size
290
291
) ;
291
- const circleDot = calculateThickness ( dotParser ( circleData . dot !== undefined ? circleData . dot : globalDot ) . size ) ;
292
+ const circleDot = dotParser ( circleData . dot !== undefined ? circleData . dot : globalDot , size ) . size ;
292
293
293
294
let radius ;
294
295
const baseRadius = size / 2 - Math . max ( circleThickness , circleDot ) / 2 ;
@@ -297,8 +298,8 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
297
298
const previousCirclesThickness = previousCirclesData
298
299
. map ( ( { gap, thickness, dot } , n ) => {
299
300
const g = gap !== undefined ? gap : globalGap ;
300
- const t = calculateThickness ( thickness !== undefined ? thickness : globalThickness ) ;
301
- const d = calculateThickness ( dotParser ( dot !== undefined ? dot : globalDot ) . size ) ;
301
+ const t = calcThickness ( thickness !== undefined ? thickness : globalThickness , size ) ;
302
+ const d = dotParser ( dot !== undefined ? dot : globalDot , size ) . size ;
302
303
const thicknessWithDot = Math . max ( t , d ) ;
303
304
return n > 0 ? g + thicknessWithDot : thicknessWithDot ;
304
305
} )
@@ -308,8 +309,8 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
308
309
} else {
309
310
radius = baseRadius ;
310
311
}
311
- const circleProgressWrapper = circleWrappers . at ( i ) . find ( "circle.ep-circle--progress" ) ;
312
- const circleEmptyWrapper = circleWrappers . at ( i ) . find ( "circle.ep-circle--empty" ) ;
312
+ const circleProgressWrapper = circleWrappers [ i ] . find ( "circle.ep-circle--progress" ) ;
313
+ const circleEmptyWrapper = circleWrappers [ i ] . find ( "circle.ep-circle--empty" ) ;
313
314
expect ( circleProgressWrapper . element . getAttribute ( "r" ) ) . to . equal ( `${ radius } ` ) ;
314
315
expect ( circleEmptyWrapper . element . getAttribute ( "r" ) ) . to . equal ( `${ radius } ` ) ;
315
316
} ) ;
0 commit comments