Skip to content

Commit 4676b1a

Browse files
committed
test: fix data tests
1 parent 61901ab commit 4676b1a

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/App.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@
6060
</ve-progress>
6161
</div>
6262
<ve-progress
63-
dot="20 green"
6463
:loading="loading"
6564
:size="200"
66-
:progress="progress"
65+
:thickness="10"
66+
:progress="50"
6767
:legend-value="125.1"
6868
half
69-
line-mode="out 20"
7069
:no-data="noData"
7170
:determinate="determinate"
7271
:loader="{ thickness: 40, color: 'red' }"

tests/unit/circle/circle.spec.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { expect } from "chai";
2-
import Vue from "vue";
32
import Circle from "@/components/Circle/Circle.vue";
43
import HalfCircle from "@/components/Circle/HalfCircle.vue";
54
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";
87

98
const localFactory = (props, container = Circle) => factory({ container, props });
109

@@ -50,6 +49,7 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
5049
it("lets progress circle visible for -1 < progress < 1", async () => {
5150
progress = 0;
5251
await wrapper.setProps({ options: { ...wrapper.props().options, half: true } });
52+
await setCircleProps(wrapper, { half: true });
5353
const radius = size / 2 - thickness / 2;
5454
const circumference = radius * 2 * Math.PI;
5555

@@ -126,16 +126,12 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
126126
});
127127

128128
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-
132129
expect(circleProgressWrapper.element.getAttribute("d")).to.equal(`${expectedPath}`);
133130
expect(circleEmptyWrapper.element.getAttribute("d")).to.equal(`${expectedPath}`);
134131
});
135132
it("calculates the progress circle stroke offset correctly", async () => {
136133
const circumference = (radius * 2 * Math.PI) / 2;
137134
const expectedOffset = circumference - (progress / 100) * circumference;
138-
expect(wrapper.vm.progressOffset).to.equal(expectedOffset);
139135
expect(circleProgressWrapper.element.style.strokeDashoffset).to.equal(`${expectedOffset}`);
140136
});
141137
});
@@ -235,21 +231,19 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
235231
it("sets the rotation of the svg container correctly", async () => {
236232
const angle = 80;
237233
await circleWrapper.setProps({ options: { ...circleWrapper.props().options, angle } });
238-
await Vue.nextTick();
239234
expect(circleWrapper.element.style.transform).to.equal(`rotate(${angle}deg)`);
240235
});
241236
it("sets @0 value as the rotation of the svg container correctly", async () => {
242237
const angle = 0;
243238
await circleWrapper.setProps({ options: { ...circleWrapper.props().options, angle } });
244-
await Vue.nextTick();
245239
expect(circleWrapper.element.style.transform).to.equal(`rotate(${angle}deg)`);
246240
});
247241
});
248242
describe("#data", () => {
249243
const size = 600;
250244
const globalThickness = 5;
251245
const globalGap = 5;
252-
const globalDot = "2%";
246+
const globalDot = dotParser("2%", size);
253247

254248
const data = [];
255249
// generate random test data
@@ -273,22 +267,29 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
273267

274268
const wrapper = factory({
275269
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+
},
277277
isCircleFactory: false,
278278
});
279279
const circleWrappers = wrapper.findAllComponents(Circle);
280280

281-
const calculateThickness = (t) => (t.toString().includes("%") ? (parseFloat(t) * size) / 100 : t);
281+
// const calculateThickness = (t) => (t.toString().includes("%") ? (parseFloat(t) * size) / 100 : t);
282282

283283
for (let i = 0; i < data.length; i++) {
284284
const circleData = data[i];
285285
it(`calculates the radius of circle #${i} correctly
286286
#thickness ${circleData.thickness} | #gap ${circleData.gap} | #dot ${circleData.dot} `, () => {
287287
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
290291
);
291-
const circleDot = calculateThickness(dotParser(circleData.dot !== undefined ? circleData.dot : globalDot).size);
292+
const circleDot = dotParser(circleData.dot !== undefined ? circleData.dot : globalDot, size).size;
292293

293294
let radius;
294295
const baseRadius = size / 2 - Math.max(circleThickness, circleDot) / 2;
@@ -297,8 +298,8 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
297298
const previousCirclesThickness = previousCirclesData
298299
.map(({ gap, thickness, dot }, n) => {
299300
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;
302303
const thicknessWithDot = Math.max(t, d);
303304
return n > 0 ? g + thicknessWithDot : thicknessWithDot;
304305
})
@@ -308,8 +309,8 @@ describe("[ CircleProgress.vue | HalfCircleProgress.vue ]", () => {
308309
} else {
309310
radius = baseRadius;
310311
}
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");
313314
expect(circleProgressWrapper.element.getAttribute("r")).to.equal(`${radius}`);
314315
expect(circleEmptyWrapper.element.getAttribute("r")).to.equal(`${radius}`);
315316
});

0 commit comments

Comments
 (0)