tor-browser

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

Navigation.test.jsx (3182B)


      1 import {
      2  Navigation,
      3  Topic,
      4 } from "content-src/components/DiscoveryStreamComponents/Navigation/Navigation";
      5 import React from "react";
      6 import { SafeAnchor } from "content-src/components/DiscoveryStreamComponents/SafeAnchor/SafeAnchor";
      7 import { FluentOrText } from "content-src/components/FluentOrText/FluentOrText";
      8 import { shallow, mount } from "enzyme";
      9 
     10 const DEFAULT_PROPS = {
     11  App: {
     12    isForStartupCache: false,
     13  },
     14 };
     15 
     16 describe("<Navigation>", () => {
     17  let wrapper;
     18 
     19  beforeEach(() => {
     20    wrapper = mount(<Navigation header={{}} locale="en-US" />);
     21  });
     22 
     23  it("should render", () => {
     24    assert.ok(wrapper.exists());
     25  });
     26 
     27  it("should render a title", () => {
     28    wrapper.setProps({ header: { title: "Foo" } });
     29 
     30    assert.equal(wrapper.find(".ds-navigation-header").text(), "Foo");
     31  });
     32 
     33  it("should not render a title", () => {
     34    wrapper.setProps({ header: null });
     35 
     36    assert.lengthOf(wrapper.find(".ds-navigation-header"), 0);
     37  });
     38 
     39  it("should set default alignment", () => {
     40    assert.lengthOf(wrapper.find(".ds-navigation-centered"), 1);
     41  });
     42 
     43  it("should set custom alignment", () => {
     44    wrapper.setProps({ alignment: "left-align" });
     45 
     46    assert.lengthOf(wrapper.find(".ds-navigation-left-align"), 1);
     47  });
     48 
     49  it("should set default of no links", () => {
     50    assert.lengthOf(wrapper.find("ul").children(), 0);
     51  });
     52 
     53  it("should render a FluentOrText", () => {
     54    wrapper.setProps({ header: { title: "Foo" } });
     55 
     56    assert.equal(
     57      wrapper.find(".ds-navigation").children().at(0).type(),
     58      FluentOrText
     59    );
     60  });
     61 
     62  it("should render 2 Topics", () => {
     63    wrapper.setProps({
     64      links: [
     65        { url: "https://foo.com", name: "foo" },
     66        { url: "https://bar.com", name: "bar" },
     67      ],
     68    });
     69 
     70    assert.lengthOf(wrapper.find("ul").children(), 2);
     71  });
     72 
     73  it("should render 2 extra Topics", () => {
     74    wrapper.setProps({
     75      newFooterSection: true,
     76      links: [
     77        { url: "https://foo.com", name: "foo" },
     78        { url: "https://bar.com", name: "bar" },
     79      ],
     80      extraLinks: [
     81        { url: "https://foo.com", name: "foo" },
     82        { url: "https://bar.com", name: "bar" },
     83      ],
     84    });
     85 
     86    assert.lengthOf(wrapper.find("ul").children(), 4);
     87  });
     88 });
     89 
     90 describe("<Topic>", () => {
     91  let wrapper;
     92  let sandbox;
     93 
     94  beforeEach(() => {
     95    wrapper = shallow(<Topic url="https://foo.com" name="foo" />);
     96    sandbox = sinon.createSandbox();
     97  });
     98 
     99  afterEach(() => {
    100    sandbox.restore();
    101  });
    102 
    103  it("should pass onLinkClick prop", () => {
    104    assert.propertyVal(
    105      wrapper.at(0).props(),
    106      "onLinkClick",
    107      wrapper.instance().onLinkClick
    108    );
    109  });
    110 
    111  it("should render", () => {
    112    assert.ok(wrapper.exists());
    113    assert.equal(wrapper.type(), SafeAnchor);
    114  });
    115 
    116  describe("onLinkClick", () => {
    117    let dispatch;
    118 
    119    beforeEach(() => {
    120      dispatch = sandbox.stub();
    121      wrapper = shallow(<Topic dispatch={dispatch} {...DEFAULT_PROPS} />);
    122      wrapper.setState({ isSeen: true });
    123    });
    124 
    125    it("should call dispatch", () => {
    126      wrapper.instance().onLinkClick({ target: { text: `Must Reads` } });
    127 
    128      assert.calledOnce(dispatch);
    129    });
    130  });
    131 });