app_links_spec.rb 4.0 KB

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