edit_spec.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Desktop > Ticket > Edit', app: :desktop_view, authenticated_as: :agent, type: :system do
  4. let(:agent) { create(:agent, password: 'test', groups: [group]) }
  5. let(:group) { create(:group) }
  6. let(:article) { create(:ticket_article, :inbound_email, ticket: ticket) }
  7. let(:ticket) { create(:ticket, group:, title: 'Test initial') }
  8. context 'when editing a ticket', db_strategy: :reset do
  9. let(:select_field) { create(:object_manager_attribute_select, :shown_screen, name: 'select_field', display: 'Select field', additional_data_options: { options: { '1' => 'Option 1', '2' => 'Option 2', '3' => 'Option 3' } }) }
  10. let(:text_field) { create(:object_manager_attribute_text, :shown_screen, name: 'text_field', display: 'Text field') }
  11. let(:hide_field_in_create) do
  12. create(:core_workflow,
  13. :active_and_screen,
  14. object: 'Ticket',
  15. screen: 'create_middle',
  16. perform: {
  17. 'ticket.select_field': {
  18. operator: 'hide',
  19. hide: true
  20. },
  21. })
  22. end
  23. let(:show_field_in_edit) do
  24. create(:core_workflow,
  25. :active_and_screen,
  26. object: 'Ticket',
  27. screen: 'edit',
  28. perform: {
  29. 'ticket.select_field': {
  30. operator: 'set_mandatory',
  31. set_mandatory: true
  32. },
  33. })
  34. end
  35. before do
  36. select_field
  37. text_field
  38. ObjectManager::Attribute.migration_execute
  39. hide_field_in_create
  40. show_field_in_edit
  41. article
  42. visit "/ticket/#{ticket.id}"
  43. wait_for_form_to_settle('form-ticket-edit')
  44. end
  45. it 'works correctly' do
  46. #
  47. # Ticket attributes
  48. #
  49. within_form(form_updater_gql_number: 1) do
  50. find_input('Text field').type('text content')
  51. click_on 'Update'
  52. # Check that select field is mandatory.
  53. expect(page).to have_text('This field is required.')
  54. find_select('Select field').select_option('Option 2')
  55. end
  56. click_on 'Update'
  57. wait_for_gql('shared/entities/ticket/graphql/mutations/update.graphql', number: 1)
  58. expect(page).to have_text('Ticket updated successfully')
  59. expect(ticket.reload).to have_attributes(select_field: '2', text_field: 'text content')
  60. #
  61. # Tag
  62. #
  63. click_on 'Add tag'
  64. find_autocomplete('Add tag').open.input_element.fill_in(with: 'test_tag').send_keys(:tab)
  65. wait_for_gql('shared/entities/tags/graphql/mutations/assignment/add.graphql', number: 1)
  66. expect(page).to have_text('Ticket tag added successfully')
  67. expect(ticket.tag_list).to include('test_tag')
  68. #
  69. # Title
  70. #
  71. find('[aria-label="Edit ticket title"]').click
  72. send_keys ' changed', :enter
  73. wait_for_gql('shared/entities/ticket/graphql/mutations/update.graphql', number: 2)
  74. expect(page).to have_text('Ticket updated successfully')
  75. within 'main' do
  76. expect(page).to have_text('Test initial changed')
  77. end
  78. within '#user-taskbar-tabs' do
  79. expect(page).to have_text('Test initial changed')
  80. end
  81. #
  82. # State
  83. #
  84. find_select('State').select_option('closed')
  85. click_on 'Update'
  86. wait_for_gql('shared/entities/ticket/graphql/mutations/update.graphql', number: 3)
  87. expect(page).to have_text('Ticket updated successfully')
  88. expect(ticket.reload.state.name).to eq('closed')
  89. within '#user-taskbar-tabs' do
  90. expect(page).to have_css("a[href=\"/desktop/tickets/#{ticket.id}\"] svg[aria-label=\"check-circle-outline\"]")
  91. end
  92. #
  93. # Reorder taskbar
  94. #
  95. click_on 'New ticket'
  96. expect(page).to have_css('label', text: 'Text field')
  97. expect(page).to have_no_css('label', text: 'Select field')
  98. within '#user-taskbar-tabs' do
  99. expect(page).to have_text("Test initial changed\nReceived Call")
  100. o1 = find('li.draggable', text: 'Test initial changed')
  101. o2 = find('li.draggable', text: 'Received Call')
  102. o1.drag_to(o2)
  103. wait_for_gql('apps/desktop/entities/user/current/graphql/mutations/userCurrentTaskbarItemListPrio.graphql')
  104. expect(page).to have_text("Received Call\nTest initial changed")
  105. end
  106. logout
  107. login(username: agent.login, password: 'test')
  108. within '#user-taskbar-tabs' do
  109. expect(page).to have_text("Received Call\nTest initial changed")
  110. end
  111. end
  112. end
  113. end