read_spec.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Knowledge Base Locale Answer Read', authenticated_as: true, type: :system do
  4. include_context 'basic Knowledge Base'
  5. describe 'tags' do
  6. context 'when answer has tags' do
  7. before do
  8. visit "#knowledge_base/#{knowledge_base.id}/locale/#{locale_name}/answer/#{published_answer_with_tag.id}"
  9. end
  10. it 'has tags container' do
  11. within :active_content do
  12. expect(page).to have_css('.knowledge-base-article-tags--container')
  13. end
  14. end
  15. it 'shows tag' do
  16. within :active_content do
  17. within '.knowledge-base-article-tags--container' do
  18. expect(page).to have_link(published_answer_tag_name)
  19. end
  20. end
  21. end
  22. it 'opens search on clicking' do
  23. within :active_content do
  24. find('.knowledge-base-article-tags--container a', text: published_answer_tag_name).click
  25. end
  26. search_bar = find_by_id 'global-search'
  27. expect(search_bar.value).to eq "tags:#{published_answer_tag_name}"
  28. end
  29. end
  30. context 'when answer has no tags' do
  31. before do
  32. visit "#knowledge_base/#{knowledge_base.id}/locale/#{locale_name}/answer/#{published_answer.id}"
  33. end
  34. it 'has no tags container' do
  35. within :active_content do
  36. expect(page).to have_no_css('.knowledge-base-article-tags--container')
  37. end
  38. end
  39. end
  40. end
  41. context 'deleted by another user' do
  42. before do
  43. visit "#knowledge_base/#{knowledge_base.id}/locale/#{locale_name}/answer/#{published_answer.id}"
  44. end
  45. it 'shows not available', performs_jobs: true do
  46. find(:active_content, text: published_answer.translations.first.title)
  47. perform_enqueued_jobs do
  48. ActiveRecord::Base.transaction do
  49. published_answer.destroy
  50. end
  51. end
  52. within :active_content do
  53. expect(page).to have_text('The page is not available anymore')
  54. end
  55. end
  56. end
  57. context 'updated by another user' do
  58. before do
  59. ensure_websocket do
  60. visit "#knowledge_base/#{knowledge_base.id}/locale/#{locale_name}/answer/#{published_answer.id}"
  61. end
  62. travel 1.minute
  63. end
  64. it 'shows new content', performs_jobs: true do
  65. find(:active_content, text: published_answer.translations.first.title)
  66. perform_enqueued_jobs do
  67. Transaction.execute do
  68. published_answer.translations.first.update! title: 'new title'
  69. end
  70. end
  71. within :active_content do
  72. expect(page).to have_text('new title')
  73. end
  74. end
  75. end
  76. context 'when switching between locales' do
  77. let(:long_locale_name) { 'sr-cyrl-rs' }
  78. let(:long_system_locale) { Locale.find_by(locale: long_locale_name) }
  79. let(:long_kb_locale) { create(:knowledge_base_locale, knowledge_base: knowledge_base, system_locale: long_system_locale) }
  80. let(:short_locale_name) { 'lt' }
  81. let(:short_system_locale) { Locale.find_by(locale: short_locale_name) }
  82. let(:short_kb_locale) { create(:knowledge_base_locale, knowledge_base: knowledge_base, system_locale: short_system_locale) }
  83. before do
  84. long_kb_locale && short_kb_locale
  85. end
  86. it 'switches from long locale back to main locale' do
  87. open_page long_locale_name
  88. select_locale 'English'
  89. within '.knowledge-base-article' do
  90. expect(page).to have_text(published_answer.translations.first.title)
  91. end
  92. end
  93. it 'switches from short locale back to main locale' do
  94. open_page short_locale_name
  95. select_locale 'English'
  96. within '.knowledge-base-article' do
  97. expect(page).to have_text(published_answer.translations.first.title)
  98. end
  99. end
  100. it 'switches from main locale to another locale' do
  101. another_translation = create(:knowledge_base_answer_translation, kb_locale: short_kb_locale, answer: published_answer)
  102. open_page locale_name
  103. select_locale 'Lietuvių'
  104. within '.knowledge-base-article' do
  105. expect(page).to have_text(another_translation.title)
  106. end
  107. end
  108. it 'switches to invalid locale and back' do
  109. open_page('lol')
  110. in_modal do
  111. click_on 'Open in primary locale'
  112. end
  113. within '.knowledge-base-article' do
  114. expect(page).to have_text(published_answer.translations.first.title)
  115. end
  116. end
  117. def open_page(locale_name)
  118. visit "#knowledge_base/#{knowledge_base.id}/locale/#{locale_name}/answer/#{published_answer.id}"
  119. end
  120. def select_locale(text)
  121. within '.js-pickedLanguage + .dropdown' do
  122. click '.icon-arrow-down'
  123. click 'li a', text: text
  124. end
  125. end
  126. end
  127. end