Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 2604709

Browse files
Issue #670 - fix TINY mode for element-node with spaces in classname
1 parent 42f01cf commit 2604709

File tree

4 files changed

+151
-2
lines changed

4 files changed

+151
-2
lines changed

packages/devtools-reps/src/reps/element-node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ function getElements(grip, mode) {
9292
elements.push(
9393
span({className: "attr-name theme-fg-color2"},
9494
attributes.class
95-
.replace(/(^\s+)|(\s+$)/g, "")
96-
.split(" ")
95+
.trim()
96+
.split(/\s+/)
9797
.map(cls => `.${cls}`)
9898
.join("")
9999
)

packages/devtools-reps/src/reps/stubs/element-node.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ stubs.set("NodeWithLeadingAndTrailingSpacesClassName", {
107107
}
108108
});
109109

110+
stubs.set("NodeWithSpacesInClassName", {
111+
"type": "object",
112+
"actor": "server1.conn3.child1/obj59",
113+
"class": "HTMLBodyElement",
114+
"extensible": true,
115+
"frozen": false,
116+
"sealed": false,
117+
"ownPropertyLength": 0,
118+
"preview": {
119+
"kind": "DOMNode",
120+
"nodeType": 1,
121+
"nodeName": "body",
122+
"attributes": {
123+
"class": "a b c"
124+
},
125+
"attributesLength": 1
126+
}
127+
});
128+
110129
stubs.set("NodeWithoutAttributes", {
111130
"type": "object",
112131
"actor": "server1.conn1.child1/obj32",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ElementNode - Node with spaces in the class name renders with expected text content 1`] = `
4+
ShallowWrapper {
5+
"complexSelector": ComplexSelector {
6+
"buildPredicate": [Function],
7+
"childrenOfNode": [Function],
8+
"findWhereUnwrapped": [Function],
9+
},
10+
"length": 1,
11+
"node": <span
12+
className="objectBox objectBox-node"
13+
data-link-actor-id="server1.conn3.child1/obj59"
14+
>
15+
&lt;
16+
<span
17+
className="tag-name theme-fg-color3"
18+
>
19+
body
20+
</span>
21+
22+
<span>
23+
<span
24+
className="attr-name theme-fg-color2"
25+
>
26+
class
27+
</span>
28+
="
29+
<span
30+
className="attr-value theme-fg-color6"
31+
>
32+
a b c
33+
</span>
34+
"
35+
</span>
36+
&gt;
37+
</span>,
38+
"nodes": Array [
39+
<span
40+
className="objectBox objectBox-node"
41+
data-link-actor-id="server1.conn3.child1/obj59"
42+
>
43+
&lt;
44+
<span
45+
className="tag-name theme-fg-color3"
46+
>
47+
body
48+
</span>
49+
50+
<span>
51+
<span
52+
className="attr-name theme-fg-color2"
53+
>
54+
class
55+
</span>
56+
="
57+
<span
58+
className="attr-value theme-fg-color6"
59+
>
60+
a b c
61+
</span>
62+
"
63+
</span>
64+
&gt;
65+
</span>,
66+
],
67+
"options": Object {},
68+
"renderer": ReactShallowRenderer {
69+
"_instance": null,
70+
"getRenderOutput": [Function],
71+
"render": [Function],
72+
},
73+
"root": [Circular],
74+
"unrendered": <span
75+
className="objectBox objectBox-node"
76+
data-link-actor-id="server1.conn3.child1/obj59"
77+
>
78+
&lt;
79+
<span
80+
className="tag-name theme-fg-color3"
81+
>
82+
body
83+
</span>
84+
85+
<span>
86+
<span
87+
className="attr-name theme-fg-color2"
88+
>
89+
class
90+
</span>
91+
="
92+
<span
93+
className="attr-value theme-fg-color6"
94+
>
95+
a b c
96+
</span>
97+
"
98+
</span>
99+
&gt;
100+
</span>,
101+
}
102+
`;

packages/devtools-reps/src/reps/tests/element-node.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,34 @@ describe("ElementNode - Node with leading and trailing spaces class name", () =>
172172
});
173173
});
174174

175+
describe("ElementNode - Node with spaces in the class name", () => {
176+
const stub = stubs.get("NodeWithSpacesInClassName");
177+
178+
it("selects ElementNode Rep", () => {
179+
expect(getRep(stub)).toBe(ElementNode.rep);
180+
});
181+
182+
it("renders with expected text content", () => {
183+
const renderedComponent = shallow(ElementNode.rep({
184+
object: stub
185+
}));
186+
187+
// Using snapshot testing here, because enzyme -> shallow -> text() is not returning
188+
// the correct text representation of this React component.
189+
expect(renderedComponent).toMatchSnapshot();
190+
});
191+
192+
it("renders with expected text content in tiny mode", () => {
193+
const renderedComponent = shallow(ElementNode.rep({
194+
object: stub,
195+
mode: MODE.TINY
196+
}));
197+
198+
expect(renderedComponent.text())
199+
.toEqual("body.a.b.c");
200+
});
201+
});
202+
175203
describe("ElementNode - Node without attributes", () => {
176204
const stub = stubs.get("NodeWithoutAttributes");
177205

0 commit comments

Comments
 (0)