ticket_mention_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > Ticket > Mentions', app: :mobile, authenticated_as: :agent, type: :system do
  4. let(:group) { Group.find_by(name: 'Users') }
  5. let(:agent) { create(:agent, groups: [group]) }
  6. let(:ticket) { create(:ticket, group: group) }
  7. def visit_information
  8. visit "/tickets/#{ticket.id}/information"
  9. wait_for_gql('apps/mobile/entities/ticket/graphql/queries/ticketWithMentionLimit.graphql')
  10. end
  11. it 'can subscribe to a ticket inside the ticket action dialog' do
  12. visit_information
  13. expect(find_toggle('Get notified')).to be_toggled_off
  14. expect(Mention.subscribed?(ticket, agent)).to be false
  15. find_button('Show ticket actions').click
  16. find_button('Subscribe').click
  17. wait_for_gql 'shared/entities/ticket/graphql/mutations/subscribe.graphql'
  18. expect(page).to have_button('Unsubscribe')
  19. click_on 'Done'
  20. expect(find_toggle('Get notified')).to be_toggled_on
  21. expect(Mention.subscribed?(ticket, agent)).to be true
  22. end
  23. it 'can unsubscribe from a ticket inside the ticket action dialog', current_user_id: 1 do
  24. Mention.subscribe!(ticket, agent)
  25. visit_information
  26. expect(find_toggle('Get notified')).to be_toggled_on
  27. find_button('Show ticket actions').click
  28. find_button('Unsubscribe').click
  29. wait_for_gql 'shared/entities/ticket/graphql/mutations/unsubscribe.graphql'
  30. expect(page).to have_button('Subscribe')
  31. expect(Mention.subscribed?(ticket, agent)).to be false
  32. end
  33. it 'can subscribe to a ticket in information page' do
  34. visit_information
  35. subscribe_field = find_toggle('Get notified')
  36. expect(subscribe_field).to be_toggled_off
  37. subscribe_field.toggle_on
  38. wait_for_gql 'shared/entities/ticket/graphql/mutations/subscribe.graphql'
  39. expect(subscribe_field).to be_toggled_on
  40. expect(Mention.subscribed?(ticket, agent)).to be true
  41. # don't see myself in a list of subscribers
  42. find_button('Show ticket actions').click
  43. expect(page).to have_button('Unsubscribe')
  44. end
  45. it 'can unsubscribe from a ticket in information page', current_user_id: 1 do
  46. Mention.subscribe!(ticket, agent)
  47. visit_information
  48. subscribe_field = find_toggle('Get notified')
  49. expect(subscribe_field).to be_toggled_on
  50. subscribe_field.toggle_off
  51. wait_for_gql 'shared/entities/ticket/graphql/mutations/unsubscribe.graphql'
  52. expect(subscribe_field).to be_toggled_off
  53. expect(Mention.subscribed?(ticket, agent)).to be false
  54. end
  55. it 'shows list of subscribers and can load all subscribers', current_user_id: 1 do
  56. agents = create_list(:agent, 10, groups: [group])
  57. agents.each { |agent| Mention.subscribe!(ticket, agent) }
  58. visit_information
  59. 5.times { |i| expect(page).to have_text(agents[i].fullname) }
  60. expect(page).to have_no_text(agents[5].fullname)
  61. expect(page).to have_button('Show 5 more')
  62. find_button('Show 5 more').click
  63. (5..9).each { |i| expect(page).to have_text(agents[i].fullname) }
  64. end
  65. end