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 = -> cacheOrDone = ->
if (nextElem = elems.pop()) if (nextElem = elems.pop())
App.Utils._htmlImage2DataUrlAsync(nextElem, success: (data) -> App.Utils._htmlImage2DataUrlAsync(nextElem,
$(nextElem).attr('src', data) success: (img, data) ->
cacheOrDone() $(nextElem).attr('src', data)
cacheOrDone()
fail: (img) ->
$(nextElem).remove()
cacheOrDone()
) )
else else
callback(output[0].innerHTML) callback(output[0].innerHTML)

View file

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

View file

@ -28,5 +28,9 @@ FactoryBot.define do
trait :with_video do trait :with_video do
content { build(:knowledge_base_answer_translation_content, :with_video) } content { build(:knowledge_base_answer_translation_content, :with_video) }
end end
trait :with_image do
content { build(:knowledge_base_answer_translation_content, :with_image) }
end
end 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' include_context 'basic Knowledge Base'
let(:field) { find(:richtext) } let(:field) { find(:richtext) }
let(:target_translation) { published_answer.translations.first } let(:target_translation) { answer.translations.first }
before do before do
configure_elasticsearch(required: true, rebuild: true) do configure_elasticsearch(required: true, rebuild: true) do
published_answer answer
end end
end end
it 'adds text' do context 'given published answer' do
open_page let(:answer) { published_answer }
insert_kb_answer(target_translation, field)
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 end
it 'attaches file' do context 'given answer with image' do
open_page let(:answer) { create(:knowledge_base_answer, :with_image, published_at: 1.week.ago) }
insert_kb_answer(target_translation, field)
within(:active_content) do it 'inserts image' do
expect(page).to have_css '.attachments .attachment--row' 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
end end