answer_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Copyright (C) 2012-2024 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. visit '/'
  31. travel_to published_answer.published_at - 1.week do
  32. published_answer.translations.first.touch
  33. end
  34. end
  35. context 'publishing time' do
  36. it 'shown for published item' do
  37. open_answer published_answer
  38. within '.article .article-meta' do
  39. expect(page).to have_time_tag published_answer.published_at
  40. end
  41. end
  42. it 'shown for published item scheduled to be archived' do
  43. published_answer.update! archived_at: 1.day.from_now
  44. open_answer published_answer
  45. within '.article .article-meta' do
  46. expect(page).to have_time_tag published_answer.published_at
  47. end
  48. end
  49. it 'not shown for item scheduled to be published' do
  50. draft_answer.update! published_at: 1.day.from_now
  51. open_answer draft_answer
  52. within '.article' do
  53. expect(page).not_to have_time_tag
  54. end
  55. end
  56. it 'not shown for draft item' do
  57. open_answer draft_answer
  58. within '.article' do
  59. expect(page).not_to have_time_tag
  60. end
  61. end
  62. it 'not shown for internal item' do
  63. open_answer internal_answer
  64. within '.article' do
  65. expect(page).not_to have_time_tag
  66. end
  67. end
  68. it 'not shown for archived item' do
  69. open_answer archived_answer
  70. within '.article' do
  71. expect(page).not_to have_time_tag
  72. end
  73. end
  74. it 'replaced by update time if later than publishing time' do
  75. translation = published_answer.translations.first
  76. translation.content.update! body: 'updated body'
  77. open_answer published_answer
  78. within '.article .article-meta' do
  79. expect(page).to have_time_tag published_answer.translations.first.updated_at
  80. end
  81. end
  82. end
  83. end
  84. context 'tags' do
  85. before do
  86. visit help_answer_path(locale_name, category, published_answer_with_tag)
  87. end
  88. it 'shows an associated tag' do
  89. expect(page).to have_css('.tags a', text: published_answer_tag_name)
  90. end
  91. it 'links to tag page' do
  92. click '.tags a'
  93. expect(current_url).to end_with help_tag_path(locale_name, published_answer_tag_name)
  94. end
  95. end
  96. def open_answer(answer, locale: primary_locale.system_locale.locale)
  97. visit help_answer_path(locale, answer.category, answer)
  98. end
  99. end