inserting_knowledge_base_answer_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'inserting Knowledge Base answer', type: :system, searchindex: true do
  4. include_context 'basic Knowledge Base'
  5. let(:field) { find(:richtext) }
  6. let(:target_translation) { answer.translations.first }
  7. before do
  8. answer
  9. searchindex_model_reload([::KnowledgeBase::Translation, ::KnowledgeBase::Category::Translation, ::KnowledgeBase::Answer::Translation])
  10. end
  11. context 'when published answer' do
  12. let(:answer) { published_answer }
  13. it 'adds text' do
  14. open_page
  15. insert_kb_answer(target_translation, field)
  16. expect(field).to have_text target_translation.content.body
  17. end
  18. it 'attaches file' do
  19. open_page
  20. insert_kb_answer(target_translation, field)
  21. within(:active_content) do
  22. within '.attachments .attachment--row' do
  23. store_object = Store.where(store_object_id: Store::Object.lookup(name: 'UploadCache')).last
  24. expect(page).to have_css ".attachment-delete[data-id='#{store_object.id}']", visible: :all # delete button is hidden by default
  25. end
  26. end
  27. end
  28. end
  29. context 'when answer with image' do
  30. let(:answer) { create(:knowledge_base_answer, :with_image, published_at: 1.week.ago) }
  31. it 'inserts image' do
  32. open_page
  33. insert_kb_answer(target_translation, field)
  34. within(:active_content) do
  35. within(:richtext) do
  36. wait.until do
  37. elem = first('img')
  38. script = 'return arguments[0].naturalWidth;'
  39. height = Capybara.current_session.driver.browser.execute_script(script, elem.native)
  40. expect(height).to be_positive
  41. end
  42. end
  43. end
  44. end
  45. end
  46. private
  47. def open_page
  48. visit 'ticket/create'
  49. end
  50. def insert_kb_answer(translation, target_field)
  51. target_field.send_keys('??')
  52. translation.title.slice(0, 3).chars.each { |letter| target_field.send_keys(letter) }
  53. find(:text_module, translation.id).click
  54. end
  55. end