-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateScaleTransform.sepc.js
108 lines (84 loc) · 3.88 KB
/
updateScaleTransform.sepc.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import chai from "chai";
import { mapL, rangeL } from "fxjs/es";
import {
expectSameValueSVGTransform,
expectTransformWithScaleSxSy,
} from "../../test/assertions/index.js";
import {
makeRandomNumber,
makeRandomSVGMatrix,
} from "../../test/utils/index.js";
import { $$createSVGTransformMatrix } from "../createSVGTransformMatrix/createSVGTransformMatrix.index.js";
import { $$createSVGTransformRotate } from "../createSVGTransformRotate/createSVGTransformRotate.index.js";
import { $$createSVGTransformScale } from "../createSVGTransformScale/createSVGTransformScale.index.js";
import { $$createSVGTransformTranslate } from "../createSVGTransformTranslate/createSVGTransformTranslate.index.js";
import { $$updateScaleTransform } from "./updateScaleTransform.index.js";
const { expect } = chai;
const setupMockTransform = () => {
const [sx, sy] = mapL(() => makeRandomNumber(-100, 100), rangeL(2));
const transform = $$createSVGTransformScale({ sx, sy })();
return { transform, sx, sy };
};
const setupMockInputValues = () => ({
sx: makeRandomNumber(-100, 100),
sy: makeRandomNumber(-100, 100),
});
export default ({ describe, it }) => [
describe(`$$updateScaleTransform`, function () {
it(`The sx, sy of the input transform is changed to input angle, sx, sy.`, function () {
const { transform } = setupMockTransform();
const { sx, sy } = setupMockInputValues();
$$updateScaleTransform({ sx, sy })(transform);
expectTransformWithScaleSxSy({ transform, sx, sy });
});
it(`The sx of the transform is same with before when there is no input sx.`, function () {
const { transform, sx } = setupMockTransform();
const { sy } = setupMockInputValues();
$$updateScaleTransform({ sy })(transform);
expectTransformWithScaleSxSy({ transform, sx, sy });
});
it(`The sy of the transform is same with before when there is no input sy.`, function () {
const { transform, sy } = setupMockTransform();
const { sx } = setupMockInputValues();
$$updateScaleTransform({ sx })(transform);
expectTransformWithScaleSxSy({ transform, sx, sy });
});
it(`The sx, sy of the transform is same with before when there is no input object.`, function () {
const { transform, sx, sy } = setupMockTransform();
$$updateScaleTransform()(transform);
expectTransformWithScaleSxSy({ transform, sx, sy });
});
describe(`If the transform is another type transform, the function will do nothing but return the input.`, function () {
it(`When the transform is a matrix transform...`, function () {
const before_t = $$createSVGTransformMatrix({
matrix: makeRandomSVGMatrix(() => makeRandomNumber(-100, 100)),
})();
const { sx, sy } = setupMockInputValues();
const after_t = $$updateScaleTransform({ sx, sy })(before_t);
expect(after_t).equal(before_t);
expectSameValueSVGTransform(after_t, before_t);
});
it(`When the transform is a rotate transform...`, function () {
const before_t = $$createSVGTransformRotate({
angle: makeRandomNumber(-700, 700),
cx: makeRandomNumber(-100, 100),
cy: makeRandomNumber(-100, 100),
})();
const { sx, sy } = setupMockInputValues();
const after_t = $$updateScaleTransform({ sx, sy })(before_t);
expect(after_t).equal(before_t);
expectSameValueSVGTransform(after_t, before_t);
});
it(`When the transform is a translate transform...`, function () {
const before_t = $$createSVGTransformTranslate({
tx: makeRandomNumber(-100, 100),
ty: makeRandomNumber(-100, 100),
})();
const { sx, sy } = setupMockInputValues();
const after_t = $$updateScaleTransform({ sx, sy })(before_t);
expect(after_t).equal(before_t);
expectSameValueSVGTransform(after_t, before_t);
});
});
}),
];