detail_view_edit_spec.rb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/apps/mobile_old/examples/core_workflow_examples'
  4. RSpec.describe 'Mobile > Search > User > Edit', app: :mobile, authenticated_as: :authenticate, type: :system do
  5. let(:user) { create(:customer, :with_org, address: 'Berlin') }
  6. let(:group) { create(:group) }
  7. let(:ticket) { create(:ticket, customer: user, group: group) }
  8. let(:agent) { create(:agent, groups: [group]) }
  9. def authenticate
  10. agent
  11. end
  12. def open_user
  13. visit "/users/#{user.id}"
  14. wait_for_gql('shared/entities/user/graphql/queries/user.graphql')
  15. end
  16. def open_user_edit
  17. open_user
  18. click('button', text: 'Edit')
  19. wait_for_form_to_settle('user-edit')
  20. end
  21. context 'when opening via search' do
  22. before do
  23. visit '/search/user'
  24. fill_in placeholder: 'Search…', with: user.email
  25. wait_for_gql('apps/mobile/pages/search/graphql/queries/searchOverview.graphql')
  26. click '[role="tabpanel"]', text: user.fullname
  27. end
  28. it 'shows user details' do
  29. expect(page).to have_current_path("/mobile/users/#{user.id}")
  30. end
  31. end
  32. context 'with custom attribute', db_strategy: :reset do
  33. def authenticate
  34. create(:object_manager_attribute_text, object_name: 'User', name: 'text_attribute', display: 'Text Attribute', screens: { edit: { '-all-' => { shown: true, required: false } }, view: { '-all-' => { shown: true, required: false } } })
  35. ObjectManager::Attribute.migration_execute
  36. agent
  37. end
  38. it 'show attribute only when value exists' do
  39. open_user
  40. expect(page).to have_no_css('section', text: 'Text Attribute')
  41. click_on('Edit')
  42. wait_for_form_to_settle('user-edit')
  43. within_form(form_updater_gql_number: 1) do
  44. find_input('Text Attribute').type('foobar')
  45. end
  46. click_on('Save')
  47. wait_for_gql('shared/graphql/subscriptions/userUpdates.graphql')
  48. expect(find('section', text: 'Text Attribute')).to have_text('foobar')
  49. end
  50. end
  51. context 'with basic attributes' do
  52. let(:closed_tickets) do
  53. create_list(:ticket, 2, customer: user, group: group, state: Ticket::State.find_by(name: 'closed'))
  54. end
  55. before do
  56. ticket
  57. closed_tickets
  58. open_user
  59. end
  60. it 'shows basic data' do
  61. expect(find("[role=\"img\"][aria-label=\"Avatar (#{user.fullname})\"]")).to have_text(user.firstname[0].upcase + user.lastname[0].upcase)
  62. expect(page).to have_text(user.fullname)
  63. expect(page).to have_css('a', text: user.organization.name)
  64. expect(find('section', text: 'Email')).to have_text(user.email)
  65. expect(find('section', text: 'Address')).to have_text(user.address)
  66. end
  67. it 'shows links to open and closed issues' do
  68. expect(find_all('[data-test-id="section-menu-item"]'))
  69. .to contain_exactly(have_text("open\n1"), have_text("closed\n2"))
  70. end
  71. end
  72. context 'with secondary organizations' do
  73. let(:organizations) { create_list(:organization, 4) }
  74. it 'shows secondary organizations' do
  75. user.update! organizations: organizations
  76. open_user
  77. expect(page)
  78. .to have_multiple_texts(organizations[0..2].map(&:name))
  79. .and(have_no_text(organizations.last.name))
  80. click_on('Show 1 more')
  81. wait_for_gql('shared/entities/user/graphql/queries/user.graphql', number: 2)
  82. expect(page).to have_multiple_texts(organizations.map(&:name))
  83. end
  84. it 'adds secondary organizations' do
  85. open_user_edit
  86. find_autocomplete('Secondary organizations')
  87. .search_for_options(organizations[0..1].map(&:name))
  88. click_on 'Save'
  89. expect(page)
  90. .to have_multiple_texts(organizations[0..1].map(&:name))
  91. end
  92. end
  93. context 'when editing' do
  94. before do
  95. open_user_edit
  96. end
  97. let(:organization) { create(:organization) }
  98. shared_examples 'editing user data' do
  99. it 'supports editing user data' do
  100. within_form(form_updater_gql_number: 1) do
  101. find_input('First name').type('Foo')
  102. find_input('Last name').type('Bar')
  103. find_input('Address').type('München')
  104. find_autocomplete('Organization').search_for_option(organization.name)
  105. end
  106. click_on('Save')
  107. wait_for_gql('shared/graphql/subscriptions/userUpdates.graphql')
  108. expect(find('[role="img"][aria-label="Avatar (Foo Bar)"]')).to have_text('FB')
  109. expect(page).to have_text('Foo Bar')
  110. expect(page).to have_css('a', text: organization.name)
  111. expect(find('section', text: 'Address')).to have_text('München')
  112. expect(user.reload).to have_attributes(firstname: 'Foo', lastname: 'Bar', address: 'München')
  113. end
  114. end
  115. it_behaves_like 'editing user data'
  116. it 'has an always enabled cancel button' do
  117. find_button('Cancel').click
  118. expect(page).to have_no_css('[role=dialog]')
  119. end
  120. it 'shows a confirmation dialog when leaving the screen' do
  121. within_form(form_updater_gql_number: 1) do
  122. find_input('Address').type('foobar')
  123. end
  124. find_button('Cancel').click
  125. within '[role=alert]' do
  126. expect(page).to have_text('Are you sure? You have unsaved changes that will get lost.')
  127. end
  128. end
  129. context 'when user is email-less' do
  130. let(:user) { create(:customer, :without_email) }
  131. it 'updates User record' do
  132. within_form(form_updater_gql_number: 1) do
  133. find_input('First name').type('No Email')
  134. click_on('Save')
  135. wait_for_gql('shared/graphql/subscriptions/userUpdates.graphql')
  136. expect(user.reload).to have_attributes(firstname: 'No Email')
  137. end
  138. end
  139. end
  140. context 'with admin privileges (#5066)' do
  141. let(:agent) { create(:admin) }
  142. it_behaves_like 'editing user data'
  143. end
  144. end
  145. describe 'Core Workflow' do
  146. include_examples 'mobile app: core workflow' do
  147. let(:object_name) { 'User' }
  148. let(:form_updater_gql_number) { 1 }
  149. let(:before_it) do
  150. lambda {
  151. open_user
  152. click('button', text: 'Edit')
  153. wait_for_form_to_settle('user-edit')
  154. }
  155. end
  156. end
  157. end
  158. end