Fixed #3039 - Embedding Youtube Videos in KB containing "-" does not work

This commit is contained in:
Mantas Masalskis 2020-04-28 01:43:33 +03:00 committed by Thorsten Eckel
parent cbf5359589
commit ce91b8f181
5 changed files with 61 additions and 2 deletions

View file

@ -4,8 +4,9 @@ class App.UiElement.richtext.additions.RichTextToolPopupVideo extends App.UiElem
@regexps: { @regexps: {
youtube: [ youtube: [
/youtube.com\/watch\?v=([\w]+)/ /youtube.com\/watch\?v=(\S[^:#?&/]+)/
/youtu.be\/([\w]+)/ /youtu.be\/(\S[^:#?&/]+)/
/youtube.com\/embed\/(\S[^:#?&/]+)/
], ],
vimeo: [ vimeo: [
/vimeo.com\/([\w]+)/ /vimeo.com\/([\w]+)/

View file

@ -0,0 +1,13 @@
<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css">
<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/kb_video_embeding.js", nonce: true %>
<style type="text/css">
body {
padding-top: 0px;
}
</style>
<%= javascript_tag nonce: true do -%>
<% end -%>
<div id="qunit" class="u-dontfold"></div>

View file

@ -30,6 +30,7 @@ Zammad::Application.routes.draw do
match '/tests_taskbar', to: 'tests#taskbar', via: :get match '/tests_taskbar', to: 'tests#taskbar', via: :get
match '/tests_text_module', to: 'tests#text_module', via: :get match '/tests_text_module', to: 'tests#text_module', via: :get
match '/tests_color_object', to: 'tests#color_object', via: :get match '/tests_color_object', to: 'tests#color_object', via: :get
match '/tests_kb_video_embeding', to: 'tests#kb_video_embeding', via: :get
match '/tests/wait/:sec', to: 'tests#wait', via: :get match '/tests/wait/:sec', to: 'tests#wait', via: :get
match '/tests/raised_exception', to: 'tests#error_raised_exception', via: :get match '/tests/raised_exception', to: 'tests#error_raised_exception', via: :get

View file

@ -0,0 +1,38 @@
test('kb video url parsing and converting to embeding url', function() {
var klass = App.UiElement.richtext.additions.RichTextToolPopupVideo;
var parsed = klass.detectProviderAndId('https://www.youtube.com/watch?v=vTTzwJsHpU8')
equal(parsed[0], 'youtube')
equal(parsed[1], 'vTTzwJsHpU8')
var parsed = klass.detectProviderAndId('https://www.youtube.com/watch?v=vTTzwJsHpU8&other=true')
equal(parsed[0], 'youtube')
equal(parsed[1], 'vTTzwJsHpU8')
var parsed = klass.detectProviderAndId('https://www.youtube.com/watch?v=vTTzwJsHpU8#hashtag')
equal(parsed[0], 'youtube')
equal(parsed[1], 'vTTzwJsHpU8')
var parsed = klass.detectProviderAndId('https://www.youtube.com/watch?v=_EYF1-2uiIg')
equal(parsed[0], 'youtube')
equal(parsed[1], '_EYF1-2uiIg')
var parsed = klass.detectProviderAndId('https://www.youtu.be/vTTzwJsHpU8')
equal(parsed[0], 'youtube')
equal(parsed[1], 'vTTzwJsHpU8')
var parsed = klass.detectProviderAndId('https://www.youtube.com/embed/vTTzwJsHpU8')
equal(parsed[0], 'youtube')
equal(parsed[1], 'vTTzwJsHpU8')
var parsed = klass.detectProviderAndId('https://www.vimeo.com/358296442')
equal(parsed[0], 'vimeo')
equal(parsed[1], '358296442')
})

View file

@ -141,4 +141,10 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we
q_unit_tests('taskbar') q_unit_tests('taskbar')
end end
end end
context 'Knowlede Base Editor' do
it 'Vdeo Embeding' do
q_unit_tests('kb_video_embeding')
end
end
end end