tor-browser

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

CTAParagraph.test.jsx (1288B)


      1 import React from "react";
      2 import { shallow } from "enzyme";
      3 import { CTAParagraph } from "content-src/components/CTAParagraph";
      4 
      5 describe("CTAParagraph component", () => {
      6  let sandbox;
      7  let wrapper;
      8  let handleAction;
      9 
     10  beforeEach(() => {
     11    sandbox = sinon.createSandbox();
     12    handleAction = sandbox.stub();
     13    wrapper = shallow(
     14      <CTAParagraph
     15        content={{
     16          text: {
     17            raw: "Link Text",
     18            string_name: "Test Name",
     19          },
     20        }}
     21        handleAction={handleAction}
     22      />
     23    );
     24  });
     25 
     26  afterEach(() => {
     27    sandbox.restore();
     28  });
     29 
     30  it("should render CTAParagraph component", () => {
     31    assert.ok(wrapper.exists());
     32  });
     33 
     34  it("should render CTAParagraph component if only CTA text is passed", () => {
     35    wrapper.setProps({ content: { text: "CTA Text" } });
     36    assert.ok(wrapper.exists());
     37  });
     38 
     39  it("should call handleAction method when button is link is clicked", () => {
     40    const btnLink = wrapper.find(".cta-paragraph span");
     41    btnLink.simulate("click", { preventDefault() {} });
     42    assert.calledOnce(handleAction);
     43  });
     44 
     45  it("should not render CTAParagraph component if CTA text is not passed", () => {
     46    wrapper.setProps({ content: { text: null } });
     47    assert.ok(wrapper.isEmptyRender());
     48  });
     49 });