translations_spec.rb 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'System > Translations', type: :system do
  4. before do
  5. visit '#system/translation'
  6. end
  7. context 'with description content' do
  8. context 'without any customized translations' do
  9. it 'shows description content on the page' do
  10. within :active_content do
  11. expect(page).to have_text('Contributing Translations')
  12. .and have_text('On-screen Translation')
  13. end
  14. end
  15. end
  16. context 'when there are customized translations present', authenticated_as: :authenticate do
  17. let(:translation) { create(:translation) }
  18. def authenticate
  19. translation
  20. true
  21. end
  22. it 'provides description button' do
  23. click_on 'Description'
  24. in_modal do
  25. expect(page).to have_text('Contributing Translations')
  26. .and have_text('On-screen Translation')
  27. end
  28. end
  29. end
  30. end
  31. context 'with overview table', authenticated_as: :authenticate do
  32. let(:translations) { create_list(:translation, 10) }
  33. def authenticate
  34. translations
  35. true
  36. end
  37. it 'shows all customized translations in the table' do
  38. within :active_content do
  39. expect(page).to have_text('TRANSLATION SOURCE')
  40. .and have_text('ORIGINAL TRANSLATION')
  41. .and have_text('CUSTOM TRANSLATION')
  42. .and have_text('TARGET LANGUAGE')
  43. .and have_text('ACTION')
  44. expect(find_all('tbody tr').length).to eq(10)
  45. translations.each do |translation|
  46. expect(page).to have_text(translation.source)
  47. .and have_text(translation.target_initial)
  48. .and have_text(translation.target)
  49. .and have_text(Locale.find_by(locale: translation.locale).name)
  50. end
  51. end
  52. end
  53. it 'provides remove action' do
  54. within :active_content do
  55. row = find("tr[data-id='#{translations[9].id}']")
  56. row.find('.js-action').click
  57. expect(row).to have_no_css('.js-reset')
  58. row.find('.js-remove').click
  59. end
  60. in_modal do
  61. click_on 'Yes'
  62. end
  63. within :active_content do
  64. expect(page).to have_no_text(translations[9].source)
  65. end
  66. end
  67. context 'with customized translation from codebase' do
  68. let(:translation) { Translation.last }
  69. def authenticate
  70. translation.update!(target: 'foobar')
  71. true
  72. end
  73. it 'provides reset action' do
  74. within :active_content do
  75. row = find("tr[data-id='#{translation.id}']")
  76. row.find('.js-action').click
  77. expect(row).to have_no_css('.js-remove')
  78. row.find('.js-reset').click
  79. end
  80. in_modal do
  81. click_on 'Yes'
  82. end
  83. within :active_content do
  84. expect(page).to have_no_text('foobar')
  85. expect(page).to have_text('Contributing Translations')
  86. .and have_text('On-screen Translation')
  87. end
  88. end
  89. end
  90. end
  91. context 'with translation management' do
  92. context 'with new customized translations' do
  93. before do
  94. click_on 'New Translation'
  95. end
  96. it 'adds new custom translation' do
  97. in_modal do
  98. set_textarea_field_value('source', 'foo')
  99. set_textarea_field_value('target', 'bar')
  100. click_on 'Submit'
  101. end
  102. within :active_content do
  103. expect(page).to have_text('foo')
  104. .and have_text('bar')
  105. .and have_text('English (United States)')
  106. end
  107. end
  108. it 'provides translation suggestions' do
  109. in_modal do
  110. expect(page).to have_text('TRANSLATION SOURCE')
  111. .and have_text('ORIGINAL TRANSLATION')
  112. .and have_text('TYPE')
  113. row = find_all('tbody tr')[0]
  114. source_text = row.find_all('td')[1].text
  115. target_text = row.find_all('td')[2].text
  116. row.find_all('td')[0].click
  117. check_textarea_field_value('source', source_text)
  118. find_field('target', placeholder: target_text)
  119. expect(page).to have_text('Did you know that system translations can be contributed and shared with the community on our public platform 🔗? It sports a very convenient user interface based on Weblate, give it a try!')
  120. end
  121. end
  122. it 'supports filtering translation suggestions' do
  123. in_modal do
  124. fill_in 'Search…', with: Translation.last.source
  125. expect(find('table')).to have_text(Translation.last.source)
  126. end
  127. end
  128. it 'refreshes list of suggestions when locale is changed' do
  129. in_modal do
  130. english_translation = Translation.find_by(locale: 'en-us')
  131. fill_in 'Search…', with: english_translation.source
  132. expect(find('table')).to have_text(english_translation.target_initial)
  133. set_tree_select_value('locale', 'Deutsch')
  134. german_translation = Translation.find_by(locale: 'de-de', source: english_translation.source)
  135. expect(find('table')).to have_no_text(english_translation.target_initial)
  136. expect(find('table')).to have_text(german_translation.target_initial)
  137. end
  138. end
  139. end
  140. context 'with existing customized translations', authenticated_as: :authenticate do
  141. let(:translation) { create(:translation) }
  142. def authenticate
  143. translation
  144. true
  145. end
  146. it 'allows selective editing' do
  147. within :active_content do
  148. row = find("tr[data-id='#{translation.id}']")
  149. row.find_all('td')[0].click
  150. end
  151. in_modal do
  152. find_field('source', disabled: true)
  153. set_textarea_field_value('target', 'foobar')
  154. find_field('locale', disabled: true, visible: :all)
  155. expect(page).to have_no_table
  156. click_on 'Submit'
  157. end
  158. within :active_content do
  159. expect(page).to have_text('foobar')
  160. end
  161. end
  162. end
  163. end
  164. end