Sha256: 02832462faad783e873a3c42809d17b4f691bf21312db3414ffb278339ca54db

Contents?: true

Size: 1.59 KB

Versions: 31

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

shared_examples "share link" do
  it "allows copying the share link from the share modal" do
    expect(page).to have_css(".share-link", text: "Share")
    find(".share-link", text: "Share").click

    # This overrides document.execCommand in order to ensure it was called.
    page.execute_script(
      <<~JS
        var origExec = document.execCommand;
        document.execCommand = function(cmd) {
          if (cmd === "copy") {
            var $test = $('<div id="urlShareTest" />');
            $("#urlShare").append($test);

            var selObj = window.getSelection();
            $test.text(
              "The following text was copied to clipboard: " + selObj.toString()
            );
            return true;
          } else {
            return Reflect.apply(origExec, document, arguments)
          }
        };
      JS
    )

    within "#socialShare" do
      expect(page).to have_content("Share:")
      expect(page).to have_content("Share link")

      find("a[data-open='urlShare']").click
    end

    within "#urlShare" do
      expect(page).to have_content("Share link:")
      find("button[data-clipboard-copy]").click

      expect(find("button[data-clipboard-copy]")).to have_content("Copied!")

      input = find("#urlShareLink")
      expect(page).to have_content("The following text was copied to clipboard: #{input.value}")

      # Check that the screen reader announcement is properly added.
      announcement = find(".clipboard-announcement")
      expect(announcement).to have_content("The link was successfully copied to clipboard.")
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.8 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.7 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.6 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.10 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.9 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.5 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.8 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.4 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.3 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.7 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.5 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.2 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.1 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.4 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.0 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.3 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.0.rc2 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.27.0.rc1 lib/decidim/core/test/shared_examples/share_link_examples.rb
decidim-core-0.26.2 lib/decidim/core/test/shared_examples/share_link_examples.rb