preferences_language_spec.rb 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Profile > Language', type: :system do
  4. let(:group) { create(:group) }
  5. let(:session_user) { create(:admin, preferences: { locale: locale }, groups: Group.all) }
  6. let(:path) { 'profile/language' }
  7. shared_examples 'having translated content in' do |current_element|
  8. it "the '#{current_element}' element" do
  9. within current_element do
  10. expect(page).to have_text(translated_content)
  11. end
  12. end
  13. end
  14. shared_examples 'having translated content in the page title' do
  15. it 'shows the translated content' do
  16. expect(page).to have_title(translated_content)
  17. end
  18. end
  19. shared_examples 'displaying the current language' do
  20. it 'shows the current language' do
  21. within :active_content do
  22. within '.page-content' do
  23. expect(page).to have_field(with: full_current_locale)
  24. end
  25. end
  26. end
  27. end
  28. shared_examples 'have translations in ticket page' do |translated_element|
  29. it_behaves_like 'having translated content in the page title'
  30. context 'when translated content is ticket priority' do
  31. let(:translated_content) { priority }
  32. it_behaves_like 'having translated content in', translated_element
  33. end
  34. context 'when translated content is ticket owner' do
  35. let(:translated_content) { owner }
  36. it_behaves_like 'having translated content in', translated_element
  37. end
  38. context 'when translated content is ticket title' do
  39. let(:translated_content) { title }
  40. it_behaves_like 'having translated content in', :active_content
  41. end
  42. end
  43. context 'when user locale is English (en-gb)', authenticated_as: :session_user do
  44. let(:locale) { 'en-gb' }
  45. let(:translated_content) { 'Overview' }
  46. let(:full_current_locale) { 'English (Great Britain)' }
  47. let(:priority) { 'PRIORITY' }
  48. let(:owner) { 'OWNER' }
  49. before do
  50. visit path
  51. # Suppress the modal dialog that invites to contributions for translations that are < 90% as this breaks the tests for de-de.
  52. page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))"
  53. end
  54. it_behaves_like 'displaying the current language'
  55. it_behaves_like 'having translated content in', '.js-menu'
  56. context 'when profile language is changed' do
  57. let(:new_locale) { 'de-de' }
  58. let(:full_current_locale) { 'Deutsch' }
  59. before do
  60. within :active_content do
  61. within '.page-content' do
  62. find('input.searchableSelect-main.js-input').click
  63. find("[data-value=#{new_locale}].js-option").click
  64. click_on 'Submit'
  65. session_user.reload
  66. end
  67. end
  68. end
  69. it 'changes the user preference language' do
  70. expect(session_user.preferences[:locale]).to eq(new_locale)
  71. end
  72. it_behaves_like 'displaying the current language'
  73. end
  74. context 'with language page visited' do
  75. let(:translated_content) { 'Language' }
  76. it_behaves_like 'having translated content in', '.page-header'
  77. it_behaves_like 'having translated content in', '.sidebar.NavBarProfile'
  78. end
  79. context 'with dashboard page visited' do
  80. let(:path) { 'dashboard' }
  81. let(:translated_content) { 'My Stats' }
  82. it_behaves_like 'having translated content in', :active_content
  83. end
  84. context 'with overview page visited' do
  85. let(:path) { 'ticket/view' }
  86. let(:translated_content) { 'My Assigned Tickets' }
  87. it_behaves_like 'having translated content in the page title'
  88. it_behaves_like 'having translated content in', :active_content
  89. end
  90. context 'with drafted ticket create' do
  91. let(:path) { 'ticket/create' }
  92. let(:title) { 'preferences lang check #1' }
  93. let(:customer) { 'nicole' }
  94. let(:translated_content) { "Inbound Call: #{title}" }
  95. translated_element = '.newTicket .ticket-create'
  96. before do
  97. fill_in 'title', with: title
  98. fill_in 'customer_id_completion', with: customer
  99. send_keys(:enter, :tab)
  100. find('[data-name="body"]').set(title)
  101. group = Group.find_by(name: 'Users')
  102. set_tree_select_value('group_id', group.name)
  103. end
  104. include_examples 'have translations in ticket page', translated_element
  105. end
  106. context 'with ticket zoom page' do
  107. let(:path) { "ticket/zoom/#{ticket.id}" }
  108. let(:title) { 'preferences lang check #2' }
  109. let(:translated_content) { title }
  110. let(:user_group) { Group.lookup(name: 'Users') }
  111. let(:ticket) { create(:ticket, group: user_group, title: title) }
  112. translated_element = '.content.active .sidebar-content'
  113. include_examples 'have translations in ticket page', translated_element
  114. end
  115. end
  116. context 'when user locale is Deutsch', authenticated_as: :session_user do
  117. let(:locale) { 'de-de' }
  118. let(:translated_content) { 'Übersichten' }
  119. let(:full_current_locale) { 'Deutsch' }
  120. let(:priority) { 'PRIORITÄT' }
  121. let(:owner) { 'BESITZER' }
  122. before do
  123. visit path
  124. # Suppress the modal dialog that invites to contributions for translations that are < 90% as this breaks the tests for de-de.
  125. page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))"
  126. end
  127. it_behaves_like 'displaying the current language'
  128. it_behaves_like 'having translated content in', '.js-menu'
  129. context 'when profile language is changed' do
  130. let(:new_locale) { 'en-gb' }
  131. let(:full_current_locale) { 'English (Great Britain)' }
  132. let(:translated_content) { 'Übersichten' }
  133. before do
  134. within :active_content do
  135. within '.page-content' do
  136. find('input.searchableSelect-main.js-input').click
  137. find("[data-value=#{new_locale}].js-option").click
  138. click_on 'Übermitteln'
  139. session_user.reload
  140. end
  141. end
  142. end
  143. it 'changes the user preference language' do
  144. expect(session_user.preferences[:locale]).to eq(new_locale)
  145. end
  146. it_behaves_like 'displaying the current language'
  147. end
  148. context 'with language page visited' do
  149. let(:translated_content) { 'Sprache' }
  150. it_behaves_like 'having translated content in', '.page-header'
  151. it_behaves_like 'having translated content in', '.sidebar.NavBarProfile'
  152. end
  153. context 'with dashboard page visited' do
  154. let(:path) { 'dashboard' }
  155. let(:translated_content) { 'Meine Statistik' }
  156. it_behaves_like 'having translated content in', :active_content
  157. end
  158. context 'with overview page visited' do
  159. let(:path) { 'ticket/view' }
  160. let(:translated_content) { Translation.translate('de-de', 'My Assigned Tickets') }
  161. it_behaves_like 'having translated content in the page title'
  162. it_behaves_like 'having translated content in', :active_content
  163. end
  164. context 'with drafted ticket create' do
  165. let(:path) { 'ticket/create' }
  166. let(:title) { 'preferences lang check #1' }
  167. let(:customer) { 'nicole' }
  168. let(:translated_content) { "Eingehender Anruf: #{title}" }
  169. translated_element = '.newTicket .ticket-create'
  170. before do
  171. fill_in 'title', with: title
  172. fill_in 'customer_id_completion', with: customer
  173. send_keys(:enter, :tab)
  174. find('[data-name="body"]').set(title)
  175. set_tree_select_value('group_id', Group.first.name)
  176. end
  177. include_examples 'have translations in ticket page', translated_element
  178. end
  179. context 'with ticket zoom page' do
  180. let(:path) { "ticket/zoom/#{ticket.id}" }
  181. let(:title) { 'preferences lang check #2' }
  182. let(:translated_content) { title }
  183. let(:user_group) { Group.lookup(name: 'Users') }
  184. let(:ticket) { create(:ticket, group: user_group, title: title) }
  185. translated_element = '.content.active .sidebar-content'
  186. include_examples 'have translations in ticket page', translated_element
  187. end
  188. end
  189. end