summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutwelcome/tests/unit/CTAParagraph.test.jsx
blob: c60e8e2666c4b18a5674e0aab5301d5be4e84379 (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
import React from "react";
import { shallow } from "enzyme";
import { CTAParagraph } from "content-src/components/CTAParagraph";

describe("CTAParagraph component", () => {
  let sandbox;
  let wrapper;
  let handleAction;

  beforeEach(() => {
    sandbox = sinon.createSandbox();
    handleAction = sandbox.stub();
    wrapper = shallow(
      <CTAParagraph
        content={{
          text: {
            raw: "Link Text",
            string_name: "Test Name",
          },
        }}
        handleAction={handleAction}
      />
    );
  });

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

  it("should render CTAParagraph component", () => {
    assert.ok(wrapper.exists());
  });

  it("should render CTAParagraph component if only CTA text is passed", () => {
    wrapper.setProps({ content: { text: "CTA Text" } });
    assert.ok(wrapper.exists());
  });

  it("should call handleAction method when button is link is clicked", () => {
    const btnLink = wrapper.find(".cta-paragraph span");
    btnLink.simulate("click");
    assert.calledOnce(handleAction);
  });

  it("should not render CTAParagraph component if CTA text is not passed", () => {
    wrapper.setProps({ content: { text: null } });
    assert.ok(wrapper.isEmptyRender());
  });
});