Skip to content

Commit 5126dbd

Browse files
committed
test: add dot parser tests
1 parent ac9a2ea commit 5126dbd

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

tests/unit/container.spec.js

+29-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { shallowMount, mount } from "@vue/test-utils";
33
import VueEllipseProgress from "@/components/VueEllipseProgress.vue";
44
import CircleContainer from "@/components/Circle/CircleContainer.vue";
55
import Counter from "@/components/Counter.vue";
6+
import { dotParser } from "@/components/optionsParser";
67

78
const factory = (propsData, slots = {}) => {
89
return mount(VueEllipseProgress, {
@@ -225,39 +226,43 @@ describe("[ EllipseProgressContainer.vue ]", () => {
225226
});
226227
describe("Options parsers", () => {
227228
describe("#dot parser", () => {
229+
const circleSize = 200;
230+
it("applies default value correctly", () => {
231+
const { size, color } = dotParser(0, circleSize);
232+
expect(size).to.equal(0);
233+
expect(color).to.equal("white");
234+
});
228235
it(`parses property as Number correctly`, () => {
229-
const parsedDot = dotParser(0);
230-
expect(parsedDot.size).to.equal("0");
231-
expect(parsedDot.color).to.equal("white");
236+
const { size, color } = dotParser(5, circleSize);
237+
expect(size).to.equal(5);
238+
expect(color).to.equal("white");
232239
});
233240
it(`parses property as String correctly`, () => {
234-
const wrapper = localFactory({ progress, size, dot: dotParser("5% red") });
235-
expect(wrapper.vm.parsedDot.size).to.equal("5%");
236-
expect(wrapper.vm.parsedDot.color).to.equal("red");
241+
const { size, color } = dotParser("20 red", circleSize);
242+
expect(size).to.equal(20);
243+
expect(color).to.equal("red");
237244
});
238245
it(`parses property as Object correctly`, () => {
239-
const wrapper = localFactory({ progress, size, dot: dotParser({ size: 10, backgroundColor: "green" }) });
240-
expect(wrapper.vm.parsedDot.size).to.equal(10);
241-
expect(wrapper.vm.parsedDot.color).to.equal("white");
242-
expect(wrapper.vm.parsedDot.backgroundColor).to.equal("green");
246+
const { size, backgroundColor } = dotParser({ size: 10, backgroundColor: "green" }, circleSize);
247+
expect(size).to.equal(10);
248+
expect(backgroundColor).to.equal("green");
243249
});
244250

245251
it(`converts the size percent value to pixel correctly`, () => {
246-
const dot = "5%";
247-
const wrapper = localFactory({ progress, size, dot: dotParser(dot) });
248-
const dotPixelSize = calculateThickness(dot);
249-
expect(wrapper.vm.dotSize).to.equal(dotPixelSize);
252+
const { size } = dotParser("5%", circleSize);
253+
const dotPixelSize = (5 * circleSize) / 100;
254+
expect(size).to.equal(dotPixelSize);
250255
});
251-
it("applies default value correctly", () => {
252-
const wrapper = factory({ progress }, VueEllipseProgress);
253-
const circleWrapper = wrapper.findComponent(Circle);
254-
const circleContainerWrapper = wrapper.findComponent(CircleContainer);
255-
256-
expect(wrapper.props("dot")).to.equal(0);
257-
expect(circleContainerWrapper.props("dot")).to.equal(0);
258-
expect(circleWrapper.vm.parsedDot.size).to.equal("0");
259-
expect(circleWrapper.vm.parsedDot.color).to.equal("white");
260-
expect(circleWrapper.vm.dotSize).to.equal(0);
256+
it("parses custom styles correctly", () => {
257+
const dot = {
258+
size: 10,
259+
backgroundColor: "yellow",
260+
width: "15px",
261+
};
262+
const { size, width, backgroundColor } = dotParser(dot, circleSize);
263+
expect(size).to.equal(dot.size);
264+
expect(backgroundColor).to.equal(dot.backgroundColor);
265+
expect(width).to.equal(dot.width);
261266
});
262267
});
263268
});

0 commit comments

Comments
 (0)