app_links_spec.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > App links', app: :mobile, type: :system do
  4. def disable_auto_redirect
  5. # Force desktop view in order to circumvent the automatic redirection to mobile.
  6. page.evaluate_script "window.localStorage.setItem('forceDesktopApp', true)"
  7. end
  8. context 'with "Continue to desktop" link' do
  9. shared_examples 'redirecting to desktop app' do |source, target|
  10. it 'redirects to desktop app and remembers the choice' do
  11. visit source, skip_waiting: source == 'login'
  12. click 'a', text: 'Continue to desktop'
  13. expect_current_route(target, app: :desktop)
  14. visit source, skip_waiting: true
  15. expect_current_route(target, app: :desktop)
  16. end
  17. end
  18. context 'when user is unauthenticated', authenticated_as: false do
  19. it_behaves_like 'redirecting to desktop app', 'login', 'login'
  20. end
  21. context 'when user is authenticated' do
  22. it_behaves_like 'redirecting to desktop app', 'account', 'dashboard'
  23. end
  24. end
  25. context 'with "Continue to mobile" link' do
  26. shared_examples 'hiding the mobile app link' do |source, authenticated: false|
  27. it 'hides the mobile app link' do
  28. visit source, app: :desktop
  29. if authenticated
  30. find('a[href="#current_user"]').click
  31. end
  32. expect(page).to have_no_css('a', text: 'Continue to mobile')
  33. end
  34. end
  35. shared_examples 'redirecting to mobile app' do |source, target|
  36. it 'redirects to mobile app' do
  37. visit source, app: :desktop
  38. find('a[href="#current_user"]').click
  39. click 'a', text: 'Continue to mobile'
  40. expect(page).to have_no_text('Loading failed')
  41. expect_current_route(target, app: :mobile)
  42. end
  43. end
  44. context 'with desktop user agent' do
  45. context 'when user is unauthenticated', authenticated_as: false do
  46. it_behaves_like 'hiding the mobile app link', 'login'
  47. end
  48. context 'when user is authenticated' do
  49. it_behaves_like 'hiding the mobile app link', 'dashboard'
  50. end
  51. end
  52. context 'with mobile user agent', mobile_user_agent: true do
  53. context 'when user is unauthenticated', authenticated_as: false do
  54. it 'redirects to mobile' do
  55. visit '/'
  56. disable_auto_redirect
  57. click_on('Continue to desktop')
  58. expect_current_route('login', app: :desktop)
  59. click_on('Continue to mobile')
  60. expect(page).to have_no_text('Loading failed')
  61. expect_current_route('login', app: :mobile)
  62. end
  63. end
  64. context 'when user is authenticated' do
  65. before do
  66. visit '/'
  67. disable_auto_redirect
  68. end
  69. it_behaves_like 'redirecting to mobile app', 'profile', 'profile'
  70. it_behaves_like 'redirecting to mobile app', 'profile/avatar', 'profile/avatar'
  71. it_behaves_like 'redirecting to mobile app', 'organization/profile/1', 'organization/profile/1'
  72. it_behaves_like 'redirecting to mobile app', 'search/string', 'search/ticket?search=string'
  73. it_behaves_like 'redirecting to mobile app', 'ticket/create', 'ticket/create'
  74. it_behaves_like 'redirecting to mobile app', 'ticket/zoom/1', 'ticket/zoom/1'
  75. it_behaves_like 'redirecting to mobile app', 'user/profile/1', 'user/profile/1'
  76. it_behaves_like 'redirecting to mobile app', 'dashboard', %r{mobile/$}
  77. context 'with customer user', authenticated_as: :customer do
  78. let(:customer) { create(:customer) }
  79. it_behaves_like 'redirecting to mobile app', 'ticket/view/my_tickets', 'ticket/view/my_tickets'
  80. end
  81. end
  82. end
  83. end
  84. context 'with mobile device detection', mobile_user_agent: true do
  85. shared_examples 'automatically redirecting to mobile app' do |source, target|
  86. it 'automatically redirects to mobile app' do
  87. visit source, app: :desktop
  88. expect_current_route(target, app: :mobile)
  89. end
  90. end
  91. it_behaves_like 'automatically redirecting to mobile app', '/', %r{mobile/$}
  92. it_behaves_like 'automatically redirecting to mobile app', 'ticket/zoom/1', 'ticket/zoom/1'
  93. context 'when not authenticated', authenticated_as: false do
  94. it 'forgot password doesn\'t redirect back' do
  95. visit '/login', app: :mobile
  96. click_on 'Forgot password?'
  97. expect_current_route('password_reset', app: :desktop)
  98. expect(page).to have_no_link('Continue to desktop')
  99. end
  100. it "register doesn't redirect back" do
  101. visit '/login', app: :mobile
  102. click_on 'Register'
  103. expect_current_route('signup', app: :desktop)
  104. expect(page).to have_no_link('Continue to desktop')
  105. end
  106. end
  107. end
  108. end