Sha256: b12086dc4499a8d1ef0cf953636f7105d4a587da969af25fff7d3b3e93175e74

Contents?: true

Size: 2 KB

Versions: 5

Compression:

Stored size: 2 KB

Contents

import ExternalDomainLink from "src/decidim/external_domain_warning";

describe("ExternalDomainLink", () => {
  const content = `
    <div id="links">
      <a href="https://github.com/" target="_blank">This is an external link</a>
      <a href="https://example.com/" target="_blank">This is an external link from a whitelisted domain</a>
      <div class="editor-container">
        <a href="https://example.org/" target="_blank">This is an external link within an editor</a>
      </div>
      <a href="https://github.com/" target="_blank">This is an external link without the last slash</a>
    </div>
  `;
  const config = {
    "external_domain_whitelist": ["example.com"]
  };
  window.Decidim = {
    config: {
      get: (key) => config[key]
    }
  }

  beforeEach(() => {
    $("body").html(content);
    $('a[target="_blank"]').each((_i, elem) => new ExternalDomainLink(elem));
  });

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

    expect($link.outerHTML).toEqual(
      '<a href="/link?external_url=https%3A%2F%2Fgithub.com%2F" target="_blank" data-remote="true">This is an external link</a>'
    );
  });

  it("does not update the link to the external link URL when its whitelisted", () => {
    const $link = $("#links a")[1];

    expect($link.outerHTML).toEqual(
      '<a href="https://example.com/" target="_blank">This is an external link from a whitelisted domain</a>'
    );
  });

  it("does not update the link to the external link URL when the parent class is excluded", () => {
    const $link = $("#links a")[2];

    expect($link.outerHTML).toEqual(
      '<a href="https://example.org/" target="_blank">This is an external link within an editor</a>'
    );
  });

  it("updates the link to the external link URL", () => {
    const $link = $("#links a")[3];

    expect($link.outerHTML).toEqual(
      '<a href="/link?external_url=https%3A%2F%2Fgithub.com%2F" target="_blank" data-remote="true">This is an external link without the last slash</a>'
    );
  });
});

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-core-0.28.5 app/packs/src/decidim/external_domain_warning.test.js
decidim-core-0.28.4 app/packs/src/decidim/external_domain_warning.test.js
decidim-core-0.28.3 app/packs/src/decidim/external_domain_warning.test.js
decidim-core-0.28.2 app/packs/src/decidim/external_domain_warning.test.js
decidim-core-0.28.1 app/packs/src/decidim/external_domain_warning.test.js