DEV: Add tests for wistia onebox. (#15860)

Follow-up to 4ef56b0ca4
This commit is contained in:
Alan Guo Xiang Tan 2022-02-08 13:04:32 +08:00 committed by GitHub
parent 6a2b85710b
commit 7afe768d60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 9 deletions

View File

@ -17,15 +17,15 @@ module Onebox
if extracted_url
iframe_src = extracted_url[1]
<<-HTML
<iframe
src="#{iframe_src}"
width="#{oembed.width}"
height="#{oembed.height}"
title="#{oembed.title}"
frameborder="0"
allowfullscreen
></iframe>
<<~HTML
<iframe
src="#{iframe_src}"
width="#{oembed.width}"
height="#{oembed.height}"
title="#{oembed.title}"
frameborder="0"
allowfullscreen
></iframe>
HTML
else
oembed.html

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
require "rails_helper"
describe Onebox::Engine::WistiaOnebox do
before do
body = '{"version":"1.0","type":"video","html":"\u003ciframe src=\"https://fast.wistia.net/embed/iframe/26sk4lmiix\" title=\"Nice. Video\" allow=\"autoplay; fullscreen\" allowtransparency=\"true\" frameborder=\"0\" scrolling=\"no\" class=\"wistia_embed\" name=\"wistia_embed\" msallowfullscreen width=\"960\" height=\"540\"\u003e\u003c/iframe\u003e\n\u003cscript src=\"https://fast.wistia.net/assets/external/E-v1.js\" async\u003e\u003c/script\u003e","width":960,"height":540,"provider_name":"Wistia, Inc.","provider_url":"https://wistia.com","title":"Nice. ","thumbnail_url":"https://embed-ssl.wistia.com/deliveries/56cacb9a5d6ea04b1f29defaf4b55d1ec979e1b0.jpg?image_crop_resized=960x540","thumbnail_width":960,"thumbnail_height":540,"player_color":"f27398","duration":44.42}'
stub_request(:get, "https://fast.wistia.com/oembed?embedType=iframe&url=https://support.wistia.com/medias/26sk4lmiix")
.to_return(status: 200, body: body, headers: {})
end
it "returns the right HTML markup for the onebox" do
expect(Onebox.preview('https://support.wistia.com/medias/26sk4lmiix').to_s.chomp).to eq(
'<iframe src="https://fast.wistia.net/embed/iframe/26sk4lmiix" width="960" height="540" title="Nice." frameborder="0" allowfullscreen="" seamless="seamless" sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation"></iframe>'
)
end
describe '#placeholder_html' do
it "returns the right img HTML markup" do
expect(Onebox.preview('https://support.wistia.com/medias/26sk4lmiix').placeholder_html).to eq(
"<img src=\"https://embed-ssl.wistia.com/deliveries/56cacb9a5d6ea04b1f29defaf4b55d1ec979e1b0.jpg?image_crop_resized=960x540\" title=\"Nice.\">"
)
end
end
end