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

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

  beforeEach(() => {
    wrapper = shallow(<DSEmptyState />);
  });

  it("should render", () => {
    assert.ok(wrapper.exists());
    assert.ok(wrapper.find(".section-empty-state").exists());
  });

  it("should render defaultempty state message", () => {
    assert.ok(wrapper.find(".empty-state-message").exists());
    const header = wrapper.find(
      "h2[data-l10n-id='newtab-discovery-empty-section-topstories-header']"
    );
    const paragraph = wrapper.find(
      "p[data-l10n-id='newtab-discovery-empty-section-topstories-content']"
    );

    assert.ok(header.exists());
    assert.ok(paragraph.exists());
  });

  it("should render failed state message", () => {
    wrapper = shallow(<DSEmptyState status="failed" />);
    const button = wrapper.find(
      "button[data-l10n-id='newtab-discovery-empty-section-topstories-try-again-button']"
    );

    assert.ok(button.exists());
  });

  it("should render waiting state message", () => {
    wrapper = shallow(<DSEmptyState status="waiting" />);
    const button = wrapper.find(
      "button[data-l10n-id='newtab-discovery-empty-section-topstories-loading']"
    );

    assert.ok(button.exists());
  });

  it("should dispatch DISCOVERY_STREAM_RETRY_FEED on failed state button click", () => {
    const dispatch = sinon.spy();

    wrapper = shallow(
      <DSEmptyState
        status="failed"
        dispatch={dispatch}
        feed={{ url: "https://foo.com", data: {} }}
      />
    );
    wrapper.find("button.try-again-button").simulate("click");

    assert.calledTwice(dispatch);
    let [action] = dispatch.firstCall.args;
    assert.equal(action.type, "DISCOVERY_STREAM_FEED_UPDATE");
    assert.deepEqual(action.data.feed, {
      url: "https://foo.com",
      data: { status: "waiting" },
    });

    [action] = dispatch.secondCall.args;

    assert.equal(action.type, "DISCOVERY_STREAM_RETRY_FEED");
    assert.deepEqual(action.data.feed, { url: "https://foo.com", data: {} });
  });
});