tor-browser

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

CollapsibleSection.test.jsx (1866B)


      1 import { _CollapsibleSection as CollapsibleSection } from "content-src/components/CollapsibleSection/CollapsibleSection";
      2 import { ErrorBoundary } from "content-src/components/ErrorBoundary/ErrorBoundary";
      3 import { mount } from "enzyme";
      4 import React from "react";
      5 
      6 const DEFAULT_PROPS = {
      7  id: "cool",
      8  className: "cool-section",
      9  title: "Cool Section",
     10  prefName: "collapseSection",
     11  collapsed: false,
     12  eventSource: "foo",
     13  document: {
     14    addEventListener: () => {},
     15    removeEventListener: () => {},
     16    visibilityState: "visible",
     17  },
     18  dispatch: () => {},
     19  Prefs: { values: { featureConfig: {} } },
     20 };
     21 
     22 describe("CollapsibleSection", () => {
     23  let wrapper;
     24 
     25  function testSetup(props = {}) {
     26    const customProps = Object.assign({}, DEFAULT_PROPS, props);
     27    wrapper = mount(
     28      <CollapsibleSection {...customProps}>foo</CollapsibleSection>
     29    );
     30  }
     31 
     32  beforeEach(() => testSetup());
     33 
     34  it("should render the component", () => {
     35    assert.ok(wrapper.exists());
     36  });
     37 
     38  it("should render an ErrorBoundary with class section-body-fallback", () => {
     39    assert.equal(
     40      wrapper.find(ErrorBoundary).first().prop("className"),
     41      "section-body-fallback"
     42    );
     43  });
     44 
     45  describe("without collapsible pref", () => {
     46    let dispatch;
     47    beforeEach(() => {
     48      dispatch = sinon.stub();
     49      testSetup({ collapsed: undefined, dispatch });
     50    });
     51    it("should render the section uncollapsed", () => {
     52      assert.isFalse(
     53        wrapper.find(".collapsible-section").first().hasClass("collapsed")
     54      );
     55    });
     56 
     57    it("should not render the arrow if no collapsible pref exists for the section", () => {
     58      assert.lengthOf(wrapper.find(".click-target .collapsible-arrow"), 0);
     59    });
     60  });
     61 
     62  describe("icon", () => {
     63    it("no icon should be shown", () => {
     64      assert.lengthOf(wrapper.find(".icon"), 0);
     65    });
     66  });
     67 });