Sha256: 93b4c773ff584266293f0aa4778acabf963754a63ecac7e8014aada9f2e54678

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

import $ from "jquery"; // eslint-disable-line id-length

import ExternalLink from "./external_link";

describe("ExternalLink", () => {
  const content = `
    <div id="links">
      <a href="https://decidim.org/" target="_blank">This is an external link</a>
      <a href="https://decidim.org/" target="_blank" data-external-link="false">This is an normal link</a>
    </div>
  `;

  const config = {
    "icons_path": "/path/to/icons.svg"
  };
  window.Decidim = {
    config: {
      get: (key) => config[key]
    }
  }
  const expectedIcon = "<svg width=\"0.75em\" height=\"0.75em\" role=\"img\" aria-hidden=\"true\" class=\"fill-current\"><title>external-link-line</title><use href=\"/path/to/icons.svg#ri-external-link-line\"></use></svg><span class=\"sr-only\">(External link)</span>";

  beforeEach(() => {
    document.body.innerHTML = content
    document.querySelectorAll("a[target=\"_blank\"]:not([data-external-link=\"false\"])").forEach((elem) => new ExternalLink(elem))
  });

  it("adds the external link indicator to the external link", () => {
    const $link = $("#links a")[0];

    expect($link.outerHTML).toEqual(
      `<a href="https://decidim.org/" target="_blank">This is an external link<span data-external-link="true" class="inline-block mx-0.5">${expectedIcon}</span></a>`
    );
  });

  it("does not add the external link when is disabled", () => {
    const $link = $("#links a")[1];

    expect($link.outerHTML).toEqual(
      "<a href=\"https://decidim.org/\" target=\"_blank\" data-external-link=\"false\">This is an normal link</a>"
    );
  });
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.28.0 app/packs/src/decidim/external_link.test.js
decidim-core-0.28.0.rc5 app/packs/src/decidim/external_link.test.js
decidim-core-0.28.0.rc4 app/packs/src/decidim/external_link.test.js