Add test coverage for switching language in darkswarm and admin

This commit is contained in:
Julius Pabrinkis
2017-06-08 22:36:03 +01:00
committed by Maikel Linke
parent c6f6f5bc55
commit ec6a365227
4 changed files with 81 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ Openfoodnetwork::Application.configure do
# Tests assume English text on the site.
config.i18n.default_locale = "en"
config.i18n.available_locales = ['en', 'es']
I18n.locale = config.i18n.locale = config.i18n.default_locale
# Use SQL instead of Active Record's schema dumper when creating the test database.

View File

@@ -0,0 +1,40 @@
require 'spec_helper'
feature 'Multilingual', js: true do
include AuthenticationWorkflow
include WebHelper
background do
login_to_admin_section
end
it 'has two locales available' do
expect(Rails.application.config.i18n[:default_locale]).to eq 'en'
expect(Rails.application.config.i18n[:locale]).to eq 'en'
expect(Rails.application.config.i18n[:available_locales]).to eq ['en', 'es']
end
it 'can switch language by params' do
expect(get_i18n_locale).to eq 'en'
expect(get_i18n_translation('spree_admin_overview_enterprises_header')).to eq 'My Enterprises'
expect(page).to have_content 'My Enterprises'
visit spree.admin_path(locale: 'es')
expect(get_i18n_locale).to eq 'es'
expect(get_i18n_translation('spree_admin_overview_enterprises_header')).to eq 'Mis Organizaciones'
expect(page).to have_content 'Mis Organizaciones'
end
it 'fallbacks to default_locale' do
pending 'current spree core has a bug if not available locale is provided'
# undefined method `delete_if' for "translation missing: it.date.month_names":String
# inside core/app/views/spree/admin/shared/_translations.html.erb
# I18n-js fallsback to 'en'
visit spree.admin_path(locale: 'it')
expect(get_i18n_locale).to eq 'it'
expect(get_i18n_translation('spree_admin_overview_enterprises_header')).to eq 'My Enterprises'
# This still is italian until we change enforce_available_locales to `true`
expect(page).to have_content 'Le Mie Aziende'
end
end

View File

@@ -0,0 +1,32 @@
require 'spec_helper'
feature 'Multilingual', js: true do
include WebHelper
it 'has two locales available' do
expect(Rails.application.config.i18n[:default_locale]).to eq 'en'
expect(Rails.application.config.i18n[:locale]).to eq 'en'
expect(Rails.application.config.i18n[:available_locales]).to eq ['en', 'es']
end
it 'can switch language by params' do
visit root_path
expect(get_i18n_locale).to eq 'en'
expect(get_i18n_translation('label_shops')).to eq 'Shops'
expect(page).to have_content 'Interested in getting on the Open Food Network?'
expect(page).to have_content 'SHOPS'
visit root_path(locale: 'es')
expect(get_i18n_locale).to eq 'es'
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
expect(page).to have_content '¿Estás interesada en entrar en Open Food Network?'
expect(page).to have_content 'TIENDAS'
# I18n-js fallsback to 'en'
visit root_path(locale: 'it')
expect(get_i18n_locale).to eq 'it'
expect(get_i18n_translation('label_shops')).to eq 'Shops'
# This still is italian until we change enforce_available_locales to `true`
expect(page).to have_content 'NEGOZI'
end
end

View File

@@ -113,6 +113,14 @@ module WebHelper
DirtyFormDialog.new(page)
end
def get_i18n_locale
page.evaluate_script("I18n.locale;")
end
def get_i18n_translation(key = nil)
page.evaluate_script("I18n.t('#{key}');")
end
# Fetch the content of a script block
# eg. script_content with: 'my-script.com'
# Returns nil if not found