Sha256: 92670b4c164bfbf5b410cfc805f1f47aa3bb0592dd86dc3addec321c686f8b40

Contents?: true

Size: 1.96 KB

Versions: 24

Compression:

Stored size: 1.96 KB

Contents

# encoding: UTF-8

require 'test_helper'

class GovspeakLinkTest < Minitest::Test
  test "embedded link with link provided" do
    link = {
      content_id: "5572fee5-f38f-4641-8ffa-64fed9230ad4",
      url: "https://www.gov.uk/example",
      title: "Example page",
    }
    govspeak = "[embed:link:5572fee5-f38f-4641-8ffa-64fed9230ad4]"
    rendered = Govspeak::Document.new(govspeak, links: link).to_html
    expected = %r{<a href="https://www.gov.uk/example">Example page</a>}
    assert_match(expected, rendered)
  end

  test "embedded link with markdown title" do
    link = {
      content_id: "5572fee5-f38f-4641-8ffa-64fed9230ad4",
      url: "https://www.gov.uk/example",
      title: "**Example page**",
    }
    govspeak = "[embed:link:5572fee5-f38f-4641-8ffa-64fed9230ad4]"
    rendered = Govspeak::Document.new(govspeak, links: link).to_html
    expected = %r{<a href="https://www.gov.uk/example"><strong>Example page</strong></a>}
    assert_match(expected, rendered)
  end

  test "embedded link with external url" do
    link = {
      content_id: "5572fee5-f38f-4641-8ffa-64fed9230ad4",
      url: "https://www.example.com/",
      title: "Example website",
    }
    govspeak = "[embed:link:5572fee5-f38f-4641-8ffa-64fed9230ad4]"
    rendered = Govspeak::Document.new(govspeak, links: link).to_html
    expected = %r{<a rel="external" href="https://www.example.com/">Example website</a>}
    assert_match(expected, rendered)
  end
  test "embedded link with url not provided" do
    link = {
      content_id: "e510f1c1-4862-4333-889c-8d3acd443fbf",
      title: "Example website",
    }
    govspeak = "[embed:link:e510f1c1-4862-4333-889c-8d3acd443fbf]"
    rendered = Govspeak::Document.new(govspeak, links: link).to_html
    assert_match("Example website", rendered)
  end

  test "embedded link without link object" do
    govspeak = "[embed:link:0726637c-8c66-47ad-834a-d815cbf51e0e]"
    rendered = Govspeak::Document.new(govspeak).to_html
    assert_match("", rendered)
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
govspeak-6.5.0 test/govspeak_link_test.rb
govspeak-6.4.0 test/govspeak_link_test.rb
govspeak-6.3.0 test/govspeak_link_test.rb
govspeak-6.2.1 test/govspeak_link_test.rb
govspeak-6.2.0 test/govspeak_link_test.rb
govspeak-6.1.1 test/govspeak_link_test.rb
govspeak-6.1.0 test/govspeak_link_test.rb
govspeak-6.0.0 test/govspeak_link_test.rb
govspeak-5.9.1 test/govspeak_link_test.rb
govspeak-5.9.0 test/govspeak_link_test.rb
govspeak-5.8.0 test/govspeak_link_test.rb
govspeak-5.7.1 test/govspeak_link_test.rb
govspeak-5.7.0 test/govspeak_link_test.rb
govspeak-5.6.0 test/govspeak_link_test.rb
govspeak-5.5.0 test/govspeak_link_test.rb
govspeak-5.4.0 test/govspeak_link_test.rb
govspeak-5.3.0 test/govspeak_link_test.rb
govspeak-5.2.2 test/govspeak_link_test.rb
govspeak-5.2.1 test/govspeak_link_test.rb
govspeak-5.2.0 test/govspeak_link_test.rb