summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/components/shared/tests/Modal.spec.js
blob: d609d3fda0046b6457b64e579c855cdaa42a59be (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
/* 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 { Modal } from "../Modal";

describe("Modal", () => {
  it("renders", () => {
    const wrapper = shallow(<Modal handleClose={() => {}} status="entering" />);
    expect(wrapper).toMatchSnapshot();
  });

  it("handles close modal click", () => {
    const handleCloseSpy = jest.fn();
    const wrapper = shallow(
      <Modal handleClose={handleCloseSpy} status="entering" />
    );
    wrapper.find(".modal-wrapper").simulate("click");
    expect(handleCloseSpy).toHaveBeenCalled();
  });

  it("renders children", () => {
    const children = <div className="aChild" />;
    const wrapper = shallow(
      <Modal children={children} handleClose={() => {}} status="entering" />
    );
    expect(wrapper.find(".aChild")).toHaveLength(1);
  });

  it("passes additionalClass to child div class", () => {
    const additionalClass = "testAddon";
    const wrapper = shallow(
      <Modal
        additionalClass={additionalClass}
        handleClose={() => {}}
        status="entering"
      />
    );
    expect(wrapper.find(`.modal-wrapper .${additionalClass}`)).toHaveLength(1);
  });

  it("passes status to child div class", () => {
    const status = "testStatus";
    const wrapper = shallow(<Modal status={status} handleClose={() => {}} />);
    expect(wrapper.find(`.modal-wrapper .${status}`)).toHaveLength(1);
  });
});