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
|
/* 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/>. */
import React from "devtools/client/shared/vendor/react";
import { shallow } from "enzyme";
import Group from "../Group.js";
import { makeMockFrame, makeMockSource } from "../../../../utils/test-mockup";
function render(overrides = {}) {
const frame = { ...makeMockFrame(), displayName: "foo", library: "Back" };
const defaultProps = {
group: [frame],
selectedFrame: frame,
frameworkGroupingOn: true,
toggleFrameworkGrouping: jest.fn(),
selectFrame: jest.fn(),
selectLocation: jest.fn(),
copyStackTrace: jest.fn(),
toggleBlackBox: jest.fn(),
disableContextMenu: false,
displayFullUrl: false,
panel: "webconsole",
restart: jest.fn(),
};
const props = { ...defaultProps, ...overrides };
const component = shallow(React.createElement(Group, props), {
context: { l10n: L10N },
});
return { component, props };
}
describe("Group", () => {
it("displays a group", () => {
const { component } = render();
expect(component).toMatchSnapshot();
});
it("passes the getFrameTitle prop to the Frame components", () => {
const mahscripts = makeMockSource("http://myfile.com/mahscripts.js");
const back = makeMockSource("http://myfile.com/back.js");
const group = [
{
...makeMockFrame("1", mahscripts, undefined, 55, "renderFoo"),
library: "Back",
},
{
...makeMockFrame("2", back, undefined, 55, "a"),
library: "Back",
},
{
...makeMockFrame("3", back, undefined, 55, "b"),
library: "Back",
},
];
const getFrameTitle = () => {};
const { component } = render({ group, getFrameTitle });
component.setState({ expanded: true });
const frameComponents = component.find("Frame");
expect(frameComponents).toHaveLength(3);
frameComponents.forEach(node => {
expect(node.prop("getFrameTitle")).toBe(getFrameTitle);
});
expect(component).toMatchSnapshot();
});
it("renders group with anonymous functions", () => {
const mahscripts = makeMockSource("http://myfile.com/mahscripts.js");
const back = makeMockSource("http://myfile.com/back.js");
const group = [
{
...makeMockFrame("1", mahscripts, undefined, 55),
library: "Back",
},
{
...makeMockFrame("2", back, undefined, 55),
library: "Back",
},
{
...makeMockFrame("3", back, undefined, 55),
library: "Back",
},
];
const { component } = render({ group });
expect(component).toMatchSnapshot();
component.setState({ expanded: true });
expect(component).toMatchSnapshot();
});
});
|