-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlegacy.test.ts
118 lines (95 loc) · 3.01 KB
/
legacy.test.ts
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
109
110
111
112
113
114
115
116
117
118
import blobs, {BlobOptions} from "./legacy";
const genMinimalOptions = (): BlobOptions => ({
size: 1000 * Math.random(),
complexity: 1 - Math.random(),
contrast: 1 - Math.random(),
color: "#fff",
});
describe("legacy", () => {
it("should return a different result when seed is not provided", () => {
const options = genMinimalOptions();
const a = blobs(options);
const b = blobs(options);
expect(a).not.toEqual(b);
});
it("should return the same result when the seed is provided", () => {
const options = genMinimalOptions();
options.seed = "abcde";
const a = blobs(options);
const b = blobs(options);
expect(a).toEqual(b);
});
it("should require options be provided", () => {
expect(() => (blobs as any)()).toThrow("options");
});
it("should require a size be provided", () => {
const options = genMinimalOptions();
delete (options as any).size;
expect(() => blobs(options)).toThrow("size");
});
it("should reject out of range complexity values", () => {
const options = genMinimalOptions();
options.complexity = 1234;
expect(() => blobs(options)).toThrow("complexity");
options.complexity = 0;
expect(() => blobs(options)).toThrow("complexity");
});
it("should reject out of range contrast values", () => {
const options = genMinimalOptions();
options.contrast = 999;
expect(() => blobs(options)).toThrow("contrast");
options.contrast = -1;
expect(() => blobs(options)).toThrow("contrast");
});
it("should reject options without stroke or color", () => {
const options = genMinimalOptions();
delete options.stroke;
delete options.color;
expect(() => blobs(options)).toThrow("stroke");
expect(() => blobs(options)).toThrow("color");
});
});
describe("editable", () => {
it("should reflect changes when edited", () => {
const options = genMinimalOptions();
const out = blobs.editable(options);
const initial = out.render();
out.attributes.id = "test";
const modified = out.render();
expect(modified).not.toBe(initial);
});
});
// Sanity checks to ensure the output remains consistent
// across changes to the source.
const testCases: Record<string, BlobOptions> = {
fill: {
size: 109,
complexity: 0.1,
contrast: 0.331,
color: "red",
seed: "fill",
},
stroke: {
size: 226,
complexity: 0.91,
contrast: 0.6,
stroke: {
color: "#ff00bb",
width: 3.8,
},
seed: "stroke",
},
guides: {
size: 781,
complexity: 1,
contrast: 0.331,
color: "yellow",
guides: true,
seed: "guides",
},
};
for (const testCase of Object.keys(testCases)) {
test(testCase, () => {
expect(blobs(testCases[testCase])).toMatchSnapshot();
});
}