Skip to content

Commit

Permalink
Fixes #5145 - Public Knowledge Base Bread crumbs unexpectly translated
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas committed May 6, 2024
1 parent 8a769b4 commit 90f23fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/knowledge_base_breadcrumb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def calculate_breadcrumb_nonpath(object)
def calculate_breadcrumb_to_category(category)
return [] if category.blank?

output = [category]
output = [find_category(category)]

parent = category
while (parent = find_category(parent&.parent_id))
Expand Down
8 changes: 8 additions & 0 deletions spec/support/knowledge_base_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
create(:knowledge_base_category, knowledge_base: knowledge_base)
end

let :subcategory do
create(:knowledge_base_category, knowledge_base: knowledge_base, parent: category)
end

let :other_category do
create(:knowledge_base_category, knowledge_base: knowledge_base)
end
Expand All @@ -37,6 +41,10 @@
create(:knowledge_base_answer, :published, category: other_category)
end

let :published_answer_in_subcategory do
create(:knowledge_base_answer, :published, category: subcategory)
end

let :published_answer_with_video do
create(:knowledge_base_answer, :published, :with_video, category: category)
end
Expand Down
24 changes: 24 additions & 0 deletions spec/system/knowledge_base_public/guest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@
it { expect(page).to have_breadcrumb_item(knowledge_base.translation.title).at_index(0) }
it { expect(page).to have_breadcrumb_item(category.translation.title).at_index(1) }
end

context 'when looking at translated subcategory' do
let(:translated_title) { Faker::Lorem.sentence }

before do
create(:knowledge_base_translation,
knowledge_base:, kb_locale: alternative_locale)

create(:knowledge_base_category_translation,
category: category, title: translated_title, kb_locale: alternative_locale)

create(:knowledge_base_category_translation,
category: subcategory, kb_locale: alternative_locale)

create(:knowledge_base_answer_translation,
answer: published_answer_in_subcategory, kb_locale: alternative_locale)

visit help_category_path(alternative_locale.system_locale.locale, subcategory)
end

it 'shows translated parent category in breadcrumb' do
expect(page).to have_breadcrumb_item(translated_title).at_index(1)
end
end
end

context 'answer' do
Expand Down

0 comments on commit 90f23fd

Please sign in to comment.