tor-browser

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

AddonsPicker.test.jsx (3687B)


      1 import React from "react";
      2 import { mount } from "enzyme";
      3 import { AddonsPicker } from "content-src/components/AddonsPicker";
      4 import { AboutWelcomeUtils } from "content-src/lib/aboutwelcome-utils.mjs";
      5 
      6 describe("AddonsPicker component", () => {
      7  let sandbox;
      8  let wrapper;
      9 
     10  const ADDON_DATA = {
     11    id: "addon",
     12    name: "Addon Name",
     13    description: "Addon Description",
     14    icon: "icon-url.png",
     15    type: "extension",
     16    author: {
     17      id: "author",
     18      name: "Author Name",
     19    },
     20    action: {
     21      type: "INSTALL_ADDON_FROM_URL",
     22      data: { url: "https://example.com/addon" },
     23    },
     24    source_id: "addon1_source",
     25  };
     26 
     27  const ADDON_CONTENT = {
     28    tiles: {
     29      data: [ADDON_DATA],
     30    },
     31  };
     32 
     33  beforeEach(() => {
     34    sandbox = sinon.createSandbox();
     35    sandbox.stub(AboutWelcomeUtils, "handleUserAction");
     36    sandbox.stub(AboutWelcomeUtils, "sendActionTelemetry");
     37  });
     38 
     39  afterEach(() => {
     40    sandbox.restore();
     41    if (wrapper && wrapper.unmount) {
     42      wrapper.unmount();
     43    }
     44  });
     45 
     46  describe("Centered layout", () => {
     47    beforeEach(() => {
     48      wrapper = mount(
     49        <AddonsPicker
     50          content={ADDON_CONTENT}
     51          installedAddons={[]}
     52          message_id="test_message"
     53        />
     54      );
     55    });
     56 
     57    it("should render the component when content is provided", () => {
     58      assert.ok(wrapper.exists());
     59    });
     60 
     61    it("should not render the component when no content is provided", () => {
     62      wrapper.setProps({ content: null });
     63      assert.ok(wrapper.isEmptyRender());
     64    });
     65 
     66    it("should not render addon rows container", () => {
     67      const addonContainer = wrapper.find(".addon-container").at(0);
     68      assert.equal(addonContainer.find(".addon-rows-container").length, 0);
     69    });
     70 
     71    it("should render addon title and description", () => {
     72      const addonDetails = wrapper.find(".addon-details").at(0);
     73      assert.equal(addonDetails.find(".addon-title").length, 1);
     74      assert.equal(addonDetails.find(".addon-description").length, 1);
     75    });
     76  });
     77 
     78  describe("Split layout", () => {
     79    beforeEach(() => {
     80      wrapper = mount(
     81        <AddonsPicker
     82          content={ADDON_CONTENT}
     83          installedAddons={[]}
     84          message_id="test_message"
     85          layout="split"
     86        />
     87      );
     88    });
     89 
     90    it("should render the component in split layout", () => {
     91      assert.ok(wrapper.exists());
     92      assert.equal(wrapper.find(".addon-rows-container").length, 1);
     93    });
     94 
     95    it("should render addon title and author in the first row", () => {
     96      const firstRow = wrapper.find(".addon-row").at(0);
     97      assert.equal(firstRow.find(".addon-author-details").length, 1);
     98      assert.equal(firstRow.find(".addon-title").length, 1);
     99      assert.equal(firstRow.find(".addon-author").length, 1);
    100    });
    101 
    102    it("should render install button in the first row", () => {
    103      const firstRow = wrapper.find(".addon-row").at(0);
    104      assert.equal(firstRow.find("InstallButton").length, 1);
    105    });
    106 
    107    it("should render description in the second row", () => {
    108      const secondRow = wrapper.find(".addon-row").at(1);
    109      assert.equal(secondRow.find(".addon-description").length, 1);
    110    });
    111 
    112    it("should handle author link click correctly", () => {
    113      const authorLink = wrapper.find(".author-link");
    114      authorLink.simulate("click", { stopPropagation: sandbox.stub() });
    115 
    116      assert.calledOnce(AboutWelcomeUtils.handleUserAction);
    117      assert.calledWith(AboutWelcomeUtils.handleUserAction, {
    118        type: "OPEN_URL",
    119        data: {
    120          args: `https://addons.mozilla.org/firefox/user/${ADDON_DATA.author.id}/`,
    121          where: "tab",
    122        },
    123      });
    124    });
    125  });
    126 });