2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2020-04-20 09:47:45 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2021-07-22 14:03:33 +00:00
|
|
|
RSpec.describe 'inserting Knowledge Base answer', type: :system, 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
|
2021-12-10 12:37:47 +00:00
|
|
|
wait.until do
|
2020-05-28 08:02:07 +00:00
|
|
|
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
|