-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathel.spec.js
58 lines (48 loc) · 1.76 KB
/
el.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import chai from "chai";
import { flatMapL, mapL } from "fxjs/es";
import { $$getAttrNS } from "../getAttrNS/getAttrNS.index.js";
import { $$el } from "./el.index.js";
const { expect } = chai;
const MOCK_STR = `<circle cx="10" cy="20" r="30"></circle>`;
const setupSVGList = () => [
undefined,
document.createElementNS("http://www.w3.org/2000/svg", "svg"),
];
const expectElFromMockStr = ($el) => {
expect($el).instanceof(SVGElement);
expect($el.nodeName.toLowerCase()).equal("circle");
expect($$getAttrNS("cx")($el)).equal("10");
expect($$getAttrNS("cy")($el)).equal("20");
expect($$getAttrNS("r")($el)).equal("30");
};
export default ({ describe, it }) => [
describe(`$$el`, function () {
it(`The return value is a SVG element using the input SVG string.`, function () {
for (const $svg of setupSVGList()) {
const $el = $$el(MOCK_STR)($svg);
expectElFromMockStr($el);
}
});
it(`The return value is the first element from the input SVG string.
All other elements will be ignored.`, function () {
const svg_str = `${MOCK_STR}
<rect x="100" y="110" width="120" height="130"></rect>`;
for (const $svg of setupSVGList()) {
const $el = $$el(svg_str)($svg);
expectElFromMockStr($el);
expect($el.nodeName.toLowerCase()).not.equal("rect");
}
});
it(`The return value is undefined
when the input SVG string is empty string or there is no input SVG string.`, function () {
const cases = flatMapL(
($svg) => mapL((svg_str) => ({ svg_str, $svg }), ["", undefined]),
setupSVGList()
);
for (const { $svg, svg_str } of cases) {
const $el = $$el(svg_str)($svg);
expect($el).undefined;
}
});
}),
];