tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DSEmptyState.test.jsx (2198B)


      1 import { DSEmptyState } from "content-src/components/DiscoveryStreamComponents/DSEmptyState/DSEmptyState";
      2 import React from "react";
      3 import { shallow } from "enzyme";
      4 
      5 describe("<DSEmptyState>", () => {
      6  let wrapper;
      7 
      8  beforeEach(() => {
      9    wrapper = shallow(<DSEmptyState />);
     10  });
     11 
     12  it("should render", () => {
     13    assert.ok(wrapper.exists());
     14    assert.ok(wrapper.find(".section-empty-state").exists());
     15  });
     16 
     17  it("should render defaultempty state message", () => {
     18    assert.ok(wrapper.find(".empty-state-message").exists());
     19    const header = wrapper.find(
     20      "h2[data-l10n-id='newtab-discovery-empty-section-topstories-header']"
     21    );
     22    const paragraph = wrapper.find(
     23      "p[data-l10n-id='newtab-discovery-empty-section-topstories-content']"
     24    );
     25 
     26    assert.ok(header.exists());
     27    assert.ok(paragraph.exists());
     28  });
     29 
     30  it("should render failed state message", () => {
     31    wrapper = shallow(<DSEmptyState status="failed" />);
     32    const button = wrapper.find(
     33      "button[data-l10n-id='newtab-discovery-empty-section-topstories-try-again-button']"
     34    );
     35 
     36    assert.ok(button.exists());
     37  });
     38 
     39  it("should render waiting state message", () => {
     40    wrapper = shallow(<DSEmptyState status="waiting" />);
     41    const button = wrapper.find(
     42      "button[data-l10n-id='newtab-discovery-empty-section-topstories-loading']"
     43    );
     44 
     45    assert.ok(button.exists());
     46  });
     47 
     48  it("should dispatch DISCOVERY_STREAM_RETRY_FEED on failed state button click", () => {
     49    const dispatch = sinon.spy();
     50 
     51    wrapper = shallow(
     52      <DSEmptyState
     53        status="failed"
     54        dispatch={dispatch}
     55        feed={{ url: "https://foo.com", data: {} }}
     56      />
     57    );
     58    wrapper.find("button.try-again-button").simulate("click");
     59 
     60    assert.calledTwice(dispatch);
     61    let [action] = dispatch.firstCall.args;
     62    assert.equal(action.type, "DISCOVERY_STREAM_FEED_UPDATE");
     63    assert.deepEqual(action.data.feed, {
     64      url: "https://foo.com",
     65      data: { status: "waiting" },
     66    });
     67 
     68    [action] = dispatch.secondCall.args;
     69 
     70    assert.equal(action.type, "DISCOVERY_STREAM_RETRY_FEED");
     71    assert.deepEqual(action.data.feed, { url: "https://foo.com", data: {} });
     72  });
     73 });