2020-04-20 09:47:45 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
RSpec.describe 'inserting Knowledge Base answer', type: :system, authenticated_as: true, searchindex: true do
|
2020-04-20 09:47:45 +00:00
|
|
|
include_context 'basic Knowledge Base'
|
|
|
|
|
|
|
|
let(:field) { find(:richtext) }
|
2020-05-28 08:02:07 +00:00
|
|
|
let(:target_translation) { answer.translations.first }
|
2020-04-20 09:47:45 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
configure_elasticsearch(required: true, rebuild: true) do
|
2020-05-28 08:02:07 +00:00
|
|
|
answer
|
2020-04-20 09:47:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-28 08:02:07 +00:00
|
|
|
context 'given published answer' do
|
|
|
|
let(:answer) { published_answer }
|
2020-04-20 09:47:45 +00:00
|
|
|
|
2020-05-28 08:02:07 +00:00
|
|
|
it 'adds text' do
|
|
|
|
open_page
|
|
|
|
insert_kb_answer(target_translation, field)
|
|
|
|
|
|
|
|
expect(field).to have_text target_translation.content.body
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'attaches file' do
|
|
|
|
open_page
|
|
|
|
insert_kb_answer(target_translation, field)
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
expect(page).to have_css '.attachments .attachment--row'
|
|
|
|
end
|
|
|
|
end
|
2020-04-20 09:47:45 +00:00
|
|
|
end
|
|
|
|
|
2020-05-28 08:02:07 +00:00
|
|
|
context 'given answer with image' do
|
|
|
|
let(:answer) { create(:knowledge_base_answer, :with_image, published_at: 1.week.ago) }
|
|
|
|
|
|
|
|
it 'inserts image' do
|
|
|
|
open_page
|
|
|
|
insert_kb_answer(target_translation, field)
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
within(:richtext) do
|
|
|
|
wait(5).until do
|
|
|
|
elem = first('img')
|
|
|
|
script = 'return arguments[0].naturalWidth;'
|
|
|
|
height = Capybara.current_session.driver.browser.execute_script(script, elem.native)
|
2020-04-20 09:47:45 +00:00
|
|
|
|
2020-05-28 08:02:07 +00:00
|
|
|
expect(height).to be_positive
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-20 09:47:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def open_page
|
|
|
|
visit 'ticket/create'
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert_kb_answer(translation, target_field)
|
|
|
|
target_field.send_keys('??')
|
2021-05-28 11:25:36 +00:00
|
|
|
translation.title.slice(0, 3).chars.each { |letter| target_field.send_keys(letter) }
|
2020-04-20 09:47:45 +00:00
|
|
|
|
|
|
|
find(:text_module, translation.id).click
|
|
|
|
end
|
|
|
|
end
|