diff --git a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_video.coffee b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_video.coffee index a9677be24..903713436 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_video.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/richtext_additions/popup_video.coffee @@ -4,8 +4,9 @@ class App.UiElement.richtext.additions.RichTextToolPopupVideo extends App.UiElem @regexps: { youtube: [ - /youtube.com\/watch\?v=([\w]+)/ - /youtu.be\/([\w]+)/ + /youtube.com\/watch\?v=(\S[^:#?&/]+)/ + /youtu.be\/(\S[^:#?&/]+)/ + /youtube.com\/embed\/(\S[^:#?&/]+)/ ], vimeo: [ /vimeo.com\/([\w]+)/ diff --git a/app/views/tests/kb_video_embeding.html.erb b/app/views/tests/kb_video_embeding.html.erb new file mode 100644 index 000000000..9fc1cea68 --- /dev/null +++ b/app/views/tests/kb_video_embeding.html.erb @@ -0,0 +1,13 @@ + +<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/kb_video_embeding.js", nonce: true %> + + + +<%= javascript_tag nonce: true do -%> +<% end -%> + +
diff --git a/config/routes/test.rb b/config/routes/test.rb index b89c662a4..f31d43ffb 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -30,6 +30,7 @@ Zammad::Application.routes.draw do match '/tests_taskbar', to: 'tests#taskbar', via: :get match '/tests_text_module', to: 'tests#text_module', 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/raised_exception', to: 'tests#error_raised_exception', via: :get diff --git a/public/assets/tests/kb_video_embeding.js b/public/assets/tests/kb_video_embeding.js new file mode 100644 index 000000000..12138b0f3 --- /dev/null +++ b/public/assets/tests/kb_video_embeding.js @@ -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') +}) diff --git a/spec/system/js/q_unit_spec.rb b/spec/system/js/q_unit_spec.rb index 38ddfefab..3bf06d174 100644 --- a/spec/system/js/q_unit_spec.rb +++ b/spec/system/js/q_unit_spec.rb @@ -141,4 +141,10 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we q_unit_tests('taskbar') end end + + context 'Knowlede Base Editor' do + it 'Vdeo Embeding' do + q_unit_tests('kb_video_embeding') + end + end end