diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
commit | 14bd84b61276ef29b97d23642d698de769bacfd2 (patch) | |
tree | f9eba90140c1bd874211dea17750a0d422c04080 /spec/lib/banzai/filter/inline_observability_filter_spec.rb | |
parent | 891c388697b2db0d8ee0c8358a9bdbf6dc56d581 (diff) |
Add latest changes from gitlab-org/gitlab@15-10-stable-eev15.10.0-rc42
Diffstat (limited to 'spec/lib/banzai/filter/inline_observability_filter_spec.rb')
-rw-r--r-- | spec/lib/banzai/filter/inline_observability_filter_spec.rb | 82 |
1 files changed, 64 insertions, 18 deletions
diff --git a/spec/lib/banzai/filter/inline_observability_filter_spec.rb b/spec/lib/banzai/filter/inline_observability_filter_spec.rb index fb1ba46e76c..81896faced8 100644 --- a/spec/lib/banzai/filter/inline_observability_filter_spec.rb +++ b/spec/lib/banzai/filter/inline_observability_filter_spec.rb @@ -2,25 +2,20 @@ require 'spec_helper' -RSpec.describe Banzai::Filter::InlineObservabilityFilter do +RSpec.describe Banzai::Filter::InlineObservabilityFilter, feature_category: :metrics do include FilterSpecHelper let(:input) { %(<a href="#{url}">example</a>) } let(:doc) { filter(input) } - let(:group) { create(:group) } - let(:user) { create(:user) } - describe '#filter?' do - context 'when the document has an external link' do - let(:url) { 'https://foo.com' } - - it 'leaves regular non-observability links unchanged' do - expect(doc.to_s).to eq(input) - end - end + before do + allow(Gitlab::Observability).to receive(:embeddable_url).and_return('embeddable-url') + stub_config_setting(url: "https://www.gitlab.com") + end - context 'when the document contains an embeddable observability link' do - let(:url) { 'https://observe.gitlab.com/12345' } + describe '#filter?' do + context 'when the document contains a valid observability link' do + let(:url) { "https://www.gitlab.com/groups/some-group/-/observability/test" } it 'leaves the original link unchanged' do expect(doc.at_css('a').to_s).to eq(input) @@ -30,17 +25,34 @@ RSpec.describe Banzai::Filter::InlineObservabilityFilter do node = doc.at_css('.js-render-observability') expect(node).to be_present - expect(node.attribute('data-frame-url').to_s).to eq(url) + expect(node.attribute('data-frame-url').to_s).to eq('embeddable-url') + expect(Gitlab::Observability).to have_received(:embeddable_url).with(url).once end end - context 'when feature flag is disabled' do - let(:url) { 'https://observe.gitlab.com/12345' } + context 'with duplicate URLs' do + let(:url) { "https://www.gitlab.com/groups/some-group/-/observability/test" } + let(:input) { %(<a href="#{url}">example1</a><a href="#{url}">example2</a>) } - before do - stub_feature_flags(observability_group_tab: false) + where(:embeddable_url) do + [ + 'not-nil', + nil + ] end + with_them do + it 'calls Gitlab::Observability.embeddable_url only once' do + allow(Gitlab::Observability).to receive(:embeddable_url).with(url).and_return(embeddable_url) + + filter(input) + + expect(Gitlab::Observability).to have_received(:embeddable_url).with(url).once + end + end + end + + shared_examples 'does not embed observabilty' do it 'leaves the original link unchanged' do expect(doc.at_css('a').to_s).to eq(input) end @@ -51,5 +63,39 @@ RSpec.describe Banzai::Filter::InlineObservabilityFilter do expect(node).not_to be_present end end + + context 'when the embeddable url is nil' do + let(:url) { "https://www.gitlab.com/groups/some-group/-/something-else/test" } + + before do + allow(Gitlab::Observability).to receive(:embeddable_url).and_return(nil) + end + + it_behaves_like 'does not embed observabilty' + end + + context 'when the document has an unrecognised link' do + let(:url) { "https://www.gitlab.com/groups/some-group/-/something-else/test" } + + it_behaves_like 'does not embed observabilty' + + it 'does not build the embeddable url' do + expect(Gitlab::Observability).not_to have_received(:embeddable_url) + end + end + + context 'when feature flag is disabled' do + let(:url) { "https://www.gitlab.com/groups/some-group/-/observability/test" } + + before do + stub_feature_flags(observability_group_tab: false) + end + + it_behaves_like 'does not embed observabilty' + + it 'does not build the embeddable url' do + expect(Gitlab::Observability).not_to have_received(:embeddable_url) + end + end end end |