answer_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Public Knowledge Base answer', type: :system do
  4. include_context 'basic Knowledge Base'
  5. context 'when not authenticated', authenticated_as: false do
  6. context 'video content' do
  7. before do
  8. published_answer_with_video
  9. end
  10. it 'shows video player' do
  11. visit help_answer_path(primary_locale.system_locale.locale, category, published_answer_with_video)
  12. iframe = find('iframe')
  13. expect(iframe['src']).to start_with('https://www.youtube.com/embed/')
  14. end
  15. end
  16. context 'publishing time' do
  17. it 'shown for published item' do
  18. open_answer published_answer
  19. expect(page).to have_css('.article-meta time')
  20. end
  21. it 'shown for published item scheduled to be archived' do
  22. published_answer.update! archived_at: 1.day.from_now
  23. open_answer published_answer
  24. expect(page).to have_css('.article-meta time')
  25. end
  26. end
  27. end
  28. context 'when logged in as editor' do
  29. before do # simulate translation being created before publishing
  30. travel_to published_answer.published_at - 1.week do
  31. published_answer.translations.first.touch
  32. end
  33. end
  34. context 'publishing time' do
  35. it 'shown for published item' do
  36. open_answer published_answer
  37. within '.article .article-meta' do
  38. expect(page).to have_time_tag published_answer.published_at
  39. end
  40. end
  41. it 'shown for published item scheduled to be archived' do
  42. published_answer.update! archived_at: 1.day.from_now
  43. open_answer published_answer
  44. within '.article .article-meta' do
  45. expect(page).to have_time_tag published_answer.published_at
  46. end
  47. end
  48. it 'not shown for item scheduled to be published' do
  49. draft_answer.update! published_at: 1.day.from_now
  50. open_answer draft_answer
  51. within '.article' do
  52. expect(page).not_to have_time_tag
  53. end
  54. end
  55. it 'not shown for draft item' do
  56. open_answer draft_answer
  57. within '.article' do
  58. expect(page).not_to have_time_tag
  59. end
  60. end
  61. it 'not shown for internal item' do
  62. open_answer internal_answer
  63. within '.article' do
  64. expect(page).not_to have_time_tag
  65. end
  66. end
  67. it 'not shown for archived item' do
  68. open_answer archived_answer
  69. within '.article' do
  70. expect(page).not_to have_time_tag
  71. end
  72. end
  73. it 'replaced by update time if later than publishing time' do
  74. translation = published_answer.translations.first
  75. translation.content.update! body: 'updated body'
  76. open_answer published_answer
  77. within '.article .article-meta' do
  78. expect(page).to have_time_tag published_answer.translations.first.updated_at
  79. end
  80. end
  81. end
  82. end
  83. context 'tags' do
  84. before do
  85. visit help_answer_path(locale_name, category, published_answer_with_tag)
  86. end
  87. it 'shows an associated tag' do
  88. expect(page).to have_css('.tags a', text: published_answer_tag_name)
  89. end
  90. it 'links to tag page' do
  91. click '.tags a'
  92. expect(current_url).to end_with help_tag_path(locale_name, published_answer_tag_name)
  93. end
  94. end
  95. def open_answer(answer, locale: primary_locale.system_locale.locale)
  96. visit help_answer_path(locale, answer.category, answer)
  97. end
  98. end