profile_spec.rb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/examples/core_workflow_examples'
  4. require 'system/examples/text_modules_examples'
  5. RSpec.describe 'User Profile', type: :system do
  6. let(:organizations) { create_list(:organization, 20) }
  7. let(:customer) { create(:customer, organization: organizations[0], organizations: organizations[1..]) }
  8. it 'does show the edit link' do
  9. visit "#user/profile/#{customer.id}"
  10. click '#userAction label'
  11. click_on 'Edit'
  12. modal_ready
  13. end
  14. describe 'object manager attributes maxlength', authenticated_as: :authenticate, db_strategy: :reset do
  15. def authenticate
  16. customer
  17. create(:object_manager_attribute_text, :required_screen, object_name: 'User', name: 'maxtest', display: 'maxtest', data_option: {
  18. 'type' => 'text',
  19. 'maxlength' => 3,
  20. 'null' => true,
  21. 'translate' => false,
  22. 'default' => '',
  23. 'options' => {},
  24. 'relation' => '',
  25. })
  26. ObjectManager::Attribute.migration_execute
  27. true
  28. end
  29. it 'checks ticket create' do
  30. visit "#user/profile/#{customer.id}"
  31. within(:active_content) do
  32. page.find('.profile .js-action').click
  33. page.find('.profile li[data-type=edit]').click
  34. fill_in 'maxtest', with: 'hellu'
  35. expect(page.find_field('maxtest').value).to eq('hel')
  36. end
  37. end
  38. end
  39. describe 'Core Workflow' do
  40. include_examples 'core workflow' do
  41. let(:object_name) { 'User' }
  42. let(:before_it) do
  43. lambda {
  44. ensure_websocket(check_if_pinged: false) do
  45. visit "#user/profile/#{customer.id}"
  46. within(:active_content) do
  47. page.find('.profile .js-action').click
  48. page.find('.profile li[data-type=edit]').click
  49. end
  50. end
  51. }
  52. end
  53. end
  54. end
  55. it 'check that ignored attributes for user popover are not visible' do
  56. visit '/'
  57. fill_in id: 'global-search', with: customer.email
  58. popover_on_hover(find('.nav-tab--search.user'))
  59. expect(page).to have_css('.popover label', count: 2)
  60. end
  61. context 'when calling without session' do
  62. describe 'redirect to' do
  63. it 'login screen', authenticated_as: false do
  64. visit "#user/profile/#{customer.id}"
  65. expect(page).to have_css('#login')
  66. end
  67. end
  68. end
  69. context 'Assign user to multiple organizations #1573', authenticated_as: :authenticate do
  70. def authenticate
  71. customer
  72. true
  73. end
  74. before do
  75. visit "#user/profile/#{customer.id}"
  76. end
  77. it 'shows only first 3 organizations and loads more on demand' do
  78. expect(page).to have_text(organizations[1].name)
  79. expect(page).to have_text(organizations[2].name)
  80. expect(page).to have_no_text(organizations[10].name)
  81. click '.js-showMoreOrganizations a'
  82. expect(page).to have_text(organizations[10].name)
  83. end
  84. end
  85. context 'when ticket changes in user profile', authenticated_as: :authenticate do
  86. let(:ticket) { create(:ticket, title: SecureRandom.uuid, customer: create(:customer, :with_org), group: Group.first) }
  87. def authenticate
  88. ticket
  89. true
  90. end
  91. before do
  92. visit "#user/profile/#{ticket.customer.id}"
  93. end
  94. it 'does update when ticket changes' do
  95. expect(page).to have_text(ticket.title)
  96. ticket.update(title: SecureRandom.uuid)
  97. expect(page).to have_text(ticket.title)
  98. end
  99. end
  100. describe 'Missing secondary organizations in user profile after refreshing with many secondary organizations. #4331' do
  101. before do
  102. visit "#user/profile/#{customer.id}"
  103. page.find('.profile .js-action').click
  104. page.find('.profile li[data-type=edit]').click
  105. end
  106. it 'does show all secondary organizations on edit' do
  107. tokens = page.all('div[data-attribute-name="organization_ids"] .token')
  108. expect(tokens.count).to eq(19)
  109. end
  110. end
  111. context 'with vip attribute' do
  112. it 'shows no crown icon if user is not vip' do
  113. user = create(:user)
  114. visit "#user/profile/#{user.id}"
  115. within '.profile-window' do
  116. expect(page).to have_no_css('.icon-crown')
  117. end
  118. end
  119. it 'shows the crown icon if user is vip' do
  120. user = create(:user, vip: true)
  121. visit "#user/profile/#{user.id}"
  122. within '.profile-window' do
  123. expect(page).to have_css('.icon-crown')
  124. end
  125. end
  126. end
  127. context 'with organization popover' do
  128. let(:organizations) do
  129. organization = create(:organization, vip: true)
  130. [organization]
  131. end
  132. it 'shows the organization popover' do
  133. visit "#user/profile/#{customer.id}"
  134. page.find('.profile-organization .organization-popover').hover
  135. within '.popover' do
  136. expect(page).to have_text(organizations[0].name, wait: 30)
  137. within '.avatar--organization' do
  138. expect(page).to have_css('.icon-crown-silver')
  139. end
  140. end
  141. end
  142. end
  143. end