tor-browser

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

FluentOrText.test.jsx (2197B)


      1 import { FluentOrText } from "content-src/components/FluentOrText/FluentOrText";
      2 import React from "react";
      3 import { shallow, mount } from "enzyme";
      4 
      5 describe("<FluentOrText>", () => {
      6  it("should create span with no children", () => {
      7    const wrapper = shallow(<FluentOrText />);
      8 
      9    assert.ok(wrapper.find("span").exists());
     10  });
     11  it("should set plain text", () => {
     12    const wrapper = shallow(<FluentOrText message={"hello"} />);
     13 
     14    assert.equal(wrapper.text(), "hello");
     15  });
     16  it("should use fluent id on automatic span", () => {
     17    const wrapper = shallow(<FluentOrText message={{ id: "fluent" }} />);
     18 
     19    assert.ok(wrapper.find("span[data-l10n-id='fluent']").exists());
     20  });
     21  it("should also allow string_id", () => {
     22    const wrapper = shallow(<FluentOrText message={{ string_id: "fluent" }} />);
     23 
     24    assert.ok(wrapper.find("span[data-l10n-id='fluent']").exists());
     25  });
     26  it("should use fluent id on child", () => {
     27    const wrapper = shallow(
     28      <FluentOrText message={{ id: "fluent" }}>
     29        <p />
     30      </FluentOrText>
     31    );
     32 
     33    assert.ok(wrapper.find("p[data-l10n-id='fluent']").exists());
     34  });
     35  it("should set args for fluent", () => {
     36    const wrapper = mount(<FluentOrText message={{ args: { num: 5 } }} />);
     37    const { attributes } = wrapper.getDOMNode();
     38    const args = attributes.getNamedItem("data-l10n-args").value;
     39    assert.equal(JSON.parse(args).num, 5);
     40  });
     41  it("should also allow values", () => {
     42    const wrapper = mount(<FluentOrText message={{ values: { num: 5 } }} />);
     43    const { attributes } = wrapper.getDOMNode();
     44    const args = attributes.getNamedItem("data-l10n-args").value;
     45    assert.equal(JSON.parse(args).num, 5);
     46  });
     47  it("should preserve original children with fluent", () => {
     48    const wrapper = shallow(
     49      <FluentOrText message={{ id: "fluent" }}>
     50        <p>
     51          <b data-l10n-name="bold" />
     52        </p>
     53      </FluentOrText>
     54    );
     55 
     56    assert.ok(wrapper.find("b[data-l10n-name='bold']").exists());
     57  });
     58  it("should only allow a single child", () => {
     59    assert.throws(() =>
     60      shallow(
     61        <FluentOrText>
     62          <p />
     63          <p />
     64        </FluentOrText>
     65      )
     66    );
     67  });
     68 });