summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/content-src/components/DiscoveryStreamComponents/DSTextPromo.test.jsx
blob: 1888e194af54274b8d40352312e5a50700e784f8 (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
import { DSTextPromo } from "content-src/components/DiscoveryStreamComponents/DSTextPromo/DSTextPromo";
import React from "react";
import { shallow } from "enzyme";

describe("<DSTextPromo>", () => {
  let wrapper;
  let sandbox;
  let dispatchStub;

  beforeEach(() => {
    sandbox = sinon.createSandbox();
    dispatchStub = sandbox.stub();
    wrapper = shallow(
      <DSTextPromo
        data={{
          spocs: [
            {
              shim: { impression: "1234" },
              id: "1234",
            },
          ],
        }}
        type="TEXTPROMO"
        dispatch={dispatchStub}
      />
    );
  });

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

  it("should render", () => {
    assert.ok(wrapper.exists());
    assert.ok(wrapper.find(".ds-text-promo").exists());
  });

  it("should render a header", () => {
    wrapper.setProps({ header: "foo" });
    assert.ok(wrapper.find(".text").exists());
  });

  it("should render a subtitle", () => {
    wrapper.setProps({ subtitle: "foo" });
    assert.ok(wrapper.find(".subtitle").exists());
  });

  it("should dispatch a click event on click", () => {
    wrapper.instance().onLinkClick();

    assert.calledTwice(dispatchStub);
    assert.deepEqual(dispatchStub.firstCall.args[0].data, {
      event: "CLICK",
      source: "TEXTPROMO",
      action_position: 0,
    });
    assert.deepEqual(dispatchStub.secondCall.args[0].data, {
      source: "TEXTPROMO",
      click: 0,
      tiles: [{ id: "1234", pos: 0 }],
    });
  });

  it("should dispath telemety events on dismiss", () => {
    wrapper.instance().onDismissClick();

    const firstCall = dispatchStub.getCall(0);
    const secondCall = dispatchStub.getCall(1);
    const thirdCall = dispatchStub.getCall(2);

    assert.equal(firstCall.args[0].type, "BLOCK_URL");
    assert.deepEqual(firstCall.args[0].data, [
      {
        url: undefined,
        pocket_id: undefined,
        isSponsoredTopSite: undefined,
      },
    ]);

    assert.equal(secondCall.args[0].type, "DISCOVERY_STREAM_USER_EVENT");
    assert.deepEqual(secondCall.args[0].data, {
      event: "BLOCK",
      source: "TEXTPROMO",
      action_position: 0,
    });

    assert.equal(thirdCall.args[0].type, "TELEMETRY_IMPRESSION_STATS");
    assert.deepEqual(thirdCall.args[0].data, {
      source: "TEXTPROMO",
      block: 0,
      tiles: [{ id: "1234", pos: 0 }],
    });
  });
});