Share Globalize JavaScript interface specs
This commit is contained in:
@@ -7,6 +7,8 @@ module ActionDispatch::Routing::UrlFor
|
|||||||
case resource.class.name
|
case resource.class.name
|
||||||
when "Budget::Investment"
|
when "Budget::Investment"
|
||||||
[resource.budget, resource]
|
[resource.budget, resource]
|
||||||
|
when "Budget::Investment::Milestone"
|
||||||
|
[resource.investment.budget, resource.investment, resource]
|
||||||
when "Legislation::Annotation"
|
when "Legislation::Annotation"
|
||||||
[resource.draft_version.process, resource.draft_version, resource]
|
[resource.draft_version.process, resource.draft_version, resource]
|
||||||
when "Legislation::Proposal", "Legislation::Question"
|
when "Legislation::Proposal", "Legislation::Question"
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ feature 'Admin banners magement' do
|
|||||||
login_as(create(:administrator).user)
|
login_as(create(:administrator).user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_behaves_like "translatable",
|
||||||
|
"banner",
|
||||||
|
"edit_admin_banner_path",
|
||||||
|
%w[title description]
|
||||||
|
|
||||||
context "Index" do
|
context "Index" do
|
||||||
background do
|
background do
|
||||||
@banner1 = create(:banner, title: "Banner number one",
|
@banner1 = create(:banner, title: "Banner number one",
|
||||||
@@ -256,50 +261,5 @@ feature 'Admin banners magement' do
|
|||||||
visit @edit_banner_url
|
visit @edit_banner_url
|
||||||
expect(page).not_to have_link "Español"
|
expect(page).not_to have_link "Español"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Globalize javascript interface" do
|
|
||||||
|
|
||||||
scenario "Highlight current locale", :js do
|
|
||||||
visit @edit_banner_url
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
select('Español', from: 'locale-switcher')
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Highlight selected locale", :js do
|
|
||||||
visit @edit_banner_url
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show selected locale form", :js do
|
|
||||||
visit @edit_banner_url
|
|
||||||
|
|
||||||
expect(page).to have_field('banner_description_en', with: 'Description in English')
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(page).to have_field('banner_description_es', with: 'Descripción en Español')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Select a locale and add it to the banner form", :js do
|
|
||||||
visit @edit_banner_url
|
|
||||||
|
|
||||||
select "Français", from: "translation_locale"
|
|
||||||
|
|
||||||
expect(page).to have_link "Français"
|
|
||||||
|
|
||||||
click_link "Français"
|
|
||||||
|
|
||||||
expect(page).to have_field('banner_description_fr')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ feature "Admin custom information texts" do
|
|||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_behaves_like "translatable",
|
||||||
|
"i18n_content",
|
||||||
|
"admin_site_customization_information_texts_path",
|
||||||
|
%w[value]
|
||||||
|
|
||||||
scenario 'page is correctly loaded' do
|
scenario 'page is correctly loaded' do
|
||||||
visit admin_site_customization_information_texts_path
|
visit admin_site_customization_information_texts_path
|
||||||
|
|
||||||
@@ -113,60 +118,6 @@ feature "Admin custom information texts" do
|
|||||||
expect(debate_text.value_en).to eq('Custom debate text')
|
expect(debate_text.value_en).to eq('Custom debate text')
|
||||||
expect(debate_title.value_en).to eq('Custom debate title')
|
expect(debate_title.value_en).to eq('Custom debate title')
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Javascript interface" do
|
|
||||||
|
|
||||||
scenario "Highlight current locale", :js do
|
|
||||||
visit admin_site_customization_information_texts_path
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
select('Español', from: 'locale-switcher')
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Highlight selected locale", :js do
|
|
||||||
key = "debates.form.debate_title"
|
|
||||||
content = create(:i18n_content, key: key, value_es: 'Título')
|
|
||||||
|
|
||||||
visit admin_site_customization_information_texts_path
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show selected locale form", :js do
|
|
||||||
key = "debates.form.debate_title"
|
|
||||||
content = create(:i18n_content, key: key,
|
|
||||||
value_en: 'Title',
|
|
||||||
value_es: 'Título')
|
|
||||||
|
|
||||||
visit admin_site_customization_information_texts_path
|
|
||||||
|
|
||||||
expect(page).to have_field("contents_content_#{key}values_value_en", with: 'Title')
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(page).to have_field("contents_content_#{key}values_value_es", with: 'Título')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Select a locale and add it to the form", :js do
|
|
||||||
key = "debates.form.debate_title"
|
|
||||||
|
|
||||||
visit admin_site_customization_information_texts_path
|
|
||||||
select "Français", from: "translation_locale"
|
|
||||||
|
|
||||||
expect(page).to have_link "Français"
|
|
||||||
|
|
||||||
click_link "Français"
|
|
||||||
expect(page).to have_field("contents_content_#{key}values_value_fr")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ feature "Translations" do
|
|||||||
description_en: "Description in English",
|
description_en: "Description in English",
|
||||||
description_es: "Descripción en Español") }
|
description_es: "Descripción en Español") }
|
||||||
|
|
||||||
|
it_behaves_like "translatable",
|
||||||
|
"budget_investment_milestone",
|
||||||
|
"edit_admin_budget_budget_investment_budget_investment_milestone_path",
|
||||||
|
%w[description]
|
||||||
|
|
||||||
background do
|
background do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator)
|
||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
@@ -103,51 +108,6 @@ feature "Translations" do
|
|||||||
expect(page).to have_content('Description in pt-BR')
|
expect(page).to have_content('Description in pt-BR')
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Globalize javascript interface" do
|
|
||||||
|
|
||||||
scenario "Highlight current locale", :js do
|
|
||||||
visit @edit_milestone_url
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
select('Español', from: 'locale-switcher')
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Highlight selected locale", :js do
|
|
||||||
visit @edit_milestone_url
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show selected locale form", :js do
|
|
||||||
visit @edit_milestone_url
|
|
||||||
|
|
||||||
expect(page).to have_field('budget_investment_milestone_description_en', with: 'Description in English')
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(page).to have_field('budget_investment_milestone_description_es', with: 'Descripción en Español')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Select a locale and add it to the milestone form", :js do
|
|
||||||
visit @edit_milestone_url
|
|
||||||
|
|
||||||
select "Français", from: "translation_locale"
|
|
||||||
|
|
||||||
expect(page).to have_link "Français"
|
|
||||||
|
|
||||||
click_link "Français"
|
|
||||||
|
|
||||||
expect(page).to have_field('budget_investment_milestone_description_fr')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
73
spec/shared/features/translatable.rb
Normal file
73
spec/shared/features/translatable.rb
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
shared_examples "translatable" do |factory_name, path_name, fields|
|
||||||
|
let(:language_texts) { { es: "en español", en: "in English", fr: "en Français" } }
|
||||||
|
let(:translatable_class) { build(factory_name).class }
|
||||||
|
|
||||||
|
let(:attributes) do
|
||||||
|
fields.product(%i[en es]).map do |field, locale|
|
||||||
|
[:"#{field}_#{locale}", text_for(field, locale)]
|
||||||
|
end.to_h
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:translatable) { create(factory_name, attributes) }
|
||||||
|
let(:path) { send(path_name, *resource_hierarchy_for(translatable)) }
|
||||||
|
before { login_as(create(:administrator).user) }
|
||||||
|
|
||||||
|
context "Globalize javascript interface" do
|
||||||
|
scenario "Highlight current locale", :js do
|
||||||
|
visit path
|
||||||
|
|
||||||
|
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
||||||
|
|
||||||
|
select('Español', from: 'locale-switcher')
|
||||||
|
|
||||||
|
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Highlight selected locale", :js do
|
||||||
|
visit path
|
||||||
|
|
||||||
|
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
||||||
|
|
||||||
|
click_link "Español"
|
||||||
|
|
||||||
|
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Show selected locale form", :js do
|
||||||
|
visit path
|
||||||
|
field = fields.last # TODO: not sure about first, last, or sample
|
||||||
|
|
||||||
|
expect(page).to have_field(field_for(field, :en), with: text_for(field, :en))
|
||||||
|
|
||||||
|
click_link "Español"
|
||||||
|
|
||||||
|
expect(page).to have_field(field_for(field, :es), with: text_for(field, :es))
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Select a locale and add it to the form", :js do
|
||||||
|
visit path
|
||||||
|
|
||||||
|
select "Français", from: "translation_locale"
|
||||||
|
|
||||||
|
expect(page).to have_link "Français"
|
||||||
|
|
||||||
|
click_link "Français"
|
||||||
|
|
||||||
|
expect(page).to have_field(field_for(fields.last, :fr))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def text_for(field, locale)
|
||||||
|
I18n.with_locale(locale) do
|
||||||
|
"#{translatable_class.human_attribute_name(field)} #{language_texts[locale]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def field_for(field, locale)
|
||||||
|
if translatable_class.name == "I18nContent"
|
||||||
|
"contents_content_#{translatable.key}values_#{field}_#{locale}"
|
||||||
|
else
|
||||||
|
"#{translatable_class.model_name.singular}_#{field}_#{locale}"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user