Skip to content

Commit 5afac40

Browse files
committed
test: extend counter tests
1 parent 75f4855 commit 5afac40

File tree

2 files changed

+73
-45
lines changed

2 files changed

+73
-45
lines changed

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<div style="border: 1px solid red; display: inline-block">
4141
<!-- <ve-progress :progress="progress" animation="rs 2000 2000" :legend-formatter="customFormatter">
4242
</ve-progress>-->
43-
<ve-progress :progress="progress" animation="default 2500 1000" :legend="-123"></ve-progress>
43+
<ve-progress :progress="progress" animation="default 2500 1000" :legend="-123.1"></ve-progress>
4444
</div>
4545
</div>
4646
</div>

tests/unit/counter.spec.js

+72-44
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,59 @@ describe("[ Counter.vue ]", () => {
3333
describe("#value", async () => {
3434
it("renders the final value correctly", (done) => {
3535
const counterWrapper = factory({
36-
legend: 50,
36+
legend: "50.00",
3737
animation: `default 0 0`,
3838
}).findComponent(Counter);
3939
setTimeout(() => {
40-
expect(counterWrapper.element.textContent).to.equal("50");
40+
expect(counterWrapper.element.textContent).to.equal("50.00");
4141
}, 100);
4242
done();
4343
});
4444

4545
const values = [
4646
{
4747
legend: -45.2456,
48-
count: 4,
48+
decimalsCount: 4,
4949
start: "0.0000",
5050
},
5151
{
5252
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,
5479
start: "00.00",
5580
},
5681
{
5782
legend: "25,564",
58-
count: 3,
83+
decimalsCount: 3,
5984
start: "00,000",
6085
},
6186
{
6287
legend: "-30,5",
63-
count: 1,
88+
decimalsCount: 1,
6489
start: "0,0",
6590
},
6691
];
@@ -69,57 +94,60 @@ describe("[ Counter.vue ]", () => {
6994
delay: 1000,
7095
};
7196
for (const val of values) {
72-
const { legend, count, start } = val;
97+
const { legend, decimalsCount, start } = val;
7398
const wrapper = factory({
7499
legend,
75100
animation: `default ${animation.duration} ${animation.delay}`,
76101
});
77-
const counterWrapper = wrapper.findComponent(Counter);
78102

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);
86105

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);
90108
});
91109

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);
94112
});
95113

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+
});
100118

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+
});
107122

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+
}
116127

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+
});
123151
});
124152
}
125153
});

0 commit comments

Comments
 (0)