account_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Desktop > Account', app: :desktop_view, authenticated_as: :agent, type: :system do
  4. let(:agent) { create(:agent) }
  5. before do
  6. visit '/'
  7. find("[aria-label=\"Avatar (#{agent.fullname})\"]").click
  8. end
  9. describe 'appearance selection' do
  10. it 'user can switch appearance' do
  11. # Switch starts on 'auto'
  12. default_theme = page.execute_script("return matchMedia('(prefers-color-scheme: dark)').matches") ? 'dark' : 'light'
  13. expect(page).to have_css("html[data-theme=#{default_theme}]")
  14. # Switch to 'dark'
  15. click_on 'Appearance'
  16. wait_for_mutation('userCurrentAppearance')
  17. expect(page).to have_css('html[data-theme=dark]')
  18. # Switch to 'light'
  19. click_on 'Appearance'
  20. wait_for_mutation('userCurrentAppearance', number: 2)
  21. expect(page).to have_css('html[data-theme=light]')
  22. end
  23. end
  24. describe 'language selection' do
  25. it 'user can change language' do
  26. click_on 'Profile settings'
  27. click_on 'Language'
  28. find('label', text: 'Your language').click
  29. find('span', text: 'Deutsch').click
  30. expect(page).to have_text('Sprache')
  31. end
  32. end
  33. describe 'password change' do
  34. let(:agent) { create(:agent, password: 'test') }
  35. it 'user can change password' do
  36. click_on 'Profile settings'
  37. click_on 'Password'
  38. fill_in 'Current password', with: 'test'
  39. fill_in 'New password', with: 'testTEST1234'
  40. fill_in 'Confirm new password', with: 'testTEST1234'
  41. click_on 'Change Password'
  42. expect(page).to have_text('Password changed successfully')
  43. end
  44. end
  45. describe 'avatar handling', authenticated_as: :agent do
  46. let(:agent) { create(:agent, firstname: 'Jane', lastname: 'Doe') }
  47. it 'user can upload avatar' do
  48. click_on 'Profile settings'
  49. click_on 'Avatar'
  50. expect(page).to have_text('JD')
  51. find('input[data-test-id="fileUploadInput"]', visible: :all).set(Rails.root.join('test/data/image/1000x1000.png'))
  52. expect(page).to have_text('Avatar Preview')
  53. click_on 'Save'
  54. expect(page).to have_text('Your avatar has been uploaded')
  55. avatar_element_style = find("#user-menu span[aria-label=\"Avatar (#{agent.fullname})\"]").style('background-image')
  56. expect(avatar_element_style['background-image']).to include("/api/v1/users/image/#{Avatar.last.store_hash}")
  57. end
  58. end
  59. end