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

const selectItem = jest.fn();
const selectedIndex = 1;
const payload = {
  items: [
    {
      id: 0,
      subtitle: "subtitle",
      title: "title",
      value: "value",
    },
    {
      id: 1,
      subtitle: "subtitle 1",
      title: "title 1",
      value: "value 1",
    },
  ],
  selected: selectedIndex,
  selectItem,
};

describe("Result list", () => {
  it("should call onClick function", () => {
    const wrapper = shallow(<ResultList {...payload} />);

    wrapper.childAt(selectedIndex).simulate("click");
    expect(selectItem).toHaveBeenCalled();
  });

  it("should render the component", () => {
    const wrapper = shallow(<ResultList {...payload} />);
    expect(wrapper).toMatchSnapshot();
  });

  it("selected index should have 'selected class'", () => {
    const wrapper = shallow(<ResultList {...payload} />);
    const childHasClass = wrapper.childAt(selectedIndex).hasClass("selected");

    expect(childHasClass).toEqual(true);
  });
});