# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ require 'rails_helper' RSpec.describe HtmlSanitizer::Scrubber::Link do let(:scrubber) { described_class.new(web_app_url_prefix: 'http://example') } describe('#scrubber') do subject(:actual) { fragment.scrub!(scrubber).to_html } let(:fragment) { Loofah.fragment(input) } context 'when url as text' do let(:input) { 'http://zammad.org' } let(:target) { 'http://zammad.org' } it { is_expected.to eq target } end context 'when a has no href' do let(:input) { 'link' } let(:target) { 'link' } it { is_expected.to eq target } end context 'when a has title' do let(:input) { 'link' } let(:target) { 'link' } it { is_expected.to eq target } end context 'when a has no title' do let(:input) { 'link' } let(:target) { 'link' } it { is_expected.to eq target } end context 'when external URL' do let(:input) { 'link' } let(:target) { 'link' } it { is_expected.to eq target } end context 'when URL without protocol' do let(:input) { 'link' } let(:target) { 'link' } it { is_expected.to eq target } end context 'when URL without protocol and external' do let(:scrubber) { described_class.new(web_app_url_prefix: 'http://example', external: true) } let(:input) { 'link' } let(:target) { 'link' } it { is_expected.to eq target } end context 'when external URL with tel protocol' do let(:input) { 'my telephone number' } let(:target) { 'my telephone number' } it { is_expected.to eq target } end end end