Sha256: 53f7c6d0536764c44bf471858dd9cd0b94d8f431da858f8a1871da529a0f0a78

Contents?: true

Size: 1.76 KB

Versions: 26

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

shared_examples "having a rich text editor" do |css, toolbar|
  it "has a form with a rich text editor" do
    within "form.#{css}" do
      expect(page).to have_selector("div.editor-container[data-toolbar='#{toolbar}']", visible: :all)
    end
  end
end

shared_context "with rich text editor content" do
  let(:content) { "<p>#{safe_tags}</p>#{script}" }
  let(:safe_tags) { em + u + strong }
  let(:em) { "<em>em</em>" }
  let(:u) { "<u>u</u>" }
  let(:strong) { "<strong>strong</strong>" }
  let(:script) { "<script>alert('SCRIPT')</script>" }
end

shared_examples "rendering safe content" do |css|
  include_context "with rich text editor content"

  it "renders potentially safe HTML tags unescaped" do
    within css do
      expect(page).to have_selector("em", text: "em")
      expect(page).to have_selector("u", text: "u")
      expect(page).to have_selector("strong", text: "strong")
    end
  end

  it "sanitizes potentially malicious HTML tags" do
    within css do
      expect(page).not_to have_selector("script", visible: :all)
      expect(page).to have_content("alert('SCRIPT')")
    end
  end
end

shared_examples "rendering unsafe content" do |css|
  include_context "with rich text editor content"

  it "sanitizes potentially safe HTML tags" do
    within css do
      expect(page).not_to have_selector("em")
      expect(page).to have_content("em")
      expect(page).not_to have_selector("u")
      expect(page).to have_content("u")
      expect(page).not_to have_selector("strong")
      expect(page).to have_content("strong")
    end
  end

  it "strips potentially malicious HTML tags" do
    within css do
      expect(page).not_to have_selector("script", visible: :all)
      expect(page).not_to have_content("alert('SCRIPT')")
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
decidim-core-0.26.5 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.27.2 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.27.1 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.4 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.27.0 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.3 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.27.0.rc2 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.27.0.rc1 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.2 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.1 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.0 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.0.rc2 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.26.0.rc1 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.2 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.1 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.0 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.0.rc4 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.0.rc3 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.0.rc2 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb
decidim-core-0.25.0.rc1 lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb