summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutwelcome/tests/unit/LinkParagraph.test.jsx
blob: 240342b5e2d43ea81b705b863998eebecc6c5885 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React from "react";
import { mount } from "enzyme";
import { LinkParagraph } from "content-src/components/LinkParagraph";

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

  beforeEach(() => {
    sandbox = sinon.createSandbox();
    handleAction = sandbox.stub();

    wrapper = mount(
      <LinkParagraph
        text_content={{
          text: {
            string_id:
              "shopping-onboarding-opt-in-privacy-policy-and-terms-of-use3",
          },
          link_keys: ["privacy_policy"],
          font_styles: "legal",
        }}
        handleAction={handleAction}
      />
    );
  });

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

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

  it("should render copy with legal style if legal is passed to font_styles", () => {
    assert.strictEqual(wrapper.find(".legal-paragraph").length, 1);
  });

  it("should render one link when only one link id is passed", () => {
    assert.strictEqual(wrapper.find(".legal-paragraph a").length, 1);
  });

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

  it("should render two links if an additional link id is passed", () => {
    wrapper.setProps({
      text_content: {
        text: {
          string_id:
            "shopping-onboarding-opt-in-privacy-policy-and-terms-of-use3",
        },
        link_keys: ["privacy_policy", "terms_of_use"],
        font_styles: "legal",
      },
    });
    assert.strictEqual(wrapper.find(".legal-paragraph a").length, 2);
  });

  it("should render no links when no link id is passed", () => {
    wrapper.setProps({
      text_content: { links: null },
    });
    assert.strictEqual(wrapper.find(".legal-paragraph a").length, 0);
  });

  it("should render copy even when no link id is passed", () => {
    wrapper.setProps({
      text_content: { links: null },
    });
    assert.ok(wrapper.find(".legal-paragraph"));
  });

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

  it("should render copy in link style if no font style is passed", () => {
    wrapper.setProps({
      text_content: {
        text: {
          string_id: "shopping-onboarding-body",
        },
        link_keys: ["learn_more"],
      },
    });
    assert.strictEqual(wrapper.find(".link-paragraph").length, 1);
  });

  it("should not render links if string_id is not provided", () => {
    wrapper.setProps({
      text_content: { text: { string_id: null } },
    });
    assert.strictEqual(wrapper.find(".link-paragraph a").length, 0);
  });
});