sidebar_spec.rb 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket zoom > Sidebar', authenticated_as: :user, time_zone: 'Europe/London', type: :system do
  4. let(:ticket) do
  5. ticket = create(:ticket, customer: customer, group: group)
  6. travel_to close_time do
  7. ticket.update! state: Ticket::State.find_by(name: 'closed')
  8. end
  9. ticket
  10. end
  11. let(:customer) { create(:customer, organization: create(:organization)) }
  12. let(:close_time) { Time.current }
  13. describe 're-openability of a closed ticket' do
  14. before do
  15. visit "#ticket/zoom/#{ticket.id}"
  16. end
  17. let(:state_elem) { find('.sidebar [name=state_id]') }
  18. shared_examples 'shows sidebar as read only' do
  19. it 'shows sidebar as read only' do
  20. within(:active_content) do
  21. expect(state_elem).to match_css(':disabled')
  22. end
  23. end
  24. end
  25. shared_examples 'shows sidebar as updatable' do
  26. it 'shows sidebar as updatable' do
  27. within(:active_content) do
  28. expect(state_elem).to match_css(':enabled')
  29. end
  30. end
  31. end
  32. shared_examples 'check roles' do |customer:, agent:, agent_customer:|
  33. context 'when user is customer' do
  34. let(:user) { ticket.customer }
  35. include_examples customer ? 'shows sidebar as updatable' : 'shows sidebar as read only'
  36. end
  37. context 'when user is agent' do
  38. let(:user) { create(:agent, groups: [ticket.group]) }
  39. include_examples agent ? 'shows sidebar as updatable' : 'shows sidebar as read only'
  40. end
  41. context 'when user is agent-customer' do
  42. let(:user) { create(:agent_and_customer) }
  43. let(:customer) { user }
  44. include_examples agent_customer ? 'shows sidebar as updatable' : 'shows sidebar as read only'
  45. end
  46. end
  47. context 'when ticket is closed and groups.follow_up_possible is "yes"' do
  48. let(:group) { create(:group, follow_up_possible: 'yes') }
  49. include_examples 'check roles', customer: true, agent: true, agent_customer: true
  50. end
  51. context 'when ticket is closed and groups.follow_up_possible is "new_ticket"' do
  52. let(:group) { create(:group, follow_up_possible: 'new_ticket') }
  53. include_examples 'check roles', customer: false, agent: true, agent_customer: false
  54. end
  55. context 'when ticket is closed and groups.follow_up_possible is "new_ticket_after_certain_time"' do
  56. let(:group) { create(:group, follow_up_possible: 'new_ticket_after_certain_time', reopen_time_in_days: 5) }
  57. context 'when ticket was closed within the timeframe' do
  58. let(:close_time) { 3.days.ago }
  59. include_examples 'check roles', customer: true, agent: true, agent_customer: true
  60. end
  61. context 'when ticket was closed outside of the timeframe' do
  62. let(:close_time) { 1.month.ago }
  63. include_examples 'check roles', customer: false, agent: true, agent_customer: false
  64. end
  65. end
  66. end
  67. end