edit_spec.rb 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Knowledge Base Locale Answer Edit', type: :system do
  4. include_context 'basic Knowledge Base'
  5. before do
  6. published_answer && draft_answer && internal_answer
  7. end
  8. it 'wraps long texts' do
  9. long_string = '3KKFA9DAWE9VJYNNnpYRRtMwfa168O1yvpD2t9QXsfb3cppGV6KZ12q0UUJIy5r4Exfk18GnWPR0A3SoDsjxIHz1Gcu4aCEVzenilSOu4gAfxnB6k3mSBUOGIfdgChEBYhcHGgiCmV2EoXu4gG7GAJxKJhM2d4NUiL5RZttGtMXYYFr2Jsg7MV7xXGcygnsLMYqnwzOJxBK0vH3fzhdIZd6YrqR3fggaY0RyKtVigOBZ2SETC8s238Z9eDL4gfUW'
  10. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{draft_answer.id}/edit"
  11. within(:active_content) do
  12. find('.richtext-content').send_keys long_string
  13. expect(page).to have_css('.js-submit') { |elem| !elem.obscured? }
  14. expect(page).to have_css('.page-header-title') { |elem| !elem.obscured? }
  15. end
  16. end
  17. context 'add weblink' do
  18. def open_editor_and_add_link(input)
  19. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{draft_answer.id}/edit"
  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. find('a[data-action="embed_video"]').click
  47. within('.popover-content') do
  48. find('input').fill_in with: 'https://www.youtube.com/watch?v=vTTzwJsHpU8'
  49. find('[type=submit]').click
  50. end
  51. within('.richtext-content') do
  52. expect(page).to have_text('( widget: video, provider: youtube, id: vTTzwJsHpU8 )')
  53. end
  54. end
  55. it 'loads stored' do
  56. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{published_answer_with_video.id}"
  57. iframe = find('iframe')
  58. expect(iframe['src']).to start_with('https://www.youtube.com/embed/')
  59. end
  60. end
  61. context 'tags' do
  62. before do
  63. visit "#knowledge_base/#{knowledge_base.id}/locale/#{locale_name}/answer/#{published_answer_with_tag.id}/edit"
  64. end
  65. let(:new_tag_name) { 'capybara_kb_tag' }
  66. it 'adds a new tag' do
  67. within :active_content do
  68. click '.js-newTagLabel'
  69. elem = find('.js-newTagInput')
  70. elem.fill_in with: new_tag_name
  71. elem.send_keys :return
  72. wait.until_exists { published_answer_with_tag.reload.tag_list.include? new_tag_name }
  73. expect(page).to have_css('a.js-tag', text: new_tag_name)
  74. end
  75. end
  76. it 'shows an existing tag' do
  77. within :active_content do
  78. expect(page).to have_css('a.js-tag', text: published_answer_tag_name)
  79. end
  80. end
  81. it 'deletes a tag' do
  82. within :active_content do
  83. find('.list-item', text: published_answer_tag_name)
  84. .find('.js-delete').click
  85. expect(page).to have_no_css('a.js-tag', text: published_answer_tag_name)
  86. wait.until_exists { published_answer_with_tag.reload.tag_list.exclude? published_answer_tag_name }
  87. end
  88. end
  89. end
  90. context 'deleted by another user' do
  91. before do
  92. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{published_answer.id}/edit"
  93. end
  94. it 'shows not available', performs_jobs: true do
  95. find(:active_content, text: published_answer.translations.first.title)
  96. perform_enqueued_jobs do
  97. ActiveRecord::Base.transaction do
  98. published_answer.destroy
  99. end
  100. end
  101. within :active_content do
  102. expect(page).to have_text('The page is not available anymore')
  103. end
  104. end
  105. end
  106. context 'updated by another user' do
  107. before do
  108. ensure_websocket do
  109. visit "#knowledge_base/#{knowledge_base.id}/locale/#{primary_locale.system_locale.locale}/answer/#{published_answer.id}/edit"
  110. end
  111. travel 1.minute
  112. end
  113. it 'shows new content', performs_jobs: true do
  114. find(:active_content, text: published_answer.translations.first.title)
  115. accept_prompt do
  116. perform_enqueued_jobs do
  117. Transaction.execute do
  118. published_answer.translations.first.update! title: 'new title'
  119. end
  120. end
  121. end
  122. within :active_content do
  123. expect(page).to have_text('new title')
  124. end
  125. end
  126. end
  127. end