summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/components/SecondaryPanes/Breakpoints/tests/BreakpointsContextMenu.spec.js
blob: 87194f762d8db3ad006df68b1d9c3fb6c98989a2 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* 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 "react";
import { shallow } from "enzyme";

import BreakpointsContextMenu from "../BreakpointsContextMenu";
import { buildMenu } from "../../../../context-menu/menu";

import {
  makeMockBreakpoint,
  makeMockSource,
  mockcx,
} from "../../../../utils/test-mockup";

jest.mock("../../../../context-menu/menu");

function render(disabled = false) {
  const props = generateDefaults(disabled);
  const component = shallow(<BreakpointsContextMenu {...props} />);
  return { component, props };
}

function generateDefaults(disabled) {
  const source = makeMockSource(
    "https://example.com/main.js",
    "source-https://example.com/main.js"
  );
  const breakpoints = [
    {
      ...makeMockBreakpoint(source, 1),
      id: "https://example.com/main.js:1:",
      disabled,
      options: {
        condition: "",
        logValue: "",
        hidden: false,
      },
    },
    {
      ...makeMockBreakpoint(source, 2),
      id: "https://example.com/main.js:2:",
      disabled,
      options: {
        hidden: false,
      },
    },
    {
      ...makeMockBreakpoint(source, 3),
      id: "https://example.com/main.js:3:",
      disabled,
    },
  ];

  const props = {
    cx: mockcx,
    breakpoints,
    breakpoint: breakpoints[0],
    removeBreakpoint: jest.fn(),
    removeBreakpoints: jest.fn(),
    removeAllBreakpoints: jest.fn(),
    toggleBreakpoints: jest.fn(),
    toggleAllBreakpoints: jest.fn(),
    toggleDisabledBreakpoint: jest.fn(),
    selectSpecificLocation: jest.fn(),
    setBreakpointCondition: jest.fn(),
    openConditionalPanel: jest.fn(),
    contextMenuEvent: { preventDefault: jest.fn() },
    selectedSource: makeMockSource(),
    setBreakpointOptions: jest.fn(),
    checkSourceOnIgnoreList: jest.fn(),
  };
  return props;
}

describe("BreakpointsContextMenu", () => {
  afterEach(() => {
    buildMenu.mockReset();
  });

  describe("context menu actions affecting other breakpoints", () => {
    it("'remove others' calls removeBreakpoints with proper arguments", () => {
      const { props } = render();
      const menuItems = buildMenu.mock.calls[0][0];
      const deleteOthers = menuItems.find(
        item => item.item.id === "node-menu-delete-other"
      );
      deleteOthers.item.click();

      expect(props.removeBreakpoints).toHaveBeenCalled();

      const otherBreakpoints = [props.breakpoints[1], props.breakpoints[2]];
      expect(props.removeBreakpoints.mock.calls[0][1]).toEqual(
        otherBreakpoints
      );
    });

    it("'enable others' calls toggleBreakpoints with proper arguments", () => {
      const { props } = render(true);
      const menuItems = buildMenu.mock.calls[0][0];
      const enableOthers = menuItems.find(
        item => item.item.id === "node-menu-enable-others"
      );
      enableOthers.item.click();

      expect(props.toggleBreakpoints).toHaveBeenCalled();

      expect(props.toggleBreakpoints.mock.calls[0][1]).toBe(false);

      const otherBreakpoints = [props.breakpoints[1], props.breakpoints[2]];
      expect(props.toggleBreakpoints.mock.calls[0][2]).toEqual(
        otherBreakpoints
      );
    });

    it("'disable others' calls toggleBreakpoints with proper arguments", () => {
      const { props } = render();
      const menuItems = buildMenu.mock.calls[0][0];
      const disableOthers = menuItems.find(
        item => item.item.id === "node-menu-disable-others"
      );
      disableOthers.item.click();

      expect(props.toggleBreakpoints).toHaveBeenCalled();
      expect(props.toggleBreakpoints.mock.calls[0][1]).toBe(true);

      const otherBreakpoints = [props.breakpoints[1], props.breakpoints[2]];
      expect(props.toggleBreakpoints.mock.calls[0][2]).toEqual(
        otherBreakpoints
      );
    });
  });
});