Skip to content

Commit 3a49c4f

Browse files
committed
test: add animation parser tests
1 parent 5126dbd commit 3a49c4f

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

tests/unit/container.spec.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { expect } from "chai";
2-
import { shallowMount, mount } from "@vue/test-utils";
2+
import { 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";
6+
import { animationParser, dotParser } from "@/components/optionsParser";
7+
import props from "@/components/interface";
78

89
const factory = (propsData, slots = {}) => {
910
return mount(VueEllipseProgress, {
@@ -265,5 +266,46 @@ describe("[ EllipseProgressContainer.vue ]", () => {
265266
expect(width).to.equal(dot.width);
266267
});
267268
});
269+
describe("#animation parser", () => {
270+
it("applies default #animation value", () => {
271+
const defaultAnimation = {
272+
type: "default",
273+
duration: 1000,
274+
delay: 400,
275+
};
276+
const parsedAnimation = animationParser(props.animation.default);
277+
for (const prop in defaultAnimation) {
278+
expect(parsedAnimation[prop]).to.equal(defaultAnimation[prop]);
279+
}
280+
});
281+
it("parses #animation correctly", () => {
282+
const { type, duration, delay } = animationParser("rs 500 300");
283+
expect(type).to.equal("rs");
284+
expect(duration).to.equal(500);
285+
expect(delay).to.equal(300);
286+
});
287+
it("parses #animation correctly with default duration", () => {
288+
const { type, duration } = animationParser("bounce");
289+
expect(type).to.equal("bounce");
290+
expect(duration).to.equal(animationParser(props.animation.default).duration);
291+
});
292+
it("parses #animation correctly with default delay", () => {
293+
const { type, duration, delay } = animationParser("bounce 2000");
294+
expect(type).to.equal("bounce");
295+
expect(duration).to.equal(2000);
296+
expect(delay).to.equal(animationParser(props.animation.default).delay);
297+
});
298+
it("parses #animation incorrectly with wrong arguments order", () => {
299+
const { type, duration, delay } = animationParser("300 rs 2000");
300+
expect(type).to.not.equal("rs");
301+
expect(duration).to.not.equal(300);
302+
expect(delay).to.equal(2000);
303+
});
304+
it("applies default values for duration and delay if invalid values provided", () => {
305+
const { duration, delay } = animationParser("loop 20%0 sdf");
306+
expect(duration).to.not.equal(animationParser(props.animation.default).duration);
307+
expect(delay).to.equal(animationParser(props.animation.default).delay);
308+
});
309+
});
268310
});
269311
});

0 commit comments

Comments
 (0)