add_article_hint_spec.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Add Article Hint', authenticated_as: :authenticate, type: :system do
  4. def authenticate
  5. Setting.set 'ui_ticket_add_article_hint', {
  6. 'note-internal': 'internal note',
  7. 'note-public': 'public note',
  8. 'phone-public': 'public phone',
  9. }
  10. user
  11. end
  12. let(:user) { create(:agent, groups: [Ticket.first.group]) }
  13. context 'with a fresh article' do
  14. before do
  15. visit "#ticket/zoom/#{Ticket.first.id}"
  16. end
  17. it 'shows hint for the selected type' do
  18. within '.article-new' do
  19. expect { click '.attachmentPlaceholder' }
  20. .to change { page.has_text?('internal note', wait: 0) }
  21. .to true
  22. end
  23. end
  24. it 'changes hint when changing visibility' do
  25. within '.article-new' do
  26. click '.attachmentPlaceholder'
  27. click '.js-toggleVisibility'
  28. expect(page).to have_text 'public note'
  29. end
  30. end
  31. it 'changes hint when changing type' do
  32. within '.article-new' do
  33. click '.attachmentPlaceholder'
  34. click '.js-selectableTypes'
  35. click '.js-articleTypeItem[data-value=phone]'
  36. expect(page).to have_text 'public phone'
  37. end
  38. end
  39. it 'hides hint when changing to type that has no hint' do
  40. within '.article-new' do
  41. click '.attachmentPlaceholder'
  42. click '.js-selectableTypes'
  43. click '.js-articleTypeItem[data-value=email]'
  44. expect(page).to have_no_css '.article-visibility-text'
  45. end
  46. end
  47. end
  48. context 'with a taskbar' do
  49. before do
  50. create(:taskbar,
  51. key: "Ticket-#{Ticket.first.id}",
  52. user_id: user.id,
  53. state: { ticket: {}, article: article_payload })
  54. visit "#ticket/zoom/#{Ticket.first.id}"
  55. end
  56. context 'when selected type has a hint' do
  57. let(:article_payload) { { type: :phone, internal: false } }
  58. it 'shows a hint' do
  59. within :active_content do
  60. click '.attachmentPlaceholder'
  61. expect(page).to have_text 'public phone'
  62. end
  63. end
  64. it 'hides the hint when changing to visibility that has no hint' do
  65. within '.article-new' do
  66. click '.attachmentPlaceholder'
  67. click '.js-toggleVisibility'
  68. expect(page).to have_no_css '.article-visibility-text'
  69. end
  70. end
  71. end
  72. context 'when selected type has no hint' do
  73. let(:article_payload) { { type: :email, internal: false } }
  74. it 'shows no hint' do
  75. within :active_content do
  76. click '.attachmentPlaceholder'
  77. expect(page).to have_no_css '.article-visibility-text'
  78. end
  79. end
  80. end
  81. end
  82. end