Fixed #3060 - Loading KB-Answers doesn't work for contained images

This commit is contained in:
Mantas Masalskis 2020-05-28 10:02:07 +02:00 committed by Thorsten Eckel
parent 09a808162d
commit 1da20d3f90
5 changed files with 59 additions and 14 deletions

View file

@ -1266,9 +1266,13 @@ class App.Utils
cacheOrDone = ->
if (nextElem = elems.pop())
App.Utils._htmlImage2DataUrlAsync(nextElem, success: (data) ->
$(nextElem).attr('src', data)
cacheOrDone()
App.Utils._htmlImage2DataUrlAsync(nextElem,
success: (img, data) ->
$(nextElem).attr('src', data)
cacheOrDone()
fail: (img) ->
$(nextElem).remove()
cacheOrDone()
)
else
callback(output[0].innerHTML)

View file

@ -19,6 +19,12 @@ FactoryBot.define do
end
end
trait :with_image do
transient do
translation_traits { [:with_image] }
end
end
trait :with_attachment do
transient do
attachment { File.open('spec/fixtures/upload/hello_world.txt') }

View file

@ -28,5 +28,9 @@ FactoryBot.define do
trait :with_video do
content { build(:knowledge_base_answer_translation_content, :with_video) }
end
trait :with_image do
content { build(:knowledge_base_answer_translation_content, :with_image) }
end
end
end

File diff suppressed because one or more lines are too long

View file

@ -4,27 +4,52 @@ RSpec.describe 'inserting Knowledge Base answer', type: :system, authenticated:
include_context 'basic Knowledge Base'
let(:field) { find(:richtext) }
let(:target_translation) { published_answer.translations.first }
let(:target_translation) { answer.translations.first }
before do
configure_elasticsearch(required: true, rebuild: true) do
published_answer
answer
end
end
it 'adds text' do
open_page
insert_kb_answer(target_translation, field)
context 'given published answer' do
let(:answer) { published_answer }
expect(field).to have_text target_translation.content.body
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
end
it 'attaches file' do
open_page
insert_kb_answer(target_translation, field)
context 'given answer with image' do
let(:answer) { create(:knowledge_base_answer, :with_image, published_at: 1.week.ago) }
within(:active_content) do
expect(page).to have_css '.attachments .attachment--row'
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)
expect(height).to be_positive
end
end
end
end
end