guest_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Public Knowledge Base for guest', type: :system, authenticated_as: false 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. end
  48. context 'answer' do
  49. before { visit help_answer_path(primary_locale.system_locale.locale, category, published_answer) }
  50. context 'breadcrumb' do
  51. it { expect(page).to have_breadcrumb.with(3).items }
  52. it { expect(page).to have_breadcrumb_item(knowledge_base.translation.title).at_index(0) }
  53. it { expect(page).to have_breadcrumb_item(category.translation.title).at_index(1) }
  54. it { expect(page).to have_breadcrumb_item(published_answer.translation.title).at_index(2) }
  55. end
  56. end
  57. context 'wrong locale' do
  58. before { visit help_root_path(alternative_locale.system_locale.locale) }
  59. it { expect(page).to have_language_banner }
  60. context 'switch to correct locale after clicking on language banner' do
  61. before do
  62. within '.language-banner' do
  63. click_on 'activate'
  64. end
  65. end
  66. it { expect(page).not_to have_language_banner }
  67. end
  68. end
  69. context 'offer in another locale' do
  70. before do
  71. create(:knowledge_base_translation, kb_locale: alternative_locale)
  72. visit help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
  73. end
  74. it { expect(page).to have_text(published_answer.translation_primary.title) }
  75. it { expect(page).to have_text('only available in these languages') }
  76. it { expect(page).to have_no_selector('h1', text: published_answer.translation_primary.title) }
  77. context 'follow primary locale' do
  78. before { click_on published_answer.translation_primary.title }
  79. it { expect(page).to have_selector('h1', text: published_answer.translation_primary.title) }
  80. end
  81. end
  82. context '404' do
  83. before { visit help_answer_path(primary_locale.system_locale.locale, category, 12_345) }
  84. it { expect(page).to have_text('Page not found') }
  85. end
  86. end