Skip to content

Commit daebcfd

Browse files
codehagjasonLaster
authored andcommitted
Merge pull request firefox-devtools#3543 from devtools-html/debugger.html/bug/3496-expressions-should-have-a-unique-key
[Expressions] should have a unique key
1 parent 139f4ff commit daebcfd

8 files changed

Lines changed: 1046 additions & 22 deletions

File tree

src/components/PrimaryPanes/SourcesTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class SourcesTree extends Component {
259259
return [];
260260
},
261261
getRoots: () => sourceTree.contents,
262-
getKey: (item, i) => item.path,
262+
getPath: item => item.path,
263263
itemHeight: 21,
264264
autoExpandDepth: 1,
265265
autoExpandAll: false,

src/components/ProjectSearch/TextSearch.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export default class TextSearch extends Component {
166166
renderResults() {
167167
const { results } = this.props;
168168
results = results.filter(result => result.matches.length > 0);
169+
function getFilePath(item) {
170+
return item.filepath
171+
? `${item.sourceId}`
172+
: `${item.sourceId}-${item.line}-${item.column}`;
173+
}
174+
169175
return ManagedTree({
170176
getRoots: () => results,
171177
getChildren: file => {
@@ -176,10 +182,7 @@ export default class TextSearch extends Component {
176182
autoExpandDepth: 1,
177183
focused: results[0],
178184
getParent: item => null,
179-
getKey: item =>
180-
item.filepath
181-
? `${item.sourceId}`
182-
: `${item.sourceId}-${item.line}-${item.column}`,
185+
getPath: getFilePath,
183186
renderItem: (item, depth, focused, _, expanded, { setExpanded }) =>
184187
item.filepath
185188
? this.renderFile(item, focused, expanded, setExpanded)

src/components/SecondaryPanes/ChromeScopes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class Scopes extends Component {
186186
getParent: item => null,
187187
getChildren: this.getChildren,
188188
getRoots: () => roots,
189-
getKey: item => item.path,
189+
getPath: item => item.path,
190190
autoExpand: 0,
191191
autoExpandDepth: 1,
192192
autoExpandAll: false,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from "react";
2+
import { shallow } from "enzyme";
3+
import Expressions from "../Expressions";
4+
5+
const ExpressionsComponent = React.createFactory(Expressions.WrappedComponent);
6+
7+
function generateDefaults(overrides) {
8+
return {
9+
loadObjectProperties: jest.fn(),
10+
expressions: [
11+
{
12+
input: "expression1",
13+
value: {
14+
result: {
15+
value: "foo",
16+
class: ""
17+
}
18+
}
19+
},
20+
{
21+
input: "expression2",
22+
value: {
23+
result: {
24+
value: "bar",
25+
class: ""
26+
}
27+
}
28+
}
29+
],
30+
...overrides
31+
};
32+
}
33+
34+
function render(overrides = {}) {
35+
const props = generateDefaults(overrides);
36+
const component = shallow(new ExpressionsComponent(props));
37+
return { component, props };
38+
}
39+
40+
describe("Expressions", () => {
41+
it("should render", async () => {
42+
const { component } = render();
43+
expect(component).toMatchSnapshot();
44+
});
45+
46+
it("should always have unique keys", async () => {
47+
const overrides = {
48+
expressions: [
49+
{
50+
input: "expression1",
51+
value: {
52+
result: {
53+
value: undefined,
54+
class: ""
55+
}
56+
}
57+
},
58+
{
59+
input: "expression2",
60+
value: {
61+
result: {
62+
value: undefined,
63+
class: ""
64+
}
65+
}
66+
}
67+
]
68+
};
69+
70+
const { component } = render(overrides);
71+
expect(component).toMatchSnapshot();
72+
});
73+
});

0 commit comments

Comments
 (0)