reader_spec.rb 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Knowledge Base Locale Answer Reader', time_zone: 'Europe/London', type: :system do
  4. include_context 'basic Knowledge Base'
  5. context 'when logged in as editor' do
  6. before do # simulate translation being created before publishing
  7. date = published_answer.published_at - 1.week
  8. published_answer.translations.first.update! created_at: date, updated_at: date
  9. end
  10. context 'state' do
  11. it 'shown as "Draft" for draft' do
  12. open_answer draft_answer
  13. within :active_content do
  14. expect(page).to have_css('.knowledge-base-article-meta', text: 'Draft')
  15. end
  16. end
  17. it 'shown as "Internal" for internal' do
  18. open_answer internal_answer
  19. within :active_content do
  20. expect(page).to have_css('.knowledge-base-article-meta', text: 'Internal')
  21. end
  22. end
  23. it 'shown as "Published" for published' do
  24. open_answer published_answer
  25. within :active_content do
  26. expect(page).to have_css('.knowledge-base-article-meta', text: 'Published')
  27. end
  28. end
  29. it 'shown as "Archived" for archived' do
  30. open_answer archived_answer
  31. within :active_content do
  32. expect(page).to have_css('.knowledge-base-article-meta', text: 'Archived')
  33. end
  34. end
  35. end
  36. context 'time' do
  37. it 'shown for internal' do
  38. travel_to internal_answer.internal_at - 1.week do
  39. internal_answer.translations.first.touch
  40. end
  41. open_answer internal_answer
  42. within :active_content, '.knowledge-base-article-meta' do
  43. expect(page).to have_time_tag(internal_answer.internal_at)
  44. end
  45. end
  46. it 'shown for published' do
  47. travel_to published_answer.published_at do
  48. published_answer.translations.first.touch
  49. end
  50. open_answer published_answer
  51. within :active_content, '.knowledge-base-article-meta' do
  52. expect(page).to have_time_tag published_answer.published_at
  53. end
  54. end
  55. it 'internal publishing time shown if published is present too' do
  56. published_answer.update! internal_at: published_answer.published_at - 1.day
  57. travel_to published_answer.published_at - 2.days do
  58. published_answer.translations.first.touch
  59. end
  60. open_answer published_answer
  61. within :active_content, '.knowledge-base-article-meta' do
  62. expect(page).to have_time_tag published_answer.internal_at
  63. end
  64. end
  65. it 'not shown for draft' do
  66. open_answer draft_answer
  67. within :active_content, '.knowledge-base-article-meta' do
  68. expect(page).not_to have_time_tag
  69. end
  70. end
  71. it 'not shown for archived' do
  72. open_answer archived_answer
  73. within :active_content, '.knowledge-base-article-meta' do
  74. expect(page).not_to have_time_tag
  75. end
  76. end
  77. it 'replaced by update time if later than publishing time' do
  78. translation = published_answer.translations.first
  79. translation.content.update! body: 'updated body'
  80. open_answer published_answer
  81. within :active_content, '.knowledge-base-article-meta' do
  82. expect(page).to have_time_tag published_answer.translations.first.updated_at
  83. end
  84. end
  85. end
  86. context 'user', current_user_id: -> { user.id } do
  87. let(:user) { create(:admin) }
  88. it 'shown for internal' do
  89. open_answer internal_answer
  90. within :active_content, '.knowledge-base-article-meta' do
  91. expect(page).to have_text user.fullname
  92. end
  93. end
  94. it 'shown for published' do
  95. open_answer published_answer
  96. within :active_content, '.knowledge-base-article-meta' do
  97. expect(page).to have_text user.fullname
  98. end
  99. end
  100. it 'not shown for draft' do
  101. open_answer draft_answer
  102. within :active_content, '.knowledge-base-article-meta' do
  103. expect(page).to have_no_text user.fullname
  104. end
  105. end
  106. it 'not shown for archived' do
  107. open_answer archived_answer
  108. within :active_content, '.knowledge-base-article-meta' do
  109. expect(page).to have_no_text user.fullname
  110. end
  111. end
  112. it 'shows translation updater rather than publisher' do
  113. published_answer.update! published_by_id: 1
  114. open_answer published_answer
  115. within :active_content, '.knowledge-base-article-meta' do
  116. expect(page).to have_text user.fullname
  117. end
  118. end
  119. end
  120. end
  121. context 'when logged in as reader', authenticated_as: :visitor, current_user_id: -> { editor.id } do
  122. let(:editor) { create(:admin, firstname: 'Editor') }
  123. let(:visitor) { create(:agent) }
  124. it 'state not shown' do
  125. open_answer published_answer
  126. within :active_content, '.knowledge-base-article-meta' do
  127. expect(page).to have_no_text('published')
  128. end
  129. end
  130. it 'time shown' do
  131. travel_to published_answer.published_at - 1.week do
  132. published_answer.translations.first.touch
  133. end
  134. open_answer published_answer
  135. within :active_content, '.knowledge-base-article-meta' do
  136. expect(page).to have_time_tag(published_answer.published_at)
  137. end
  138. end
  139. it 'user shown' do
  140. open_answer published_answer
  141. within :active_content, '.knowledge-base-article-meta' do
  142. expect(page).to have_text editor.fullname
  143. end
  144. end
  145. it 'opens preview' do
  146. open_answer published_answer
  147. new_window = window_opened_by { click '.icon-external' }
  148. within_window new_window do
  149. within '.main--article' do
  150. expect(page).to have_text(published_answer.translations.first.title)
  151. end
  152. end
  153. end
  154. it 'shows linked ticket user is authorized to see' do
  155. ticket1 = create(:ticket, title: 'visible linked ticket')
  156. ticket2 = create(:ticket, title: 'hidden linked ticket')
  157. visitor.groups << ticket1.group
  158. create(:link, from: ticket1, to: published_answer.translations.first)
  159. create(:link, from: ticket2, to: published_answer.translations.first)
  160. open_answer published_answer
  161. within :active_content do
  162. expect(page).to have_text(ticket1.title).and(have_no_text(ticket2.title))
  163. end
  164. end
  165. end
  166. def open_answer(answer, locale: primary_locale)
  167. visit "knowledge_base/#{answer.category.knowledge_base.id}/locale/#{locale.system_locale.locale}/answer/#{answer.id}"
  168. end
  169. end