ticket_priority_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/examples/pagination_examples'
  4. RSpec.describe 'Manage > Ticket Priorities', type: :system do
  5. describe 'ajax pagination' do
  6. include_examples 'pagination', model: :ticket_priority, klass: Ticket::Priority, path: 'manage/ticket_priorities'
  7. end
  8. describe 'default create attribute' do
  9. before do
  10. priority
  11. old_priority if defined? old_priority
  12. visit 'manage/ticket_priorities'
  13. end
  14. context 'with existing default priority' do
  15. let(:priority) { Ticket::Priority.find_by(default_create: true) }
  16. it 'shows the badge next to the current default priority' do
  17. within :active_content do
  18. expect(find("tr[data-id='#{priority.id}']")).to have_css('span.badge', text: 'Default for new tickets')
  19. end
  20. end
  21. end
  22. context 'when using set as default action' do
  23. let(:priority) { create(:ticket_priority, name: '4 very high') }
  24. let(:old_priority) { Ticket::Priority.find_by(default_create: true) }
  25. before do
  26. within :active_content do
  27. row = find("tr[data-id=\"#{priority.id}\"]")
  28. row.find('.js-action').click
  29. row.find('.js-setDefaultCreate').click
  30. end
  31. end
  32. it 'shows the badge next to the current default priority' do
  33. within :active_content do
  34. expect(find("tr[data-id='#{old_priority.id}']")).to have_no_css('span.badge', text: 'Default for new tickets')
  35. expect(find("tr[data-id='#{priority.id}']")).to have_css('span.badge', text: 'Default for new tickets')
  36. end
  37. end
  38. end
  39. end
  40. describe 'creating new priority' do
  41. let(:new_priority_name) { '4 very high' }
  42. before do
  43. visit 'manage/ticket_priorities'
  44. click_on 'New Priority'
  45. end
  46. it 'creates a new priority' do
  47. fill_in 'Name', with: new_priority_name
  48. scroll_into_view('button.js-submit', position: :bottom)
  49. click_on 'Submit'
  50. within :active_content do
  51. expect(find("tr[data-id='#{Ticket::Priority.last.id}']")).to have_text(new_priority_name)
  52. end
  53. end
  54. it 'does not show ui_icon field by default' do
  55. within :active_content do
  56. expect(page).to have_no_field('ui_icon')
  57. end
  58. end
  59. context 'with ui_ticket_overview_priority_icon enabled', authenticated_as: :authenticate do
  60. def authenticate
  61. Setting.set('ui_ticket_overview_priority_icon', true)
  62. true
  63. end
  64. it 'does not show ui_icon field by default' do
  65. within :active_content do
  66. expect(page).to have_no_field('ui_icon')
  67. end
  68. end
  69. it 'show ui_icon field when ui_color is set' do
  70. find('[name="ui_color"]').select('High priority')
  71. within :active_content do
  72. expect(page).to have_field('ui_icon')
  73. end
  74. end
  75. end
  76. end
  77. describe 'editing existing priority' do
  78. let(:priority) { create(:ticket_priority, name: '4 very high', ui_color: 'high-priority', ui_icon: 'important') }
  79. let(:new_priority_name) { '5 highest' }
  80. before do
  81. priority
  82. visit 'manage/ticket_priorities'
  83. find("tr[data-id='#{priority.id}']").click
  84. end
  85. it 'edits existing priority' do
  86. fill_in 'Name', with: new_priority_name
  87. scroll_into_view('button.js-submit', position: :bottom)
  88. click_on 'Submit'
  89. within :active_content do
  90. expect(find("tr[data-id='#{priority.id}']")).to have_text(new_priority_name)
  91. end
  92. end
  93. it 'does not show ui_icon field by default' do
  94. within :active_content do
  95. expect(page).to have_no_field('ui_icon')
  96. end
  97. end
  98. context 'with ui_ticket_overview_priority_icon enabled', authenticated_as: :authenticate do
  99. def authenticate
  100. Setting.set('ui_ticket_overview_priority_icon', true)
  101. true
  102. end
  103. it 'shows ui_icon field with existing data' do
  104. within :active_content do
  105. expect(page).to have_select('ui_icon', selected: 'Important')
  106. end
  107. end
  108. end
  109. end
  110. end