tag_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Public Knowledge Base tag', authenticated_as: false, type: :system do
  4. include_context 'basic Knowledge Base'
  5. context 'when answer with the tag exists' do
  6. before do
  7. published_answer && published_answer_with_tag
  8. visit help_tag_path(locale_name, published_answer_tag_name)
  9. end
  10. it 'displays tag name' do
  11. expect(page).to have_css('h1', text: published_answer_tag_name)
  12. end
  13. it 'lists an answer with the tag' do
  14. expect(page).to have_link(published_answer_with_tag.translations.first.title)
  15. end
  16. it 'does not list another answer' do
  17. expect(page).to have_no_link(published_answer.translations.first.title)
  18. end
  19. it 'does not show empty placeholder' do
  20. expect(page).to have_no_css('.sections-empty')
  21. end
  22. end
  23. context 'when no answers with the tag exists' do
  24. before do
  25. published_answer
  26. visit help_tag_path(locale_name, published_answer_tag_name)
  27. end
  28. it 'shows empty placeholder' do
  29. expect(page).to have_css('.sections-empty')
  30. end
  31. it 'shows no links' do
  32. expect(page).to have_no_css('.main a')
  33. end
  34. it 'displays tag name' do
  35. expect(page).to have_css('h1', text: published_answer_tag_name)
  36. end
  37. end
  38. context 'when KB has a custom address' do
  39. before do
  40. knowledge_base.update! custom_address: '/custom'
  41. allow_any_instance_of(KnowledgeBase)
  42. .to receive(:custom_address_matches?).and_return(true)
  43. published_answer && published_answer_with_tag
  44. visit help_tag_path(locale_name, published_answer_tag_name)
  45. end
  46. let(:prefix) { "https://#{Setting.get('fqdn')}" }
  47. let(:expected_path) { help_tag_path(locale_name, published_answer_tag_name).gsub(%r{/help}, '/custom') }
  48. let(:expected_url) { "#{prefix}#{expected_path}" }
  49. # https://github.com/zammad/zammad/issues/4111
  50. it 'shows tag breadcrumb correctly' do
  51. expect(page)
  52. .to have_breadcrumb_item(published_answer_tag_name)
  53. .at_index(1)
  54. .with_url(expected_url)
  55. end
  56. end
  57. end