inserting_knowledge_base_answer_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. require 'rails_helper'
  2. RSpec.describe 'inserting Knowledge Base answer', type: :system, authenticated: true, searchindex: true do
  3. include_context 'basic Knowledge Base'
  4. let(:field) { find(:richtext) }
  5. let(:target_translation) { answer.translations.first }
  6. before do
  7. configure_elasticsearch(required: true, rebuild: true) do
  8. answer
  9. end
  10. end
  11. context 'given 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. expect(page).to have_css '.attachments .attachment--row'
  23. end
  24. end
  25. end
  26. context 'given answer with image' do
  27. let(:answer) { create(:knowledge_base_answer, :with_image, published_at: 1.week.ago) }
  28. it 'inserts image' do
  29. open_page
  30. insert_kb_answer(target_translation, field)
  31. within(:active_content) do
  32. within(:richtext) do
  33. wait(5).until do
  34. elem = first('img')
  35. script = 'return arguments[0].naturalWidth;'
  36. height = Capybara.current_session.driver.browser.execute_script(script, elem.native)
  37. expect(height).to be_positive
  38. end
  39. end
  40. end
  41. end
  42. end
  43. private
  44. def open_page
  45. visit 'ticket/create'
  46. end
  47. def insert_kb_answer(translation, target_field)
  48. target_field.send_keys('??')
  49. translation.title.slice(0, 3).split('').each { |letter| target_field.send_keys(letter) }
  50. find(:text_module, translation.id).click
  51. end
  52. end