tor-browser

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

Search.test.jsx (1849B)


      1 import { GlobalOverrider } from "test/unit/utils";
      2 import { mount, shallow } from "enzyme";
      3 import React from "react";
      4 import { _Search as Search } from "content-src/components/Search/Search";
      5 import { Logo } from "content-src/components/Logo/Logo";
      6 
      7 const DEFAULT_PROPS = {
      8  dispatch() {},
      9  Prefs: { values: { featureConfig: {}, "search.useHandoffComponent": true } },
     10 };
     11 
     12 describe("<Search>", () => {
     13  let globals;
     14  let sandbox;
     15  beforeEach(() => {
     16    globals = new GlobalOverrider();
     17    sandbox = globals.sandbox;
     18 
     19    global.ContentSearchUIController.prototype = { search: sandbox.spy() };
     20  });
     21  afterEach(() => {
     22    globals.restore();
     23  });
     24 
     25  it("should render a Search element", () => {
     26    const wrapper = shallow(<Search {...DEFAULT_PROPS} />);
     27    assert.ok(wrapper.exists());
     28  });
     29  it("should not use a <form> element", () => {
     30    const wrapper = mount(<Search {...DEFAULT_PROPS} />);
     31 
     32    assert.equal(wrapper.find("form").length, 0);
     33  });
     34  it("should show our logo when the prop exists.", () => {
     35    const showLogoProps = Object.assign({}, DEFAULT_PROPS, { showLogo: true });
     36    const wrapper = shallow(<Search {...showLogoProps} />);
     37    const logo_component = wrapper.find(Logo);
     38    assert.ok(logo_component.exists());
     39  });
     40  it("should not show our logo when the prop does not exist.", () => {
     41    const hideLogoProps = Object.assign({}, DEFAULT_PROPS, { showLogo: false });
     42    const wrapper = shallow(<Search {...hideLogoProps} />);
     43    const logo_component = wrapper.find(Logo);
     44    assert.ok(!logo_component.exists());
     45  });
     46 
     47  describe("Search Hand-off", () => {
     48    it("should render a Search hand-off element", () => {
     49      const wrapper = shallow(<Search {...DEFAULT_PROPS} />);
     50      assert.ok(wrapper.exists());
     51      assert.equal(wrapper.find("content-search-handoff-ui").length, 1);
     52    });
     53  });
     54 });