guest_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. require 'rails_helper'
  2. RSpec.describe 'Public Knowledge Base for guest', type: :system, authenticated_as: false do
  3. include_context 'basic Knowledge Base'
  4. before do
  5. published_answer && draft_answer && internal_answer
  6. end
  7. context 'homepage' do
  8. before { visit help_no_locale_path }
  9. it('is redirected to primary locale') { expect(page).to have_current_path help_root_path(primary_locale.system_locale.locale) }
  10. it { expect(page).not_to have_breadcrumb }
  11. it { expect(page).not_to have_editor_bar }
  12. it 'shows category' do
  13. within '.main' do
  14. expect(page).to have_selector(:link_containing, published_answer.category.translation.title)
  15. end
  16. end
  17. it 'does not show answer' do
  18. within '.main' do
  19. expect(page).to have_no_selector(:link_containing, published_answer.translation.title)
  20. end
  21. end
  22. end
  23. context 'category' do
  24. before { visit help_category_path(primary_locale.system_locale.locale, category) }
  25. it { expect(page).to have_breadcrumb }
  26. it 'shows published answer' do
  27. within '.main' do
  28. expect(page).to have_selector(:link_containing, published_answer.translation.title)
  29. end
  30. end
  31. it 'does not show draft answer' do
  32. within '.main' do
  33. expect(page).to have_no_selector(:link_containing, draft_answer.translation.title)
  34. end
  35. end
  36. it 'does not show internal answer' do
  37. within '.main' do
  38. expect(page).to have_no_selector(:link_containing, internal_answer.translation.title)
  39. end
  40. end
  41. context 'breadcrumb' do
  42. it { expect(page).to have_breadcrumb.with(2).items }
  43. it { expect(page).to have_breadcrumb_item(knowledge_base.translation.title).at_index(0) }
  44. it { expect(page).to have_breadcrumb_item(category.translation.title).at_index(1) }
  45. end
  46. end
  47. context 'answer' do
  48. before { visit help_answer_path(primary_locale.system_locale.locale, category, published_answer) }
  49. context 'breadcrumb' do
  50. it { expect(page).to have_breadcrumb.with(3).items }
  51. it { expect(page).to have_breadcrumb_item(knowledge_base.translation.title).at_index(0) }
  52. it { expect(page).to have_breadcrumb_item(category.translation.title).at_index(1) }
  53. it { expect(page).to have_breadcrumb_item(published_answer.translation.title).at_index(2) }
  54. end
  55. end
  56. context 'wrong locale' do
  57. before { visit help_root_path(alternative_locale.system_locale.locale) }
  58. it { expect(page).to have_language_banner }
  59. context 'switch to correct locale after clicking on language banner' do
  60. before do
  61. within '.language-banner' do
  62. click_on 'activate'
  63. end
  64. end
  65. it { expect(page).not_to have_language_banner }
  66. end
  67. end
  68. context 'offer in another locale' do
  69. before do
  70. create(:knowledge_base_translation, kb_locale: alternative_locale)
  71. visit help_answer_path(alternative_locale.system_locale.locale, category, published_answer)
  72. end
  73. it { expect(page).to have_text(published_answer.translation_primary.title) }
  74. it { expect(page).to have_text('only available in these languages') }
  75. it { expect(page).to have_no_selector('h1', text: published_answer.translation_primary.title) }
  76. context 'follow primary locale' do
  77. before { click_on published_answer.translation_primary.title }
  78. it { expect(page).to have_selector('h1', text: published_answer.translation_primary.title) }
  79. end
  80. end
  81. context '404' do
  82. before { visit help_answer_path(primary_locale.system_locale.locale, category, 12_345) }
  83. it { expect(page).to have_text('Page not found') }
  84. end
  85. end