summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/content-src/components/TopSites/SearchShortcutsForm.test.jsx
blob: 22c4e8192aebb556be7242a9b5bccd7e0b6865c8 (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
import {
  SearchShortcutsForm,
  SelectableSearchShortcut,
} from "content-src/components/TopSites/SearchShortcutsForm";
import React from "react";
import { shallow } from "enzyme";

describe("<SearchShortcutsForm>", () => {
  let wrapper;
  let sandbox;
  let dispatchStub;

  beforeEach(() => {
    sandbox = sinon.createSandbox();
    dispatchStub = sandbox.stub();
    const defaultProps = { rows: [], searchShortcuts: [] };
    wrapper = shallow(
      <SearchShortcutsForm TopSites={defaultProps} dispatch={dispatchStub} />
    );
  });

  afterEach(() => {
    sandbox.restore();
  });

  it("should render", () => {
    assert.ok(wrapper.exists());
    assert.ok(wrapper.find(".topsite-form").exists());
  });

  it("should render SelectableSearchShortcut components", () => {
    wrapper.setState({ shortcuts: [{}, {}] });

    assert.lengthOf(
      wrapper.find(".search-shortcuts-container div").children(),
      2
    );
    assert.equal(
      wrapper.find(".search-shortcuts-container div").children().at(0).type(),
      SelectableSearchShortcut
    );
  });

  it("should render SelectableSearchShortcut components", () => {
    const onCloseStub = sandbox.stub();
    const fakeEvent = { preventDefault: sandbox.stub() };
    wrapper.setState({ shortcuts: [{}, {}] });
    wrapper.setProps({ onClose: onCloseStub });

    wrapper.find(".done").simulate("click", fakeEvent);

    assert.calledOnce(dispatchStub);
    assert.calledOnce(fakeEvent.preventDefault);
    assert.calledOnce(onCloseStub);
  });
});