Skip to content

Commit 55cb952

Browse files
committed
fix: improve passed counter props to formatter
1 parent c9159b4 commit 55cb952

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

src/components/VueEllipseProgress.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</template>
3636

3737
<script>
38-
import { getNumberIfValid, isValidNumber } from "../utils";
38+
import { getNumberIfValid, isValidNumber, defaultCounterTick } from "../utils";
3939
import props from "./interface";
4040
import CircleContainer from "./Circle/CircleContainer.vue";
4141
import Counter from "./Counter.vue";
@@ -62,7 +62,7 @@ export default {
6262
return this.data.length > 1;
6363
},
6464
isHTML() {
65-
return /<[a-z/][\s\S]*>/i.test((this.legendFormatter({}) || "").toString().trim());
65+
return /<[a-z/][\s\S]*>/i.test((this.legendFormatter(defaultCounterTick) || "").toString().trim());
6666
},
6767
circlesData() {
6868
if (this.isMultiple) {

src/utils.js

+16
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,20 @@ const getNumberIfValid = (prop) => {
77
return false;
88
};
99

10+
export const defaultCounterTick = {
11+
currentValue: 0,
12+
countProgress: 0,
13+
currentFormattedValue: "0",
14+
currentRawValue: 0,
15+
duration: 0,
16+
previousCountStepValue: 0,
17+
start: 0,
18+
end: 0,
19+
difference: 0,
20+
currentDifference: 0,
21+
oneStepDifference: 0,
22+
startTime: 0,
23+
elapsed: 0,
24+
};
25+
1026
export { getNumberIfValid, isValidNumber };

tests/helper.js

+16
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ const mockProps = {
8787
};
8888
mockProps.loader = mockProps;
8989

90+
export const defaultCounterTick = {
91+
currentValue: 0,
92+
countProgress: 0,
93+
currentFormattedValue: "0",
94+
currentRawValue: 0,
95+
duration: 0,
96+
previousCountStepValue: 0,
97+
start: 0,
98+
end: 0,
99+
difference: 0,
100+
currentDifference: 0,
101+
oneStepDifference: 0,
102+
startTime: 0,
103+
elapsed: 0,
104+
};
105+
90106
export { mockProps };
91107

92108
export const wait = (ms = 400) => new Promise((resolve) => setTimeout(() => resolve(), ms));

tests/unit/container.spec.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +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";
89

910
const factory = (propsData, slots = {}) => {
1011
return mount(VueEllipseProgress, {
@@ -193,12 +194,13 @@ describe("[ EllipseProgressContainer.vue ]", () => {
193194
expect(counterTickData).to.be.an("object");
194195
return "Nice!";
195196
};
196-
factory({ legend: 120, legendFormatter: formatter, animation: "default 0 0" });
197+
factory({ legendFormatter: formatter, animation: "default 0 0" });
197198
});
198199
it("passes at least progress and currentValue properties to #legendFormatter", () => {
199200
const formatter = (counterTick) => {
200-
expect(counterTick.currentValue).to.be.a("number");
201-
// expect(counterTick.progress).to.be.a("number");
201+
for (const prop in defaultCounterTick) {
202+
expect(counterTick).to.have.a.property(prop);
203+
}
202204
return "Nice!";
203205
};
204206
factory({ progress: 1, legendFormatter: formatter, animation: "default 0 0" });

0 commit comments

Comments
 (0)