link_knowledge_base_answer_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket zoom > Link knowledge base answer', type: :system do
  4. include_context 'basic Knowledge Base'
  5. describe 'Link knowledge base answer', authenticated_as: :authenticate do
  6. include_context 'basic Knowledge Base'
  7. let(:ticket) { create(:ticket, group: Group.find_by(name: 'Users')) }
  8. let(:translation) { published_answer.translations.first }
  9. def authenticate
  10. translation
  11. true
  12. end
  13. shared_examples 'verify linking' do |elasticsearch:|
  14. before do
  15. if elasticsearch
  16. searchindex_model_reload([KnowledgeBase::Translation, KnowledgeBase::Category::Translation, KnowledgeBase::Answer::Translation])
  17. end
  18. visit "#ticket/zoom/#{ticket.id}"
  19. end
  20. it 'allows to look up an answer' do
  21. within :active_content do
  22. find('.link_kb_answers')
  23. within '.link_kb_answers' do
  24. find('.js-add').click
  25. find('.js-input').send_keys translation.title
  26. find(%(li[data-value="#{translation.id}"])).click
  27. expect(find('.link_kb_answers ol')).to have_text translation.title
  28. end
  29. end
  30. end
  31. end
  32. context 'with Elasticsearch', searchindex: true do
  33. include_examples 'verify linking', elasticsearch: true
  34. end
  35. context 'without Elasticsearch' do
  36. include_examples 'verify linking', elasticsearch: false
  37. end
  38. end
  39. describe 'displaying knowledge base answer', authenticated_as: :user do
  40. let(:ticket) { Ticket.first }
  41. let(:draft_translation) { draft_answer.translations.first }
  42. let(:internal_translation) { internal_answer.translations.first }
  43. before do
  44. create(:link, from: ticket, to: draft_answer.translations.first)
  45. create(:link, from: ticket, to: internal_answer.translations.first)
  46. visit "#ticket/zoom/#{ticket.id}"
  47. end
  48. context 'when user is editor' do
  49. let(:user) { true }
  50. it 'shows both linked answers' do
  51. within '.link_kb_answers' do
  52. expect(page)
  53. .to have_text(draft_translation.title)
  54. .and(have_text(internal_translation.title))
  55. end
  56. end
  57. end
  58. context 'when user is reader' do
  59. let(:user) { create(:agent, groups: [ticket.group]) }
  60. it 'shows accessible answer' do
  61. within '.link_kb_answers' do
  62. expect(page)
  63. .to have_no_text(draft_translation.title)
  64. .and(have_text(internal_translation.title))
  65. end
  66. end
  67. end
  68. end
  69. end