Skip to content

Commit bce276e

Browse files
committed
fix: correctly handle skipped animation
1 parent ab8394d commit bce276e

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

src/App.vue

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
<input type="checkbox" v-model="circles[3].loading" />
4545
</div>-->
4646
<div style="border: 1px solid red; display: inline-block">
47-
<ve-progress :progress="progress" animation="bounce 3000 300" :legend-formatter="customFormatter"
47+
<ve-progress :progress="progress" animation="default 0 0" :legend="120" :legend-formatter="({ currentValue }) => `Formatted: ${currentValue}`">
48+
</ve-progress>
49+
50+
<!-- <ve-progress :progress="progress" animation="bounce 3000 300" :legend-formatter="customFormatter"
4851
:loading="loading">
4952
<template #legend>
5053
<span id="my-slot">Hello Circle</span>
@@ -68,7 +71,7 @@
6871
fill="transparent"
6972
:style="attrs.styles"
7073
/>
71-
<!-- <line
74+
&lt;!&ndash; <line
7275
ref="polygon"
7376
:stroke-dashoffset="attrs.strokeDashOffset / 4"
7477
:stroke-dasharray="lineLength"
@@ -80,7 +83,7 @@
8083
stroke="blue"
8184
stroke-width="4"
8285
fill="none"
83-
/>-->
86+
/>&ndash;&gt;
8487
</template>
8588
<template #legend>
8689
<span id="my-slot">Hello custom Circle</span>
@@ -173,7 +176,7 @@
173176
<template #legend>
174177
<span id="my-slot">Hello custom Circle</span>
175178
</template>
176-
</ve-progress>
179+
</ve-progress>-->
177180
<!-- <ve-progress
178181
:progress="progress"
179182
:determinate="determinate"

src/components/Circle/circleMixin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export default {
166166
circle.addEventListener("animationstart", this.toggleIsAnimationPlaying, false);
167167
circle.addEventListener("animationend", this.toggleIsAnimationPlaying, false);
168168
}
169-
if (!this.options.loading) {
169+
if (this.options.animation.delay && !this.options.loading) {
170170
// await initial delay before applying animations
171171
await wait(this.options.animation.delay);
172172
}

src/components/Counter.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default {
134134
},
135135
},
136136
mounted() {
137-
if (!this.loading) {
137+
if (!this.loading && this.duration) {
138138
setTimeout(() => {
139139
this.raf = requestAnimationFrame(this.count);
140140
}, this.delay);

src/components/optionsParser.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export const lineModeParser = (lineMode, multiple) => {
1111

1212
export const animationParser = (animation) => {
1313
const animationConfig = animation.trim().split(" ");
14+
const duration = isValidNumber(animationConfig[1]) ? parseFloat(animationConfig[1]) : 1000;
15+
const delay = isValidNumber(animationConfig[2]) ? parseFloat(animationConfig[2]) : 400;
1416
return {
1517
type: animationConfig[0],
16-
duration: isValidNumber(animationConfig[1]) ? parseFloat(animationConfig[1]) : 1000,
17-
delay: isValidNumber(animationConfig[2]) ? parseFloat(animationConfig[2]) : 400,
18+
duration: duration >= 0 ? duration : 0,
19+
delay: delay >= 0 ? delay : 0,
1820
};
1921
};
2022

tests/unit/container.spec.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CircleContainer from "@/components/Circle/CircleContainer.vue";
55
import Counter from "@/components/Counter.vue";
66
import { animationParser, dotParser, dashParser, lineModeParser, linePositionParser } from "@/components/optionsParser";
77
import props from "@/components/interface";
8-
import { defaultCounterTick } from "@/../tests/helper";
8+
import { defaultCounterTick, wait } from "@/../tests/helper";
99
import { nextTick } from "vue";
1010

1111
const factory = (propsData, slots = {}) => {
@@ -251,14 +251,15 @@ describe("[ EllipseProgressContainer.vue ]", () => {
251251
};
252252
factory({ progress: 1, legendFormatter: formatter, animation: "default 0 0" });
253253
});
254-
it("renders the custom formatted value", (done) => {
254+
it("renders the custom formatted value", async () => {
255255
const customFormat = (value) => `Formatted: ${value}`;
256256
const formatter = ({ currentValue }) => customFormat(currentValue);
257257
const wrapper = factory({ legend: 120, legendFormatter: formatter, animation: "default 0 0" });
258-
setTimeout(() => {
259-
expect(wrapper.find(".ep-legend--value__counter").element.textContent).to.equal(customFormat(120));
260-
done();
261-
}, 100);
258+
259+
await wait(200);
260+
await nextTick();
261+
262+
expect(wrapper.find(".ep-legend--value__counter").element.textContent).to.equal(customFormat(120));
262263
});
263264
it("isHTML returns false by default ", () => {
264265
expect(factory({ legendFormatter: () => "Custom" }).vm.isHTML).to.be.false;

tests/unit/counter.spec.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { expect } from "chai";
22
import { mount } from "@vue/test-utils";
33
import Counter from "@/components/Counter.vue";
44
import VueEllipseProgress from "@/components/VueEllipseProgress.vue";
5+
import { nextTick } from "vue";
6+
import { wait } from "../helper";
57

68
const factory = (propsData, slots) => {
79
return mount(VueEllipseProgress, {
@@ -31,15 +33,17 @@ global.cancelAnimationFrame = (id) => clearTimeout(id);
3133

3234
describe("[ Counter.vue ]", () => {
3335
describe("#value", async () => {
34-
it("renders the final value correctly", (done) => {
36+
it("renders the final value correctly", async () => {
3537
const counterWrapper = factory({
3638
legend: "50.00",
3739
animation: `default 0 0`,
3840
}).findComponent(Counter);
39-
setTimeout(() => {
40-
expect(counterWrapper.element.textContent).to.equal("50.00");
41-
}, 100);
42-
done();
41+
42+
// need to await RAF tick, tests is flaky
43+
await wait(200);
44+
await nextTick();
45+
46+
expect(counterWrapper.element.textContent).to.equal("50.00");
4347
});
4448

4549
const values = [

0 commit comments

Comments
 (0)