Skip to content

Commit c3852ad

Browse files
authored
Merge pull request #97 from setaman/v2-fix-tests
V2 fix tests
2 parents 05579dc + 1f125b5 commit c3852ad

21 files changed

+792
-658
lines changed

package-lock.json

+173-190
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
"@vue/cli-plugin-eslint": "^4.5.9",
3939
"@vue/cli-plugin-unit-mocha": "^4.5.9",
4040
"@vue/cli-service": "^4.5.9",
41-
"@vue/compiler-sfc": "^3.0.4",
41+
"@vue/compiler-sfc": "^3.0.5",
4242
"@vue/eslint-config-airbnb": "^5.3.0",
43-
"@vue/test-utils": "^2.0.0-beta.11",
43+
"@vue/test-utils": "^2.0.0-beta.13",
4444
"babel-eslint": "^10.1.0",
4545
"chai": "^4.2.0",
46-
"eslint": "^7.15.0",
47-
"eslint-config-prettier": "^7.0.0",
48-
"eslint-plugin-prettier": "^3.2.0",
49-
"eslint-plugin-vue": "^7.2.0",
46+
"eslint": "^7.17.0",
47+
"eslint-config-prettier": "^7.1.0",
48+
"eslint-plugin-prettier": "^3.3.0",
49+
"eslint-plugin-vue": "^7.4.0",
5050
"node-sass": "^5.0.0",
5151
"prettier": "^2.2.1",
5252
"sass-loader": "^10.1.0",

src/App.vue

+4-29
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,21 @@
3838
<input type="checkbox" v-model="circles[3].loading" />
3939
</div>-->
4040
<div style="border: 1px solid red; display: inline-block">
41-
<ve-progress
42-
:size="200"
43-
:progress="progress"
44-
:legend="1315.56"
45-
animation="rs 2000 500"
46-
:loading="loading"
47-
:reverse="true"
48-
:thickness="20"
49-
:empty-thickness="10"
50-
dot="10 red"
51-
:loader="{ thickness: 40, color: 'red' }"
52-
line-mode="bottom"
53-
:no-data="noData"
54-
:determinate="determinate"
55-
>
56-
<template v-slot:default="{ counterTick }">
57-
<span
58-
:style="` transition: 0.5s; font-weight: bold; font-size: 1.6rem; color: ${
59-
counterTick.currentValue < 600 ? 'red' : 'yellow'
60-
};`"
61-
>
62-
{{ formattedPrice(counterTick.currentValue) }}
63-
</span>
64-
</template>
65-
</ve-progress>
41+
<ve-progress :size="200" loading :progress="progress" legend="345,12345"> </ve-progress>
6642
</div>
6743
<ve-progress
68-
dot="20 green"
6944
:loading="loading"
7045
:size="200"
71-
:progress="progress"
46+
:thickness="10"
47+
:progress="50"
7248
:legend-value="125.1"
7349
half
74-
line-mode="out 20"
7550
:no-data="noData"
7651
:determinate="determinate"
7752
:loader="{ thickness: 40, color: 'red' }"
7853
>
7954
<template v-slot:legend-caption>
80-
<p slot="legend-caption">TASKS DONE</p>
55+
<p id="slot-id" slot="legend-caption">TASKS DONE</p>
8156
</template>
8257
</ve-progress>
8358
</div>

src/components/Circle/Circle.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
}"
99
>
1010
<circle
11+
v-if="options.emptyColorFill !== 'transparent'"
1112
class="ep-circle--empty__fill"
1213
:r="emptyFillRadius"
1314
:cx="position"
@@ -36,12 +37,8 @@
3637
:stroke-width="emptyThickness"
3738
>
3839
</circle>
39-
<fade-in-transition>
40-
<g v-if="isLoading">
41-
<circle-loader :options="options.loader" />
42-
</g>
43-
</fade-in-transition>
4440
<circle
41+
v-if="options.colorFill !== 'transparent'"
4542
class="ep-circle--progress__fill"
4643
:r="fillRadius"
4744
:cx="position"
@@ -51,6 +48,11 @@
5148
:style="{ transition: styles.transition }"
5249
>
5350
</circle>
51+
<fade-in-transition>
52+
<g v-if="isLoading">
53+
<circle-loader :options="options.loader" />
54+
</g>
55+
</fade-in-transition>
5456
<circle
5557
class="ep-circle--progress"
5658
:class="animationClass"

src/components/Circle/HalfCircle.vue

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
}"
99
>
1010
<path
11+
v-if="options.emptyColorFill !== 'transparent'"
1112
:fill="computedEmptyColorFill"
13+
class="ep-half-circle--empty__fill"
1214
:d="emptyFillPath"
1315
:style="{
1416
transition: styles.transition,
@@ -31,19 +33,19 @@
3133
:class="{ 'ep-circle--nodata': !dataIsAvailable }"
3234
>
3335
</path>
34-
<fade-in-transition>
35-
<g v-if="isLoading">
36-
<half-circle-loader :options="options.loader" />
37-
</g>
38-
</fade-in-transition>
39-
4036
<path
37+
v-if="options.colorFill !== 'transparent'"
4138
class="ep-half-circle--progress__fill"
4239
:d="fillPath"
4340
:fill="computedColorFill"
4441
:style="{ transition: styles.transition }"
4542
>
4643
</path>
44+
<fade-in-transition>
45+
<g v-if="isLoading">
46+
<half-circle-loader :options="options.loader" />
47+
</g>
48+
</fade-in-transition>
4749
<path
4850
:stroke-width="thickness"
4951
class="ep-half-circle--progress ep-circle--progress"

src/components/Circle/HalfCircleLoader.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:stroke-width="thickness"
55
class="ep-half-circle--loader animation__loading"
66
:d="path"
7-
:fill="computedColorFill"
7+
fill="transparent"
88
:stroke="computedColor"
99
:stroke-dasharray="circumference"
1010
:stroke-linecap="options.line"

src/components/Circle/circleMixin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { emptyRadius, fillRadius, radius } from "@/components/Circle/radiusCalculation";
2-
import { isValidNumber } from "../../utils";
2+
import { isValidNumber } from "@/utils";
33

44
const wait = (ms = 400) => new Promise((resolve) => setTimeout(() => resolve(), ms));
55

@@ -101,7 +101,7 @@ export default {
101101
},
102102

103103
dash() {
104-
return this.options.dot;
104+
return this.options.dash;
105105
},
106106
emptyDasharray() {
107107
if (!this.dash.count || !this.dash.spacing) {

src/components/interface.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { isValidNumber } from "@/utils";
2+
13
const colorConfig = (defaultColor = "transparent") => ({
24
type: [String, Object],
35
required: false,
46
default: defaultColor,
57
validator: (value) => {
6-
if (typeof value === "string" && value) {
7-
return true;
8+
if (typeof value === "string") {
9+
return value;
810
}
911
if (typeof value === "object" && value.colors) {
1012
return value.colors.every((config) => config.color && config.offset);
@@ -14,7 +16,12 @@ const colorConfig = (defaultColor = "transparent") => ({
1416
});
1517

1618
const validateLoaderProps = (loaderOptions) =>
17-
Object.keys(loaderOptions).every((option) => options[option].validator(loaderOptions[option]));
19+
Object.keys(loaderOptions).every((option) => {
20+
if (option === "opacity") {
21+
return isValidNumber(loaderOptions[option]) && loaderOptions[option] >= 0;
22+
}
23+
return options[option].validator(loaderOptions[option]);
24+
});
1825

1926
const linePosition = {
2027
type: String,

src/components/optionsParser.js

+24-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { getNumberIfValid, isValidNumber } from "@/utils";
22

3-
export const lineModeParser = (options) => {
4-
const lineModeConfig = options.lineMode.trim().split(" ");
5-
const mode = options.multiple ? "multiple" : lineModeConfig[0];
3+
export const lineModeParser = (lineMode, multiple) => {
4+
const lineModeConfig = lineMode.trim().split(" ");
5+
const mode = multiple ? "multiple" : lineModeConfig[0];
66
return {
77
mode,
88
offset: getNumberIfValid(lineModeConfig[1]) || 0,
99
};
1010
};
1111

12-
const animationParser = (animation) => {
12+
export const animationParser = (animation) => {
1313
const animationConfig = animation.trim().split(" ");
1414
return {
1515
type: animationConfig[0],
@@ -18,7 +18,7 @@ const animationParser = (animation) => {
1818
};
1919
};
2020

21-
const dashParser = (dash) => {
21+
export const dashParser = (dash) => {
2222
const dashConfig = dash.trim().split(" ");
2323
const isStrict = dashConfig[0] === "strict";
2424
if (!isStrict) {
@@ -30,7 +30,7 @@ const dashParser = (dash) => {
3030
};
3131
};
3232

33-
export const dotParser = (dot) => {
33+
export const dotParser = (dot, circleSize) => {
3434
let dotSize = 0;
3535
let dotColor = "white";
3636
let styles = {};
@@ -44,38 +44,34 @@ export const dotParser = (dot) => {
4444
}
4545
return {
4646
...styles,
47-
size: dotSize,
47+
size: calcThickness(dotSize, circleSize),
4848
color: dotColor,
4949
};
5050
};
5151

52-
export const calcThickness = (thickness, size) => {
52+
export const calcThickness = (thickness, circleSize) => {
5353
const value = parseFloat(thickness);
54-
return thickness.toString().includes("%") ? (value * size) / 100 : value;
54+
return thickness.toString().includes("%") ? (value * circleSize) / 100 : value;
5555
};
5656

57-
const parseLinePosition = (linePosition) => {
57+
export const linePositionParser = (linePosition) => {
5858
const [position, offset] = linePosition.toString().split(" ");
5959
return {
6060
position,
61-
offset: offset || 0,
61+
offset: parseFloat(offset) || 0,
6262
};
6363
};
6464

65-
export const parseOptions = (options) => {
66-
const dot = dotParser(options.dot);
67-
const globalDot = dotParser(options.globalDot);
68-
return {
69-
...options,
70-
thickness: calcThickness(options.thickness, options.size),
71-
emptyThickness: calcThickness(options.emptyThickness, options.size),
72-
globalThickness: calcThickness(options.globalThickness, options.size),
73-
dot: { ...dot, size: calcThickness(dot.size, options.size) },
74-
globalDot: { ...globalDot, size: calcThickness(globalDot.size, options.size) },
75-
dash: dashParser(options.dash),
76-
lineMode: lineModeParser(options),
77-
linePosition: parseLinePosition(options.linePosition),
78-
emptyLinePosition: parseLinePosition(options.emptyLinePosition),
79-
animation: animationParser(options.animation),
80-
};
81-
};
65+
export const parseOptions = (options) => ({
66+
...options,
67+
thickness: calcThickness(options.thickness, options.size),
68+
emptyThickness: calcThickness(options.emptyThickness, options.size),
69+
globalThickness: calcThickness(options.globalThickness, options.size),
70+
dot: dotParser(options.dot, options.size),
71+
globalDot: dotParser(options.globalDot, options.size),
72+
dash: dashParser(options.dash),
73+
lineMode: lineModeParser(options.lineMode, options.multiple),
74+
linePosition: linePositionParser(options.linePosition),
75+
emptyLinePosition: linePositionParser(options.emptyLinePosition),
76+
animation: animationParser(options.animation),
77+
});

tests/helper.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { mount } from "@vue/test-utils";
2+
3+
const mockProps = {
4+
id: 0,
5+
index: 0,
6+
multiple: false,
7+
data: [],
8+
progress: 50,
9+
legend: null,
10+
size: 200,
11+
thickness: 10,
12+
globalThickness: 10,
13+
emptyThickness: 10,
14+
line: "round",
15+
lineMode: {
16+
mode: "normal",
17+
offset: 0,
18+
},
19+
linePosition: {
20+
position: "center",
21+
offset: 0,
22+
},
23+
emptyLinePosition: {
24+
position: "center",
25+
offset: 0,
26+
},
27+
color: "#3f79ff",
28+
emptyColor: "#e6e9f0",
29+
colorFill: "transparent",
30+
emptyColorFill: "transparent",
31+
fontSize: null,
32+
fontColor: null,
33+
animation: {
34+
type: "default",
35+
duration: 1000,
36+
delay: 400,
37+
},
38+
hideLegend: true,
39+
legendClass: "",
40+
angle: -90,
41+
loading: false,
42+
noData: false,
43+
dash: "",
44+
half: false,
45+
gap: 0,
46+
globalGap: 0,
47+
determinate: false,
48+
dot: {
49+
size: 0,
50+
color: "white",
51+
},
52+
globalDot: {
53+
size: 0,
54+
color: "white",
55+
},
56+
reverse: false,
57+
legendFormatter: null,
58+
loader: {},
59+
previousCircles: [],
60+
};
61+
mockProps.loaderOptions = mockProps;
62+
63+
export { mockProps };
64+
65+
export const wait = (ms = 400) => new Promise((resolve) => setTimeout(() => resolve(), ms));
66+
67+
export const setCircleProps = async (wrapper, props = {}) => {
68+
return wrapper.setProps({ options: { ...wrapper.props("options"), ...props } });
69+
};
70+
export const factory = ({ container, props = {}, isCircleFactory = true }) => {
71+
const propsData = isCircleFactory ? { options: { ...mockProps, ...props } } : props;
72+
return mount(container, {
73+
propsData,
74+
});
75+
};

tests/unit/.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
rules: {
66
"no-unused-expressions": 0,
77
"no-multi-assign": 0,
8-
"no-unused-vars": 1,
8+
"no-unused-vars": "warn",
99
"prefer-destructuring": 0,
1010
"no-restricted-syntax": 0,
1111
"guard-for-in": 0,

0 commit comments

Comments
 (0)