tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SearchShortcutsForm.test.jsx (1527B)


      1 import {
      2  SearchShortcutsForm,
      3  SelectableSearchShortcut,
      4 } from "content-src/components/TopSites/SearchShortcutsForm";
      5 import React from "react";
      6 import { shallow } from "enzyme";
      7 
      8 describe("<SearchShortcutsForm>", () => {
      9  let wrapper;
     10  let sandbox;
     11  let dispatchStub;
     12 
     13  beforeEach(() => {
     14    sandbox = sinon.createSandbox();
     15    dispatchStub = sandbox.stub();
     16    const defaultProps = { rows: [], searchShortcuts: [] };
     17    wrapper = shallow(
     18      <SearchShortcutsForm TopSites={defaultProps} dispatch={dispatchStub} />
     19    );
     20  });
     21 
     22  afterEach(() => {
     23    sandbox.restore();
     24  });
     25 
     26  it("should render", () => {
     27    assert.ok(wrapper.exists());
     28    assert.ok(wrapper.find(".topsite-form").exists());
     29  });
     30 
     31  it("should render SelectableSearchShortcut components", () => {
     32    wrapper.setState({ shortcuts: [{}, {}] });
     33 
     34    assert.lengthOf(
     35      wrapper.find(".search-shortcuts-container div").children(),
     36      2
     37    );
     38    assert.equal(
     39      wrapper.find(".search-shortcuts-container div").children().at(0).type(),
     40      SelectableSearchShortcut
     41    );
     42  });
     43 
     44  it("should render SelectableSearchShortcut components", () => {
     45    const onCloseStub = sandbox.stub();
     46    const fakeEvent = { preventDefault: sandbox.stub() };
     47    wrapper.setState({ shortcuts: [{}, {}] });
     48    wrapper.setProps({ onClose: onCloseStub });
     49 
     50    wrapper.find(".done").simulate("click", fakeEvent);
     51 
     52    assert.calledOnce(dispatchStub);
     53    assert.calledOnce(fakeEvent.preventDefault);
     54    assert.calledOnce(onCloseStub);
     55  });
     56 });