guest_spec.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Public Knowledge Base for guest', authenticated_as: false, type: :system do
  4. include_context 'basic Knowledge Base'
  5. before do
  6. published_answer && draft_answer && internal_answer
  7. end
  8. context 'homepage' do
  9. before { visit help_no_locale_path }
  10. it('is redirected to primary locale') { expect(page).to have_current_path help_root_path(primary_locale.system_locale.locale) }
  11. it { expect(page).not_to have_breadcrumb }
  12. it { expect(page).not_to have_editor_bar }
  13. it 'shows category' do
  14. within '.main' do
  15. expect(page).to have_selector(:link_containing, published_answer.category.translation.title)
  16. end
  17. end
  18. it 'does not show answer' do
  19. within '.main' do
  20. expect(page).to have_no_selector(:link_containing, published_answer.translation.title)
  21. end
  22. end
  23. end
  24. context 'category' do
  25. before { visit help_category_path(primary_locale.system_locale.locale, category) }
  26. it { expect(page).to have_breadcrumb }
  27. it 'shows published answer' do
  28. within '.main' do
  29. expect(page).to have_selector(:link_containing, published_answer.translation.title)
  30. end
  31. end
  32. it 'does not show draft answer' do
  33. within '.main' do
  34. expect(page).to have_no_selector(:link_containing, draft_answer.translation.title)
  35. end
  36. end
  37. it 'does not show internal answer' do
  38. within '.main' do
  39. expect(page).to have_no_selector(:link_containing, internal_answer.translation.title)
  40. end
  41. end
  42. context 'breadcrumb' do
  43. it { expect(page).to have_breadcrumb.with(2).items }
  44. it { expect(page).to have_breadcrumb_item(knowledge_base.translation.title).at_index(0) }
  45. it { expect(page).to have_breadcrumb_item(category.translation.title).at_index(1) }
  46. end
  47. context 'when looking at translated subcategory' do
  48. let(:translated_title) { Faker::Lorem.sentence }
  49. before do
  50. create(:knowledge_base_translation,
  51. knowledge_base:, kb_locale: alternative_locale)
  52. create(:knowledge_base_category_translation,
  53. category: category, title: translated_title, kb_locale: alternative_locale)
  54. create(:knowledge_base_category_translation,
  55. category: subcategory, kb_locale: alternative_locale)
  56. create(:knowledge_base_answer_translation,
  57. answer: published_answer_in_subcategory, kb_locale: alternative_locale)
  58. visit help_category_path(alternative_locale.system_locale.locale, subcategory)
  59. end
  60. it 'shows translated parent category in breadcrumb' do
  61. expect(page).to have_breadcrumb_item(translated_title).at_index(1)
  62. end
  63. end
  64. end
  65. context 'answer' do
  66. before { visit help_answer_path(primary_locale.system_locale.locale, category, published_answer) }
  67. context 'breadcrumb' do
  68. it { expect(page).to have_breadcrumb.with(3).items }
  69. it { expect(page).to have_breadcrumb_item(knowledge_base.translation.title).at_index(0) }
  70. it { expect(page).to have_breadcrumb_item(category.translation.title).at_index(1) }
  71. it { expect(page).to have_breadcrumb_item(published_answer.translation.title).at_index(2) }
  72. end
  73. end
  74. context 'preview token' do
  75. context 'when token is valid' do
  76. let(:token) { Token.renew_token! 'KnowledgeBasePreview', create(:admin).id }
  77. it 'loads draft answer' do
  78. visit help_answer_path(primary_locale.system_locale.locale, category, draft_answer, preview_token: token)
  79. within '.main--article' do
  80. expect(page).to have_text(draft_answer.translations.first.title)
  81. end
  82. end
  83. end
  84. context 'when token user does not have access' do
  85. let(:token) { Token.renew_token! 'KnowledgeBasePreview', create(:customer).id }
  86. it 'loads draft answer' do
  87. visit help_answer_path(primary_locale.system_locale.locale, category, draft_answer, preview_token: token)
  88. expect(page).to have_no_text(draft_answer.translations.first.title)
  89. end
  90. end
  91. end
  92. context 'wrong locale' do
  93. before { visit help_root_path(alternative_locale.system_locale.locale) }
  94. it { expect(page).to have_language_banner }
  95. context 'switch to correct locale after clicking on language banner' do
  96. before do
  97. within '.language-banner' do
  98. click_on 'activate'
  99. end
  100. end
  101. it { expect(page).not_to have_language_banner }
  102. end
  103. end
  104. context 'offer in another locale' do
  105. before do
  106. create(:knowledge_base_translation, kb_locale: alternative_locale)
  107. visit help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
  108. end
  109. it { expect(page).to have_text(published_answer.translation_primary.title) }
  110. it { expect(page).to have_text('only available in these languages') }
  111. it { expect(page).to have_no_selector('h1', text: published_answer.translation_primary.title) }
  112. context 'follow primary locale' do
  113. before { click_on published_answer.translation_primary.title }
  114. it { expect(page).to have_css('h1', text: published_answer.translation_primary.title) }
  115. end
  116. end
  117. context '404' do
  118. before { visit help_answer_path(primary_locale.system_locale.locale, category, 12_345) }
  119. it { expect(page).to have_text('Page not found') }
  120. end
  121. end