edit_spec.rb 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. require 'rails_helper'
  2. RSpec.describe 'Knowledge Base Locale Answer Edit', type: :system, authenticated_as: true do
  3. include_context 'basic Knowledge Base'
  4. before do
  5. published_answer && draft_answer && internal_answer
  6. end
  7. it 'wraps long texts' do
  8. long_string = '3KKFA9DAWE9VJYNNnpYRRtMwfa168O1yvpD2t9QXsfb3cppGV6KZ12q0UUJIy5r4Exfk18GnWPR0A3SoDsjxIHz1Gcu4aCEVzenilSOu4gAfxnB6k3mSBUOGIfdgChEBYhcHGgiCmV2EoXu4gG7GAJxKJhM2d4NUiL5RZttGtMXYYFr2Jsg7MV7xXGcygnsLMYqnwzOJxBK0vH3fzhdIZd6YrqR3fggaY0RyKtVigOBZ2SETC8s238Z9eDL4gfUW'
  9. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{draft_answer.id}/edit"
  10. within(:active_content) do
  11. find('.richtext-content').send_keys long_string
  12. expect(page).to have_css('.js-submit') { |elem| !elem.obscured? }
  13. expect(page).to have_css('.page-header-title') { |elem| !elem.obscured? }
  14. end
  15. end
  16. context 'add weblink' do
  17. def open_editor_and_add_link(input)
  18. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{draft_answer.id}/edit"
  19. sleep 3 # wait for popover killer to pass
  20. find('a[data-action="link"]').click
  21. within('.popover-content') do
  22. find('input').fill_in with: input
  23. find('[type=submit]').click
  24. end
  25. end
  26. it 'allows mailto links' do
  27. open_editor_and_add_link 'mailto:test@example.com'
  28. expect(page).to have_selector('a[href="mailto:test@example.com"]')
  29. end
  30. it 'allows link with a protocol' do
  31. open_editor_and_add_link 'protocol://example.org'
  32. expect(page).to have_selector('a[href="protocol://example.org"]')
  33. end
  34. it 'allows relative link' do
  35. open_editor_and_add_link '/path'
  36. expect(page).to have_selector('a[href="/path"]')
  37. end
  38. it 'allows non-protocol URL and prepends default protocol' do
  39. open_editor_and_add_link 'example.com'
  40. expect(page).to have_selector('a[href="http://example.com"]')
  41. end
  42. end
  43. context 'embedded video' do
  44. it 'has adding functionality' do
  45. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{published_answer.id}/edit"
  46. sleep 3 # wait for popover killer to pass
  47. find('a[data-action="embed_video"]').click
  48. within('.popover-content') do
  49. find('input').fill_in with: 'https://www.youtube.com/watch?v=vTTzwJsHpU8'
  50. find('[type=submit]').click
  51. end
  52. within('.richtext-content') do
  53. expect(page).to have_text('( widget: video, provider: youtube, id: vTTzwJsHpU8 )')
  54. end
  55. end
  56. it 'loads stored' do
  57. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{published_answer_with_video.id}"
  58. iframe = find('iframe')
  59. expect(iframe['src']).to start_with('https://www.youtube.com/embed/')
  60. end
  61. end
  62. end