diff options
Diffstat (limited to 'spec/lib/banzai/filter')
10 files changed, 108 insertions, 15 deletions
diff --git a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb index 7fd25eac81b..4fc9d9dd4f6 100644 --- a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb +++ b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb @@ -55,4 +55,12 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter, feature_category: :team_planni filter('<p>:tanuki:</p> <p>:party-parrot:</p>') end.not_to exceed_all_query_limit(control_count.count) end + + it 'uses custom emoji from ancestor group' do + subgroup = create(:group, parent: group) + + doc = filter('<p>:tanuki:</p>', group: subgroup) + + expect(doc.css('gl-emoji').size).to eq 1 + end end diff --git a/spec/lib/banzai/filter/markdown_filter_spec.rb b/spec/lib/banzai/filter/markdown_filter_spec.rb index 251e6efe50b..b4fb715b8f0 100644 --- a/spec/lib/banzai/filter/markdown_filter_spec.rb +++ b/spec/lib/banzai/filter/markdown_filter_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Banzai::Filter::MarkdownFilter, feature_category: :team_planning do + using RSpec::Parameterized::TableSyntax include FilterSpecHelper describe 'markdown engine from context' do @@ -22,6 +23,21 @@ RSpec.describe Banzai::Filter::MarkdownFilter, feature_category: :team_planning end end + describe 'parse_sourcepos' do + where(:sourcepos, :expected) do + '1:1-1:4' | { start: { row: 0, col: 0 }, end: { row: 0, col: 3 } } + '12:22-1:456' | { start: { row: 11, col: 21 }, end: { row: 0, col: 455 } } + '0:0-0:0' | { start: { row: 0, col: 0 }, end: { row: 0, col: 0 } } + '-1:2-3:-4' | nil + end + + with_them do + it 'correctly parses' do + expect(described_class.parse_sourcepos(sourcepos)).to eq expected + end + end + end + describe 'code block' do it 'adds language to lang attribute when specified' do result = filter("```html\nsome code\n```", no_sourcepos: true) diff --git a/spec/lib/banzai/filter/quick_action_filter_spec.rb b/spec/lib/banzai/filter/quick_action_filter_spec.rb new file mode 100644 index 00000000000..a2a300d157c --- /dev/null +++ b/spec/lib/banzai/filter/quick_action_filter_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Banzai::Filter::QuickActionFilter, feature_category: :team_planning do + let(:result) { {} } + + it 'detects action in paragraph' do + described_class.call('<p data-sourcepos="1:1-2:3">/quick</p>', {}, result) + + expect(result[:quick_action_paragraphs]).to match_array [{ start_line: 0, end_line: 1 }] + end + + it 'does not detect action in paragraph if no sourcepos' do + described_class.call('<p>/quick</p>', {}, result) + + expect(result[:quick_action_paragraphs]).to be_empty + end + + it 'does not detect action in blockquote' do + described_class.call('<blockquote data-sourcepos="1:1-1:1">/quick</blockquote>', {}, result) + + expect(result[:quick_action_paragraphs]).to be_empty + end + + it 'does not detect action in html block' do + described_class.call('<li data-sourcepos="1:1-1:1">/quick</li>', {}, result) + + expect(result[:quick_action_paragraphs]).to be_empty + end + + it 'does not detect action in code block' do + described_class.call('<code data-sourcepos="1:1-1:1">/quick</code>', {}, result) + + expect(result[:quick_action_paragraphs]).to be_empty + end +end diff --git a/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb b/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb index 9723e9b39f1..9a2e68aaae0 100644 --- a/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb @@ -240,9 +240,15 @@ RSpec.describe Banzai::Filter::References::AlertReferenceFilter, feature_categor # Since we're not batching alert queries across projects, # we have to account for that. - # 1 for both projects, 1 for alerts in each project == 3 + # 1 for routes to find routes.source_id of projects matching paths + # 1 for projects belonging to the above routes + # 1 for preloading routes of the projects + # 1 for loading the namespaces associated to the project + # 1 for loading the routes associated with the namespace + # 1x2 for alerts in each project + # Total == 7 # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359 - max_count += 2 + max_count += 6 expect do reference_filter(markdown) diff --git a/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb index 6e0f9eda0e2..35a3f20f7b7 100644 --- a/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb @@ -287,12 +287,18 @@ RSpec.describe Banzai::Filter::References::CommitReferenceFilter, feature_catego reference_filter(markdown) end.count - markdown = "#{commit_reference} 8b95f2f1 8b95f2f2 8b95f2f3 #{commit2_reference} #{commit3_reference}" + expect(max_count).to eq 0 + + markdown = "#{commit_reference} 8b95f2f1 8b95f2f2 8b95f2f3 #{commit2_reference} #{commit3_reference}" # Commits are not DB entries, they are on the project itself. - # So adding commits from two more projects to the markdown should - # only increase by 1 query - max_count += 1 + # 1 for for routes to find routes.source_id of projects matching paths + # 1 for projects belonging to the above routes + # 1 for preloading routes of the projects + # 1 for loading the namespaces associated to the project + # 1 for loading the routes associated with the namespace + # Total = 5 + max_count += 5 expect do reference_filter(markdown) diff --git a/spec/lib/banzai/filter/references/label_reference_filter_spec.rb b/spec/lib/banzai/filter/references/label_reference_filter_spec.rb index a4587b70dfa..81b08a4c516 100644 --- a/spec/lib/banzai/filter/references/label_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/label_reference_filter_spec.rb @@ -747,10 +747,16 @@ RSpec.describe Banzai::Filter::References::LabelReferenceFilter, feature_categor # Since we're not batching label queries across projects/groups, # queries increase when a new project/group is added. # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359 - # first reference to already loaded project (1), - # second reference requires project and namespace (2), and label (1) + # 1 for for routes to find routes.source_id of projects matching paths + # 1 for projects belonging to the above routes + # 1 for preloading routes of the projects + # 1 for loading the namespaces associated to the project + # 1 for loading the routes associated with the namespace + # 1 for the group + # 1x2 for labels + # Total == 8 markdown = "#{project_reference} #{group2_reference}" - max_count = control_count + 3 + max_count = control_count + 7 expect do reference_filter(markdown) diff --git a/spec/lib/banzai/filter/references/milestone_reference_filter_spec.rb b/spec/lib/banzai/filter/references/milestone_reference_filter_spec.rb index 1fa62d70b72..e778f07227c 100644 --- a/spec/lib/banzai/filter/references/milestone_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/milestone_reference_filter_spec.rb @@ -522,7 +522,7 @@ RSpec.describe Banzai::Filter::References::MilestoneReferenceFilter, feature_cat # queries increase when a new project/group is added. # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359 markdown = "#{project_reference} #{group2_reference}" - control_count += 5 + control_count += 9 expect do reference_filter(markdown) diff --git a/spec/lib/banzai/filter/references/project_reference_filter_spec.rb b/spec/lib/banzai/filter/references/project_reference_filter_spec.rb index 9433862ac8a..c55fff78756 100644 --- a/spec/lib/banzai/filter/references/project_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/project_reference_filter_spec.rb @@ -119,7 +119,7 @@ RSpec.describe Banzai::Filter::References::ProjectReferenceFilter, feature_categ reference_filter(markdown) end.count - expect(max_count).to eq 1 + expect(max_count).to eq 2 markdown = "#{normal_project_reference} #{invalidate_reference(normal_project_reference)} #{group_project_reference} #{nested_project_reference}" diff --git a/spec/lib/banzai/filter/references/reference_cache_spec.rb b/spec/lib/banzai/filter/references/reference_cache_spec.rb index 577e4471433..04877931610 100644 --- a/spec/lib/banzai/filter/references/reference_cache_spec.rb +++ b/spec/lib/banzai/filter/references/reference_cache_spec.rb @@ -79,8 +79,16 @@ RSpec.describe Banzai::Filter::References::ReferenceCache, feature_category: :te expect(control_count).to eq 3 # Since this is an issue filter that is not batching issue queries # across projects, we have to account for that. - # 1 for original issue, 2 for second route/project, 1 for other issue - max_count = control_count + 4 + # 1 for for routes to find routes.source_id of projects matching paths + # 1 for projects belonging to the above routes + # 1 for preloading routes of the projects + # 1 for loading the namespaces associated to the project + # 1 for loading the routes associated with the namespace + # 1x2 for issues + # 1x2 for groups + # 1x2 for work_item_types + # Total = 11 + max_count = control_count + 8 expect do cache.load_references_per_parent(filter.nodes) diff --git a/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb index b196d85ba8a..00eac7262f4 100644 --- a/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb @@ -239,9 +239,15 @@ RSpec.describe Banzai::Filter::References::SnippetReferenceFilter, feature_categ # Since we're not batching snippet queries across projects, # we have to account for that. - # 1 for both projects, 1 for snippets in each project == 3 + # 1 for for routes to find routes.source_id of projects matching paths + # 1 for projects belonging to the above routes + # 1 for preloading routes of the projects + # 1 for loading the namespaces associated to the project + # 1 for loading the routes associated with the namespace + # 1x2 for snippets in each project == 2 + # Total = 7 # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359 - max_count = control_count + 2 + max_count = control_count + 6 expect do reference_filter(markdown) |