123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe 'Profile > Language', type: :system do
- let(:group) { create(:group) }
- let(:session_user) { create(:admin, preferences: { locale: locale }, groups: Group.all) }
- let(:path) { 'profile/language' }
- shared_examples 'having translated content in' do |current_element|
- it "the '#{current_element}' element" do
- within current_element do
- expect(page).to have_text(translated_content)
- end
- end
- end
- shared_examples 'having translated content in the page title' do
- it 'shows the translated content' do
- expect(page).to have_title(translated_content)
- end
- end
- shared_examples 'displaying the current language' do
- it 'shows the current language' do
- within :active_content do
- within '.page-content' do
- expect(page).to have_field(with: full_current_locale)
- end
- end
- end
- end
- shared_examples 'have translations in ticket page' do |translated_element|
- it_behaves_like 'having translated content in the page title'
- context 'when translated content is ticket priority' do
- let(:translated_content) { priority }
- it_behaves_like 'having translated content in', translated_element
- end
- context 'when translated content is ticket owner' do
- let(:translated_content) { owner }
- it_behaves_like 'having translated content in', translated_element
- end
- context 'when translated content is ticket title' do
- let(:translated_content) { title }
- it_behaves_like 'having translated content in', :active_content
- end
- end
- context 'when user locale is English (en-gb)', authenticated_as: :session_user do
- let(:locale) { 'en-gb' }
- let(:translated_content) { 'Overview' }
- let(:full_current_locale) { 'English (Great Britain)' }
- let(:priority) { 'PRIORITY' }
- let(:owner) { 'OWNER' }
- before do
- visit path
- # Suppress the modal dialog that invites to contributions for translations that are < 90% as this breaks the tests for de-de.
- page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))"
- end
- it_behaves_like 'displaying the current language'
- it_behaves_like 'having translated content in', '.js-menu'
- context 'when profile language is changed' do
- let(:new_locale) { 'de-de' }
- let(:full_current_locale) { 'Deutsch' }
- before do
- within :active_content do
- within '.page-content' do
- find('input.searchableSelect-main.js-input').click
- find("[data-value=#{new_locale}].js-option").click
- click_on 'Submit'
- session_user.reload
- end
- end
- end
- it 'changes the user preference language' do
- expect(session_user.preferences[:locale]).to eq(new_locale)
- end
- it_behaves_like 'displaying the current language'
- end
- context 'with language page visited' do
- let(:translated_content) { 'Language' }
- it_behaves_like 'having translated content in', '.page-header'
- it_behaves_like 'having translated content in', '.sidebar.NavBarProfile'
- end
- context 'with dashboard page visited' do
- let(:path) { 'dashboard' }
- let(:translated_content) { 'My Stats' }
- it_behaves_like 'having translated content in', :active_content
- end
- context 'with overview page visited' do
- let(:path) { 'ticket/view' }
- let(:translated_content) { 'My Assigned Tickets' }
- it_behaves_like 'having translated content in the page title'
- it_behaves_like 'having translated content in', :active_content
- end
- context 'with drafted ticket create' do
- let(:path) { 'ticket/create' }
- let(:title) { 'preferences lang check #1' }
- let(:customer) { 'nicole' }
- let(:translated_content) { "Inbound Call: #{title}" }
- translated_element = '.newTicket .ticket-create'
- before do
- fill_in 'title', with: title
- fill_in 'customer_id_completion', with: customer
- send_keys(:enter, :tab)
- find('[data-name="body"]').set(title)
- group = Group.find_by(name: 'Users')
- set_tree_select_value('group_id', group.name)
- end
- include_examples 'have translations in ticket page', translated_element
- end
- context 'with ticket zoom page' do
- let(:path) { "ticket/zoom/#{ticket.id}" }
- let(:title) { 'preferences lang check #2' }
- let(:translated_content) { title }
- let(:user_group) { Group.lookup(name: 'Users') }
- let(:ticket) { create(:ticket, group: user_group, title: title) }
- translated_element = '.content.active .sidebar-content'
- include_examples 'have translations in ticket page', translated_element
- end
- end
- context 'when user locale is Deutsch', authenticated_as: :session_user do
- let(:locale) { 'de-de' }
- let(:translated_content) { 'Übersichten' }
- let(:full_current_locale) { 'Deutsch' }
- let(:priority) { 'PRIORITÄT' }
- let(:owner) { 'BESITZER' }
- before do
- visit path
- # Suppress the modal dialog that invites to contributions for translations that are < 90% as this breaks the tests for de-de.
- page.evaluate_script "App.LocalStorage.set('translation_support_no', true, App.Session.get('id'))"
- end
- it_behaves_like 'displaying the current language'
- it_behaves_like 'having translated content in', '.js-menu'
- context 'when profile language is changed' do
- let(:new_locale) { 'en-gb' }
- let(:full_current_locale) { 'English (Great Britain)' }
- let(:translated_content) { 'Übersichten' }
- before do
- within :active_content do
- within '.page-content' do
- find('input.searchableSelect-main.js-input').click
- find("[data-value=#{new_locale}].js-option").click
- click_on 'Übermitteln'
- session_user.reload
- end
- end
- end
- it 'changes the user preference language' do
- expect(session_user.preferences[:locale]).to eq(new_locale)
- end
- it_behaves_like 'displaying the current language'
- end
- context 'with language page visited' do
- let(:translated_content) { 'Sprache' }
- it_behaves_like 'having translated content in', '.page-header'
- it_behaves_like 'having translated content in', '.sidebar.NavBarProfile'
- end
- context 'with dashboard page visited' do
- let(:path) { 'dashboard' }
- let(:translated_content) { 'Meine Statistik' }
- it_behaves_like 'having translated content in', :active_content
- end
- context 'with overview page visited' do
- let(:path) { 'ticket/view' }
- let(:translated_content) { Translation.translate('de-de', 'My Assigned Tickets') }
- it_behaves_like 'having translated content in the page title'
- it_behaves_like 'having translated content in', :active_content
- end
- context 'with drafted ticket create' do
- let(:path) { 'ticket/create' }
- let(:title) { 'preferences lang check #1' }
- let(:customer) { 'nicole' }
- let(:translated_content) { "Eingehender Anruf: #{title}" }
- translated_element = '.newTicket .ticket-create'
- before do
- fill_in 'title', with: title
- fill_in 'customer_id_completion', with: customer
- send_keys(:enter, :tab)
- find('[data-name="body"]').set(title)
- set_tree_select_value('group_id', Group.first.name)
- end
- include_examples 'have translations in ticket page', translated_element
- end
- context 'with ticket zoom page' do
- let(:path) { "ticket/zoom/#{ticket.id}" }
- let(:title) { 'preferences lang check #2' }
- let(:translated_content) { title }
- let(:user_group) { Group.lookup(name: 'Users') }
- let(:ticket) { create(:ticket, group: user_group, title: title) }
- translated_element = '.content.active .sidebar-content'
- include_examples 'have translations in ticket page', translated_element
- end
- end
- end
|