inserting_knowledge_base_answer_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'inserting Knowledge Base answer', searchindex: true, type: :system 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. next false if height <= 0
  41. expect(height).to be_positive
  42. end
  43. end
  44. end
  45. end
  46. end
  47. private
  48. def open_page
  49. visit 'ticket/create'
  50. end
  51. def insert_kb_answer(translation, target_field)
  52. target_field.send_keys('??')
  53. translation.title.slice(0, 3).chars.each { |letter| target_field.send_keys(letter) }
  54. find(:text_module, translation.id).click
  55. end
  56. end