blacklight-spotlight 1.5.1 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -3
  3. data/app/assets/javascripts/spotlight/translation_progress.js +23 -0
  4. data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
  5. data/app/assets/stylesheets/spotlight/_translations.scss +47 -0
  6. data/app/assets/stylesheets/spotlight/_utilities.scss +3 -0
  7. data/app/assets/stylesheets/spotlight/_variables.scss +5 -0
  8. data/app/controllers/concerns/spotlight/controller.rb +12 -1
  9. data/app/controllers/spotlight/about_pages_controller.rb +6 -0
  10. data/app/controllers/spotlight/browse_controller.rb +1 -1
  11. data/app/controllers/spotlight/catalog_controller.rb +6 -1
  12. data/app/controllers/spotlight/exhibits_controller.rb +10 -2
  13. data/app/controllers/spotlight/feature_pages_controller.rb +6 -0
  14. data/app/controllers/spotlight/filters_controller.rb +2 -2
  15. data/app/controllers/spotlight/home_pages_controller.rb +10 -0
  16. data/app/controllers/spotlight/languages_controller.rb +46 -0
  17. data/app/controllers/spotlight/pages_controller.rb +57 -3
  18. data/app/controllers/spotlight/solr_controller.rb +3 -3
  19. data/app/controllers/spotlight/translations_controller.rb +34 -0
  20. data/app/helpers/spotlight/application_helper.rb +1 -0
  21. data/app/helpers/spotlight/languages_helper.rb +33 -0
  22. data/app/helpers/spotlight/translations_helper.rb +13 -0
  23. data/app/models/concerns/spotlight/custom_translation_extension.rb +4 -0
  24. data/app/models/concerns/spotlight/translatables.rb +30 -0
  25. data/app/models/spotlight/ability.rb +5 -2
  26. data/app/models/spotlight/about_page.rb +1 -1
  27. data/app/models/spotlight/exhibit.rb +14 -6
  28. data/app/models/spotlight/feature_page.rb +1 -2
  29. data/app/models/spotlight/home_page.rb +1 -3
  30. data/app/models/spotlight/language.rb +24 -0
  31. data/app/models/spotlight/main_navigation.rb +12 -0
  32. data/app/models/spotlight/page.rb +53 -1
  33. data/app/models/spotlight/resources/upload.rb +6 -1
  34. data/app/models/spotlight/search.rb +4 -0
  35. data/app/services/spotlight/clone_translated_page_from_locale.rb +32 -0
  36. data/app/views/_user_util_links.html.erb +1 -0
  37. data/app/views/devise/mailer/invitation_instructions.html.erb +2 -2
  38. data/app/views/layouts/spotlight/spotlight.html.erb +2 -2
  39. data/app/views/shared/_curated_features_navbar.html.erb +2 -2
  40. data/app/views/spotlight/about_pages/_sidebar.html.erb +1 -1
  41. data/app/views/spotlight/admin_users/index.html.erb +1 -1
  42. data/app/views/spotlight/catalog/_edit_default.html.erb +1 -1
  43. data/app/views/spotlight/exhibits/_export.html.erb +1 -1
  44. data/app/views/spotlight/exhibits/_form.html.erb +1 -1
  45. data/app/views/spotlight/exhibits/_import.html.erb +2 -1
  46. data/app/views/spotlight/exhibits/_languages.html.erb +56 -0
  47. data/app/views/spotlight/exhibits/edit.html.erb +11 -5
  48. data/app/views/spotlight/feature_pages/_sidebar.html.erb +1 -1
  49. data/app/views/spotlight/filters/_form.html.erb +2 -1
  50. data/app/views/spotlight/resources/upload/_form.html.erb +1 -1
  51. data/app/views/spotlight/shared/_curation_sidebar.html.erb +5 -0
  52. data/app/views/spotlight/shared/_locale_picker.html.erb +14 -0
  53. data/app/views/spotlight/translations/_browse_categories.html.erb +67 -0
  54. data/app/views/spotlight/translations/_general.html.erb +176 -0
  55. data/app/views/spotlight/translations/_metadata.html.erb +67 -0
  56. data/app/views/spotlight/translations/_page.html.erb +45 -0
  57. data/app/views/spotlight/translations/_pages.html.erb +37 -0
  58. data/app/views/spotlight/translations/_pages_table.html.erb +15 -0
  59. data/app/views/spotlight/translations/_search_fields.html.erb +97 -0
  60. data/app/views/spotlight/translations/edit.html.erb +55 -0
  61. data/config/i18n-tasks.yml +81 -0
  62. data/config/locales/devise.en.yml +2 -1
  63. data/config/locales/spotlight.en.yml +657 -614
  64. data/config/routes.rb +19 -1
  65. data/db/migrate/20180308203409_create_spotlight_languages.rb +12 -0
  66. data/db/migrate/20180403130857_translation_uniqueness.rb +5 -0
  67. data/db/migrate/20180405044000_add_locale_to_pages.rb +6 -0
  68. data/db/migrate/20180406212516_add_default_locale_reference_to_spotlight_pages.rb +7 -0
  69. data/lib/generators/spotlight/templates/catalog_controller.rb +2 -2
  70. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +14 -4
  71. data/lib/generators/spotlight/templates/config/initializers/translation.rb +4 -2
  72. data/lib/migration/page_language.rb +27 -0
  73. data/lib/spotlight/engine.rb +32 -4
  74. data/lib/spotlight/upload_field_config.rb +27 -0
  75. data/lib/spotlight/version.rb +1 -1
  76. data/lib/tasks/spotlight_tasks.rake +6 -0
  77. data/spec/controllers/spotlight/about_pages_controller_spec.rb +67 -1
  78. data/spec/controllers/spotlight/feature_pages_controller_spec.rb +50 -0
  79. data/spec/controllers/spotlight/filters_controller_spec.rb +4 -4
  80. data/spec/controllers/spotlight/home_pages_controller_spec.rb +25 -0
  81. data/spec/controllers/spotlight/languages_controller_spec.rb +66 -0
  82. data/spec/controllers/spotlight/pages_controller_spec.rb +45 -0
  83. data/spec/controllers/spotlight/solr_controller_spec.rb +1 -1
  84. data/spec/controllers/spotlight/translations_controller_spec.rb +67 -0
  85. data/spec/examples.txt +1171 -1281
  86. data/spec/factories/exhibits.rb +1 -1
  87. data/spec/factories/language.rb +6 -0
  88. data/spec/factories/main_navigation.rb +7 -0
  89. data/spec/factories/searches.rb +1 -0
  90. data/spec/factories/tags.rb +1 -0
  91. data/spec/features/exhibits/language_create_edit_spec.rb +53 -0
  92. data/spec/features/exhibits/translation_editing_spec.rb +397 -0
  93. data/spec/features/javascript/locale_selector_spec.rb +61 -0
  94. data/spec/helpers/spotlight/languages_helper_spec.rb +73 -0
  95. data/spec/helpers/spotlight/translations_helper_spec.rb +16 -0
  96. data/spec/i18n_spec.rb +29 -0
  97. data/spec/lib/migration/page_language_spec.rb +21 -0
  98. data/spec/lib/spotlight/upload_field_config_spec.rb +24 -0
  99. data/spec/models/spotlight/ability_spec.rb +17 -4
  100. data/spec/models/spotlight/exhibit_spec.rb +49 -0
  101. data/spec/models/spotlight/language_spec.rb +41 -0
  102. data/spec/models/spotlight/page_spec.rb +109 -0
  103. data/spec/models/translation_spec.rb +11 -0
  104. data/spec/services/spotlight/clone_translated_page_from_locale_spec.rb +29 -0
  105. data/spec/spec_helper.rb +1 -13
  106. data/spec/support/disable_friendly_id_deprecation_warnings.rb +7 -6
  107. data/spec/test_app_templates/Gemfile.extra +3 -0
  108. data/spec/test_app_templates/catalog_controller.rb +31 -31
  109. data/spec/test_app_templates/lib/generators/test_app_generator.rb +9 -6
  110. data/spec/views/spotlight/contacts/edit.html.erb_spec.rb +13 -0
  111. data/spec/views/spotlight/exhibits/_form.html.erb_spec.rb +33 -0
  112. data/spec/views/spotlight/exhibits/edit.html.erb_spec.rb +4 -1
  113. data/spec/views/spotlight/resources/_external_resources_form.html.erb_spec.rb +13 -0
  114. data/spec/views/spotlight/resources/new.html.erb_spec.rb +10 -4
  115. data/spec/views/spotlight/translations/_page.html.erb_spec.rb +75 -0
  116. metadata +88 -28
  117. data/app/assets/javascripts/spotlight/sir-trevor.js +0 -0
  118. data/app/views/shared/_share_follow.html.erb +0 -5
  119. data/config/locales/social_share_button.en.yml +0 -18
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
  factory :exhibit, class: Spotlight::Exhibit do
3
3
  sequence(:title) { |n| "Exhibit Title #{n}" }
4
4
  published true
5
- after(:build) { |exhibit| exhibit.searches << FactoryBot.build(:default_search) }
5
+ after(:build) { |exhibit| exhibit.searches << FactoryBot.build(:default_search, exhibit: exhibit) }
6
6
 
7
7
  trait :with_thumbnail do
8
8
  association :thumbnail, factory: :exhibit_thumbnail
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :language, class: Spotlight::Language do
3
+ exhibit
4
+ locale 'es'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :main_navigation, class: Spotlight::MainNavigation do
3
+ exhibit
4
+ nav_type 'browse'
5
+ display true
6
+ end
7
+ end
@@ -12,6 +12,7 @@ FactoryBot.define do
12
12
  end
13
13
 
14
14
  factory :default_search, class: Spotlight::Search do
15
+ exhibit
15
16
  title 'All Exhibit Items'
16
17
  long_description 'All items in this exhibit.'
17
18
 
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  factory :tagging, class: ActsAsTaggableOn::Tagging do
7
7
  sequence(:tag) { |n| FactoryBot.create(:tag, name: "tagging#{n}") }
8
8
  tagger { FactoryBot.create(:exhibit) }
9
+ taggable { FactoryBot.create(:exhibit) }
9
10
  context :tags
10
11
  end
11
12
  end
@@ -0,0 +1,53 @@
1
+ describe 'Language', type: :feature do
2
+ let(:exhibit) { FactoryBot.create(:exhibit) }
3
+ let(:admin) { FactoryBot.create(:exhibit_admin, exhibit: exhibit) }
4
+ before do
5
+ login_as admin
6
+ visit spotlight.edit_exhibit_path(exhibit)
7
+ end
8
+ describe 'creation' do
9
+ it 'successfully adds languages' do
10
+ within '#language' do
11
+ select 'Albanian'
12
+ click_button 'Add language'
13
+ end
14
+ expect(page).to have_css '.flash_messages', text: 'The language was created.'
15
+ within '#language' do
16
+ expect(page).to have_css 'table'
17
+ expect(page).to have_css 'td', text: 'Albanian'
18
+ end
19
+ end
20
+ end
21
+ describe 'making public' do
22
+ it 'successfully updates the language' do
23
+ within '#language' do
24
+ select 'Albanian'
25
+ click_button 'Add language'
26
+ end
27
+ expect(page).to have_css '.flash_messages', text: 'The language was created.'
28
+ within '#language' do
29
+ check 'Public'
30
+ click_button 'Save changes'
31
+ end
32
+ expect(page).to have_css '.flash_messages', text: 'The exhibit was successfully updated.'
33
+ expect(exhibit.languages.last).to be_public
34
+ end
35
+ end
36
+ describe 'deleting' do
37
+ it 'successfully updates the language' do
38
+ within '#language' do
39
+ select 'Albanian'
40
+ click_button 'Add language'
41
+ end
42
+ expect(page).to have_css '.flash_messages', text: 'The language was created.'
43
+ within '#language' do
44
+ click_link 'Remove'
45
+ end
46
+ expect(page).to have_css '.flash_messages', text: 'The language was deleted.'
47
+ within '#language' do
48
+ expect(page).to have_content 'No languages have been added for translation. To add a language, make a selection above.'
49
+ expect(page).not_to have_css 'table'
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,397 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe 'Translation editing', type: :feature do
4
+ let(:exhibit) { FactoryBot.create(:exhibit, title: 'Sample', subtitle: 'SubSample') }
5
+ let(:admin) { FactoryBot.create(:exhibit_admin, exhibit: exhibit) }
6
+ before do
7
+ FactoryBot.create(:language, exhibit: exhibit, locale: 'sq')
8
+ FactoryBot.create(:language, exhibit: exhibit, locale: 'fr')
9
+ login_as admin
10
+ end
11
+ describe 'general' do
12
+ before do
13
+ visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr')
14
+ end
15
+
16
+ it 'selects the correct language' do
17
+ expect(page).to have_css '.nav-pills li.active', text: 'French'
18
+ end
19
+ describe 'basic settings' do
20
+ it 'successfully adds translations' do
21
+ within '.translation-edit-form #general' do
22
+ expect(page).to have_css '.help-block', text: 'Sample'
23
+ expect(page).to have_css '.help-block', text: 'SubSample'
24
+ fill_in 'Title', id: 'exhibit_translations_attributes_0_value', with: 'Titre français'
25
+ fill_in 'Subtitle', with: 'Sous-titre français'
26
+ click_button 'Save changes'
27
+ end
28
+ expect(page).to have_css '.flash_messages', text: 'The exhibit was successfully updated.'
29
+ within '.translation-basic-settings-title' do
30
+ expect(page).to have_css 'input[value="Titre français"]'
31
+ expect(page).to have_css 'span.glyphicon.glyphicon-ok'
32
+ end
33
+ within '.translation-basic-settings-subtitle' do
34
+ expect(page).to have_css 'input[value="Sous-titre français"]'
35
+ expect(page).to have_css 'span.glyphicon.glyphicon-ok'
36
+ end
37
+ within '.translation-basic-settings-description' do
38
+ expect(page).to_not have_css 'span.glyphicon.glyphicon-ok'
39
+ end
40
+ end
41
+ end
42
+ describe 'main menu' do
43
+ it 'adds translations to exhibit navbar' do
44
+ within '.translation-edit-form #general' do
45
+ expect(page).to have_css '.help-block', text: 'Home'
46
+ fill_in 'Home', with: 'Maison'
47
+ fill_in 'Browse', with: 'parcourir ceci!'
48
+ click_button 'Save changes'
49
+ end
50
+ expect(page).to have_css '.flash_messages', text: 'The exhibit was successfully updated.'
51
+ within '.translation-main-menu-home' do
52
+ expect(page).to have_css 'input[value="Maison"]'
53
+ expect(page).to have_css 'span.glyphicon.glyphicon-ok'
54
+ end
55
+ within '.translation-main-menu-browse' do
56
+ expect(page).to have_css 'input[value="parcourir ceci!"]'
57
+ expect(page).to have_css 'span.glyphicon.glyphicon-ok'
58
+ end
59
+ within '.translation-main-menu-curated-features' do
60
+ expect(page).to_not have_css 'span.glyphicon.glyphicon-ok'
61
+ end
62
+ within '.translation-main-menu-about' do
63
+ expect(page).to_not have_css 'span.glyphicon.glyphicon-ok'
64
+ end
65
+ I18n.locale = :fr
66
+ expect(exhibit.main_navigations.browse.label).to eq 'parcourir ceci!'
67
+ expect(I18n.t(:'spotlight.curation.nav.home')).to eq 'Maison'
68
+ I18n.locale = I18n.default_locale
69
+ end
70
+
71
+ before do
72
+ exhibit.searches.first.update(published: true)
73
+ within '.translation-edit-form #general' do
74
+ fill_in 'Home', with: 'Maison'
75
+ fill_in 'Browse', with: 'parcourir ceci!'
76
+ click_button 'Save changes'
77
+ end
78
+ end
79
+ it 'adds translations to user-facing breadcrumbs' do
80
+ expect(page).to have_css '.flash_messages', text: 'The exhibit was successfully updated.'
81
+ visit spotlight.exhibit_browse_index_path(exhibit, locale: 'fr')
82
+ expect(page).to have_breadcrumbs 'Maison', 'parcourir ceci!'
83
+ end
84
+
85
+ it 'does not translate admin breadcrumbs' do
86
+ expect(page).to have_css '.flash_messages', text: 'The exhibit was successfully updated.'
87
+ visit spotlight.exhibit_searches_path(exhibit, locale: 'fr')
88
+ expect(page).to have_breadcrumbs 'Home', 'Curation', 'Browse'
89
+ end
90
+ end
91
+
92
+ describe 'breadcrumbs' do
93
+ describe 'browse categories' do
94
+ before do
95
+ exhibit.searches.first.update(published: true)
96
+ within '.translation-edit-form #general' do
97
+ fill_in 'Home', with: 'Maison'
98
+ fill_in 'Browse', with: 'parcourir ceci!'
99
+ click_button 'Save changes'
100
+ end
101
+ end
102
+
103
+ it 'adds translations to user-facing breadcrumbs' do
104
+ visit spotlight.exhibit_browse_index_path(exhibit, locale: 'fr')
105
+ expect(page).to have_breadcrumbs 'Maison', 'parcourir ceci!'
106
+ end
107
+
108
+ it 'does not translate admin breadcrumbs' do
109
+ visit spotlight.exhibit_searches_path(exhibit, locale: 'fr')
110
+ expect(page).to have_breadcrumbs 'Home', 'Curation', 'Browse'
111
+ end
112
+ end
113
+
114
+ describe 'pages' do
115
+ let!(:about_page1) { FactoryBot.create(:about_page, title: 'First Page', exhibit: exhibit, locale: 'fr') }
116
+
117
+ before do
118
+ within '.translation-edit-form #general' do
119
+ fill_in 'Home', with: 'Maison'
120
+ fill_in 'About', with: 'Sur'
121
+ click_button 'Save changes'
122
+ end
123
+ end
124
+ it 'adds breadcrumbs to pages' do
125
+ visit spotlight.exhibit_about_page_path(about_page1.exhibit, about_page1, locale: 'fr')
126
+ expect(page).to have_breadcrumbs 'Maison', 'Sur', about_page1.title
127
+ end
128
+
129
+ it 'does not translate admin breadcrumbs' do
130
+ visit spotlight.exhibit_about_pages_path(exhibit, locale: 'fr')
131
+ expect(page).to have_breadcrumbs 'Home', 'Curation', 'About'
132
+ end
133
+ end
134
+
135
+ describe 'Catalog' do
136
+ before do
137
+ within '.translation-edit-form #general' do
138
+ fill_in 'Home', with: 'Maison'
139
+ fill_in 'Search Results', with: 'Résultats de la recherche'
140
+ click_button 'Save changes'
141
+ end
142
+ end
143
+ it 'adds breadcrumbs user facing catalog' do
144
+ visit spotlight.search_exhibit_catalog_path(exhibit, q: '*', locale: 'fr')
145
+ expect(page).to have_breadcrumbs 'Maison', 'Résultats de la recherche'
146
+ end
147
+
148
+ it 'does not translate admin catalog' do
149
+ visit spotlight.admin_exhibit_catalog_path(exhibit, locale: 'fr')
150
+ expect(page).to have_breadcrumbs 'Home', 'Curation', 'Items'
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ describe 'Metadata field labels' do
157
+ before { visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr') }
158
+
159
+ it 'redirects to the same form tab' do
160
+ click_link 'Metadata field labels'
161
+ within('#metadata', visible: true) do
162
+ fill_in 'Everything', with: 'Tout'
163
+ click_button 'Save changes'
164
+ end
165
+
166
+ expect(page).to have_css '.nav-pills li.active', text: 'French'
167
+ expect(page).to have_css '.nav-tabs li.active', text: 'Metadata field labels'
168
+ end
169
+
170
+ describe 'configured fields' do
171
+ it 'has a text input for each metadata field' do
172
+ within '#metadata' do
173
+ expect(page).to have_css('input[type="text"]', count: 17)
174
+ end
175
+ end
176
+
177
+ it 'allows users to translate both index and show metadata field labels', js: true do
178
+ click_link 'Metadata field labels'
179
+
180
+ within('#metadata', visible: true) do
181
+ language_label = find('label', text: 'Language', visible: true)
182
+ language_input = find("##{language_label['for']}", visible: true)
183
+ language_input.set('Langue')
184
+ click_button 'Save changes'
185
+ end
186
+
187
+ visit spotlight.search_exhibit_catalog_path(exhibit, f: { language_ssim: ['Latin'] }, locale: 'fr')
188
+
189
+ expect(page).to have_css('dt.blacklight-language_ssm', text: 'Langue')
190
+
191
+ click_link 'Orbis terrarum tabula recens emendata et in lucem edita'
192
+
193
+ expect(page).to have_css('dt.blacklight-language_ssm', text: 'Langue')
194
+ end
195
+ end
196
+
197
+ describe 'Exhibit-specific fields' do
198
+ let!(:custom_field) { FactoryBot.create(:custom_field, exhibit: exhibit) }
199
+
200
+ before do
201
+ visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr')
202
+ end
203
+
204
+ it 'has text inputs for the exhibit-specific fields' do
205
+ within '#metadata' do
206
+ expect(page).to have_css('input[type="text"]', count: 18)
207
+
208
+ within '.translation-exhibit-specific-fields' do
209
+ expect(page).to have_css('input[type="text"]', count: 1)
210
+ end
211
+ end
212
+ end
213
+
214
+ it 'allows users to translate exhibit-specific metadata fields' do
215
+ within '#metadata' do
216
+ fill_in custom_field.configuration['label'], with: 'French Custom Field Label'
217
+ click_button 'Save changes'
218
+ end
219
+
220
+ # Adding some data to our custom field
221
+ visit spotlight.exhibit_solr_document_path(exhibit, 'dq287tq6352', locale: :fr)
222
+ expect(page).to have_link 'Edit'
223
+ click_on 'Edit'
224
+ fill_in custom_field.configuration['label'], with: 'Custom Field Data'
225
+ click_on 'Save changes'
226
+
227
+ expect(page).to have_css('dt', text: 'French Custom Field Label')
228
+ expect(page).to have_css('dd', text: 'Custom Field Data')
229
+ end
230
+ end
231
+ end
232
+
233
+ describe 'Search field labels' do
234
+ before { visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr') }
235
+
236
+ it 'redirects to the same form tab' do
237
+ click_link 'Search field labels'
238
+ within('#search_fields', visible: true) do
239
+ fill_in 'Everything', with: 'Tout'
240
+ click_button 'Save changes'
241
+ end
242
+
243
+ expect(page).to have_css '.nav-pills li.active', text: 'French'
244
+ expect(page).to have_css '.nav-tabs li.active', text: 'Search field labels'
245
+ end
246
+
247
+ describe 'field-based search fields' do
248
+ it 'has a text input for each enabled search field' do
249
+ within '#search_fields .translation-field-based-search-fields' do
250
+ expect(page).to have_css('input[type="text"]', count: 3)
251
+ end
252
+ end
253
+
254
+ it 'allows users to translate field-based search fields', js: true do
255
+ click_link 'Search field labels'
256
+
257
+ within('#search_fields', visible: true) do
258
+ fill_in 'Everything', with: 'Tout'
259
+ click_button 'Save changes'
260
+ end
261
+
262
+ visit spotlight.exhibit_path(exhibit, locale: 'fr')
263
+
264
+ expect(page).to have_css('select#search_field option', text: 'Tout')
265
+ end
266
+ end
267
+
268
+ describe 'facet fields' do
269
+ it 'has a text input for each facet field' do
270
+ within '#search_fields .translation-facet-fields' do
271
+ expect(page).to have_css('input[type="text"]', count: 7)
272
+ end
273
+ end
274
+
275
+ it 'allows users to translate facet fields', js: true do
276
+ click_link 'Search field labels'
277
+
278
+ within('#search_fields', visible: true) do
279
+ fill_in 'Geographic', with: 'Géographique'
280
+ click_button 'Save changes'
281
+ end
282
+
283
+ visit spotlight.search_exhibit_catalog_path(exhibit, q: '*', locale: 'fr')
284
+
285
+ expect(page).to have_css('h3.facet-field-heading', text: 'Géographique')
286
+ end
287
+ end
288
+
289
+ describe 'sort fields' do
290
+ it 'has a text input for each sort field' do
291
+ within '#search_fields .translation-sort-fields' do
292
+ expect(page).to have_css('input[type="text"]', count: 6)
293
+ end
294
+ end
295
+
296
+ it 'allows users to translation sort fields', js: true do
297
+ click_link 'Search field labels'
298
+
299
+ within('#search_fields', visible: true) do
300
+ fill_in 'Relevance', with: 'French Relevance'
301
+ click_button 'Save changes'
302
+ end
303
+
304
+ visit spotlight.search_exhibit_catalog_path(exhibit, q: '*', locale: 'fr')
305
+
306
+ expect(page).to have_css('.dropdown-toggle', text: 'Trier par French Relevance', visible: true)
307
+ end
308
+ end
309
+ end
310
+
311
+ describe 'Browse categories' do
312
+ before do
313
+ FactoryBot.create(:search, exhibit: exhibit, title: 'Browse Category 1')
314
+
315
+ visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr')
316
+ end
317
+
318
+ it 'has a title and description for every browse category' do
319
+ within '#browse' do
320
+ expect(page).to have_css('input[type="text"]', count: 2)
321
+ expect(page).to have_css('textarea', count: 2)
322
+
323
+ expect(page).to have_field 'All Exhibit Items'
324
+ expect(page).to have_field 'Browse Category 1'
325
+ expect(page).to have_css('.help-block', text: 'All items in this exhibit.')
326
+ end
327
+ end
328
+
329
+ it 'redirects to the same form tab' do
330
+ click_link 'Browse categories'
331
+ within('#browse', visible: true) do
332
+ fill_in 'All Exhibit Items', with: "Tous les objets d'exposition"
333
+ click_button 'Save changes'
334
+ end
335
+
336
+ expect(page).to have_css '.nav-pills li.active', text: 'French'
337
+ expect(page).to have_css '.nav-tabs li.active', text: 'Browse categories'
338
+ end
339
+
340
+ it 'persists changes', js: true do
341
+ click_link 'Browse categories'
342
+
343
+ within('#browse', visible: true) do
344
+ fill_in 'All Exhibit Items', with: "Tous les objets d'exposition"
345
+
346
+ first('.tanslation-description-toggle').click
347
+
348
+ textarea = page.find('textarea')
349
+ textarea.set('Tous les articles de cette exposition.')
350
+
351
+ click_button 'Save changes'
352
+ end
353
+
354
+ expect(page).to have_css('.flash_messages', text: 'The exhibit was successfully updated.')
355
+
356
+ expect(exhibit.searches.first.title).to eq 'All Exhibit Items'
357
+ expect(exhibit.searches.first.long_description).to eq 'All items in this exhibit.'
358
+
359
+ I18n.locale = :fr
360
+ expect(exhibit.searches.first.title).to eq "Tous les objets d'exposition"
361
+ expect(exhibit.searches.first.long_description).to eq 'Tous les articles de cette exposition.'
362
+ I18n.locale = I18n.default_locale
363
+ end
364
+ end
365
+
366
+ describe 'home page translation table entry' do
367
+ let(:feature_page) { FactoryBot.create(:feature_page, exhibit: exhibit) }
368
+ let(:about_page) { FactoryBot.create(:about_page, exhibit: exhibit) }
369
+ before do
370
+ exhibit.home_page.clone_for_locale('fr').save
371
+ about_page.clone_for_locale('fr').tap { |p| p.published = true }.save
372
+ visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr', tab: 'pages')
373
+ end
374
+
375
+ it 'renders a disabled checkbox in the table' do
376
+ # home page should have a disabled checkbox
377
+ expect(page).to have_css('.translation-home-page-settings input[type="checkbox"][disabled]')
378
+ # feature page does not have a translation, so don't use checkbox
379
+ expect(page).not_to have_css('.translation-feature-page-settings input[type="checkbox"]')
380
+ # about page should have a checked checkbox
381
+ expect(page).to have_css('.translation-about-page-settings input[type="checkbox"][checked]')
382
+ end
383
+ end
384
+
385
+ describe 'translation progress counter', js: true do
386
+ before do
387
+ FactoryBot.create(:translation, exhibit: exhibit, locale: 'fr', key: "#{exhibit.slug}.title", value: 'Titre')
388
+ end
389
+ it 'counts existing and total available translations' do
390
+ visit spotlight.edit_exhibit_translations_path(exhibit, language: 'fr')
391
+ expect(page).to have_link('General 1/8')
392
+ expect(page).to have_link('Search field labels 0/16')
393
+ expect(page).to have_link('Browse categories 0/2')
394
+ expect(page).to have_link('Metadata field labels 0/17')
395
+ end
396
+ end
397
+ end