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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
"use strict";
const { shallow } = require("enzyme");
const {
REPS,
getRep,
} = require("resource://devtools/client/shared/components/reps/reps/rep.js");
const {
MODE,
} = require("resource://devtools/client/shared/components/reps/reps/constants.js");
const { ArrayRep, Rep } = REPS;
const { maxLengthMap } = ArrayRep;
describe("Array", () => {
it("selects Array Rep as expected", () => {
const stub = [];
expect(getRep(stub, undefined, true)).toBe(ArrayRep.rep);
});
it("renders empty array as expected", () => {
const object = [];
const renderRep = props => shallow(Rep({ object, noGrip: true, ...props }));
const defaultOutput = "[]";
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: undefined }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.TINY }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
it("renders basic array as expected", () => {
const object = [1, "foo", {}];
const renderRep = props => shallow(Rep({ object, noGrip: true, ...props }));
const defaultOutput = '[ 1, "foo", {} ]';
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: undefined }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]");
expect(renderRep({ mode: MODE.TINY }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
it("renders array with more than SHORT mode max props as expected", () => {
const object = Array(maxLengthMap.get(MODE.SHORT) + 1).fill("foo");
const renderRep = props => shallow(Rep({ object, noGrip: true, ...props }));
const defaultShortOutput = `[ ${Array(maxLengthMap.get(MODE.SHORT))
.fill('"foo"')
.join(", ")}, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultShortOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]");
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultShortOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(
`[ ${Array(maxLengthMap.get(MODE.SHORT) + 1)
.fill('"foo"')
.join(", ")} ]`
);
});
it("renders array with more than LONG mode maximum props as expected", () => {
const object = Array(maxLengthMap.get(MODE.LONG) + 1).fill("foo");
const renderRep = props => shallow(Rep({ object, noGrip: true, ...props }));
const defaultShortOutput = `[ ${Array(maxLengthMap.get(MODE.SHORT))
.fill('"foo"')
.join(", ")}, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultShortOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]");
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultShortOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(
`[ ${Array(maxLengthMap.get(MODE.LONG)).fill('"foo"').join(", ")}, … ]`
);
});
it("renders recursive array as expected", () => {
const object = [1];
object.push(object);
const renderRep = props => shallow(Rep({ object, noGrip: true, ...props }));
const defaultOutput = "[ 1, […] ]";
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: undefined }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]");
expect(renderRep({ mode: MODE.TINY }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
it("renders array containing an object as expected", () => {
const object = [
{
p1: "s1",
p2: ["a1", "a2", "a3"],
p3: "s3",
p4: "s4",
},
];
const renderRep = props => shallow(Rep({ object, noGrip: true, ...props }));
const defaultOutput = "[ {…} ]";
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: undefined }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]");
expect(renderRep({ mode: MODE.TINY }).prop("title")).toBe("Array");
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
});
|