2019-08-30 18:16:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe ExternalLinkHelper do
|
2019-08-30 18:16:39 -04:00
|
|
|
include IconsHelper
|
|
|
|
|
|
|
|
it 'returns external link with icon' do
|
2020-10-16 02:08:48 -04:00
|
|
|
link = external_link('https://gitlab.com', 'https://gitlab.com').to_s
|
|
|
|
expect(link).to start_with('<a target="_blank" rel="noopener noreferrer" href="https://gitlab.com">https://gitlab.com')
|
|
|
|
expect(link).to include('data-testid="external-link-icon"')
|
2019-08-30 18:16:39 -04:00
|
|
|
end
|
2019-09-03 17:26:39 -04:00
|
|
|
|
|
|
|
it 'allows options when creating external link with icon' do
|
2020-10-16 02:08:48 -04:00
|
|
|
link = external_link('https://gitlab.com', 'https://gitlab.com', { "data-foo": "bar", class: "externalLink" }).to_s
|
|
|
|
expect(link).to start_with('<a target="_blank" rel="noopener noreferrer" data-foo="bar" class="externalLink" href="https://gitlab.com">https://gitlab.com')
|
|
|
|
expect(link).to include('data-testid="external-link-icon"')
|
2019-09-03 17:26:39 -04:00
|
|
|
end
|
2021-09-30 14:11:31 -04:00
|
|
|
|
|
|
|
it 'sanitizes and returns external link with icon' do
|
|
|
|
link = external_link('sanitized link content', 'javascript:alert()').to_s
|
|
|
|
expect(link).not_to include('href="javascript:alert()"')
|
|
|
|
expect(link).to start_with('<a target="_blank" rel="noopener noreferrer">sanitized link content')
|
|
|
|
expect(link).to include('data-testid="external-link-icon"')
|
|
|
|
end
|
2019-08-30 18:16:39 -04:00
|
|
|
end
|