summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/content-src/components/DiscoveryStreamComponents/FeatureHighlight.test.jsx
blob: 2d7ef66ecfc9b3d137efc901f1b23e4b0c44452f (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
import { FeatureHighlight } from "content-src/components/DiscoveryStreamComponents/FeatureHighlight/FeatureHighlight";
import { SponsoredContentHighlight } from "content-src/components/DiscoveryStreamComponents/FeatureHighlight/SponsoredContentHighlight";
import React from "react";
import { mount } from "enzyme";

describe("<FeatureHighlight>", () => {
  let wrapper;
  let fakeWindow;

  beforeEach(() => {
    wrapper = mount(<FeatureHighlight />);
  });

  it("should render", () => {
    assert.ok(wrapper.exists());
    assert.ok(wrapper.find(".feature-highlight").exists());
  });

  it("should render a title", () => {
    wrapper.setProps({ message: "foo" });
    assert.ok(wrapper.find(".feature-highlight-modal p").exists());
    assert.equal(wrapper.find(".feature-highlight-modal p").text(), "foo");
  });

  it("should open a modal", () => {
    assert.ok(wrapper.find(".feature-highlight-modal.closed").exists());
    wrapper.find(".toggle-button").simulate("click");
    assert.ok(wrapper.find(".feature-highlight-modal.opened").exists());
    wrapper.find(".icon-dismiss").simulate("click");
    assert.ok(wrapper.find(".feature-highlight-modal.closed").exists());
  });

  it("should close a modal if clicking outside", () => {
    fakeWindow = {
      document: {
        addEventListener: (event, handler) => {
          fakeWindow.document.handleOutsideClick = handler;
        },
        removeEventListener: () => {},
      },
    };
    wrapper.setProps({ windowObj: fakeWindow });

    wrapper.find(".toggle-button").simulate("click");
    fakeWindow.document.handleOutsideClick({ target: null });
  });
});

describe("<SponsoredContentHighlight>", () => {
  let wrapper;

  beforeEach(() => {
    wrapper = mount(<SponsoredContentHighlight />);
  });

  it("should render", () => {
    assert.ok(wrapper.exists());
    assert.ok(wrapper.find(".sponsored-content-highlight").exists());
  });
});