Fixed #3060 - Loading KB-Answers doesn't work for contained images
This commit is contained in:
parent
09a808162d
commit
1da20d3f90
5 changed files with 59 additions and 14 deletions
|
@ -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,
|
||||||
|
success: (img, data) ->
|
||||||
$(nextElem).attr('src', data)
|
$(nextElem).attr('src', data)
|
||||||
cacheOrDone()
|
cacheOrDone()
|
||||||
|
fail: (img) ->
|
||||||
|
$(nextElem).remove()
|
||||||
|
cacheOrDone()
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
callback(output[0].innerHTML)
|
callback(output[0].innerHTML)
|
||||||
|
|
|
@ -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') }
|
||||||
|
|
|
@ -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
|
@ -4,14 +4,17 @@ 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
|
||||||
|
|
||||||
|
context 'given published answer' do
|
||||||
|
let(:answer) { published_answer }
|
||||||
|
|
||||||
it 'adds text' do
|
it 'adds text' do
|
||||||
open_page
|
open_page
|
||||||
insert_kb_answer(target_translation, field)
|
insert_kb_answer(target_translation, field)
|
||||||
|
@ -27,6 +30,28 @@ RSpec.describe 'inserting Knowledge Base answer', type: :system, authenticated:
|
||||||
expect(page).to have_css '.attachments .attachment--row'
|
expect(page).to have_css '.attachments .attachment--row'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
expect(height).to be_positive
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue