make use of the new spec helper it_behaves_like translatable

This commit is contained in:
Julian Herrero
2018-09-21 20:52:35 +02:00
parent 549c086574
commit df9955e0c6
6 changed files with 65 additions and 281 deletions

View File

@@ -7,6 +7,11 @@ feature 'Admin polls' do
login_as(admin.user)
end
it_behaves_like "translatable",
"poll",
"edit_admin_poll_path",
%w[name summary description]
scenario 'Index empty', :js do
visit admin_root_path

View File

@@ -6,6 +6,11 @@ feature 'Admin poll questions' do
login_as(create(:administrator).user)
end
it_behaves_like "translatable",
"poll_question",
"edit_admin_question_path",
%w[title]
scenario 'Index' do
question1 = create(:poll_question)
question2 = create(:poll_question)
@@ -108,4 +113,41 @@ feature 'Admin poll questions' do
pending "Mark all city by default when creating a poll question from a successful proposal"
context "Poll select box" do
let(:poll) { create(:poll, name_en: "Name in English",
name_es: "Nombre en Español",
summary_en: "Summary in English",
summary_es: "Resumen en Español",
description_en: "Description in English",
description_es: "Descripción en Español") }
let(:question) { create(:poll_question, poll: poll,
title_en: "Question in English",
title_es: "Pregunta en Español") }
before do
@edit_question_url = edit_admin_question_path(question)
end
scenario "translates the poll name in options", :js do
visit @edit_question_url
expect(page).to have_select('poll_question_poll_id', options: [poll.name_en])
select('Español', from: 'locale-switcher')
expect(page).to have_select('poll_question_poll_id', options: [poll.name_es])
end
scenario "uses fallback if name is not translated to current locale", :js do
visit @edit_question_url
expect(page).to have_select('poll_question_poll_id', options: [poll.name_en])
select('Français', from: 'locale-switcher')
expect(page).to have_select('poll_question_poll_id', options: [poll.name_es])
end
end
end

View File

@@ -57,12 +57,12 @@ feature "Translations" do
expect(page).to have_content "Description en Français"
end
scenario "Update a translation", :js do
scenario "Update a translation with allowed blank translated field", :js do
visit @edit_answer_url
click_link "Español"
fill_in 'poll_question_answer_title_es', with: 'Pregunta correcta en Español'
fill_in_ckeditor 'poll_question_answer_description_es', with: 'Descripción correcta en Español'
fill_in_ckeditor 'poll_question_answer_description_es', with: ''
click_button 'Save'
expect(page).to have_content "Changes saved"
@@ -72,7 +72,7 @@ feature "Translations" do
select('Español', from: 'locale-switcher')
expect(page).to have_content("Pregunta correcta en Español")
expect(page).to have_content("Descripción correcta en Español")
expect(page).to_not have_content("Descripción en Español")
end
scenario "Remove a translation", :js do
@@ -88,6 +88,17 @@ feature "Translations" do
expect(page).not_to have_link "Español"
end
scenario "Add a translation for a locale with non-underscored name", :js do
visit @edit_answer_url
select('Português', from: 'translation_locale')
fill_in_ckeditor 'poll_question_answer_description_pt_br', with: 'resposta em Português'
click_button 'Save'
select('Português', from: 'locale-switcher')
expect(page).to have_content("resposta em Português")
end
context "Globalize javascript interface" do
scenario "Highlight current locale", :js do

View File

@@ -1,147 +0,0 @@
# coding: utf-8
require 'rails_helper'
feature "Translations" do
context "Polls" do
let(:poll) { create(:poll, name_en: "Name in English",
name_es: "Nombre en Español",
summary_en: "Summary in English",
summary_es: "Resumen en Español",
description_en: "Description in English",
description_es: "Descripción en Español") }
background do
admin = create(:administrator)
login_as(admin.user)
end
context "Questions" do
let(:question) { create(:poll_question, poll: poll,
title_en: "Question in English",
title_es: "Pregunta en Español") }
before do
@edit_question_url = edit_admin_question_path(question)
end
context "Poll select box" do
scenario "translates the poll name in options", :js do
visit @edit_question_url
expect(page).to have_select('poll_question_poll_id', options: [poll.name_en])
select('Español', from: 'locale-switcher')
expect(page).to have_select('poll_question_poll_id', options: [poll.name_es])
end
scenario "uses fallback if name is not translated to current locale", :js do
visit @edit_question_url
expect(page).to have_select('poll_question_poll_id', options: [poll.name_en])
select('Français', from: 'locale-switcher')
expect(page).to have_select('poll_question_poll_id', options: [poll.name_es])
end
end
scenario "Add a translation", :js do
visit @edit_question_url
select "Français", from: "translation_locale"
fill_in 'poll_question_title_fr', with: 'Question en Français'
click_button 'Save'
expect(page).to have_content "Changes saved"
visit @edit_question_url
expect(page).to have_field('poll_question_title_en', with: 'Question in English')
click_link "Español"
expect(page).to have_field('poll_question_title_es', with: 'Pregunta en Español')
click_link "Français"
expect(page).to have_field('poll_question_title_fr', with: 'Question en Français')
end
scenario "Update a translation", :js do
visit @edit_question_url
click_link "Español"
fill_in 'poll_question_title_es', with: 'Pregunta correcta en Español'
click_button 'Save'
expect(page).to have_content "Changes saved"
visit poll_path(poll)
expect(page).to have_content("Question in English")
select('Español', from: 'locale-switcher')
expect(page).to have_content("Pregunta correcta en Español")
end
scenario "Remove a translation", :js do
visit @edit_question_url
click_link "Español"
click_link "Remove language"
expect(page).not_to have_link "Español"
click_button "Save"
visit @edit_question_url
expect(page).not_to have_link "Español"
end
context "Globalize javascript interface" do
scenario "Highlight current locale", :js do
visit @edit_question_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_question_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_question_url
expect(page).to have_field('poll_question_title_en', with: 'Question in English')
click_link "Español"
expect(page).to have_field('poll_question_title_es', with: 'Pregunta en Español')
end
scenario "Select a locale and add it to the poll form", :js do
visit @edit_question_url
select "Français", from: "translation_locale"
expect(page).to have_link "Français"
click_link "Français"
expect(page).to have_field('poll_question_title_fr')
end
end
end
end
end

View File

@@ -1,131 +0,0 @@
# coding: utf-8
require 'rails_helper'
feature "Translations" do
context "Polls" do
let(:poll) { create(:poll, name_en: "Name in English",
name_es: "Nombre en Español",
summary_en: "Summary in English",
summary_es: "Resumen en Español",
description_en: "Description in English",
description_es: "Descripción en Español") }
background do
admin = create(:administrator)
login_as(admin.user)
end
before do
@edit_poll_url = edit_admin_poll_path(poll)
end
scenario "Add a translation", :js do
visit @edit_poll_url
select "Français", from: "translation_locale"
fill_in 'poll_name_fr', with: 'Name en Français'
fill_in 'poll_summary_fr', with: 'Summary en Français'
fill_in 'poll_description_fr', with: 'Description en Français'
click_button 'Update poll'
expect(page).to have_content "Poll updated successfully"
visit @edit_poll_url
expect(page).to have_field('poll_name_en', with: 'Name in English')
expect(page).to have_field('poll_summary_en', with: 'Summary in English')
expect(page).to have_field('poll_description_en', with: 'Description in English')
click_link "Español"
expect(page).to have_field('poll_name_es', with: 'Nombre en Español')
expect(page).to have_field('poll_summary_es', with: 'Resumen en Español')
expect(page).to have_field('poll_description_es', with: 'Descripción en Español')
click_link "Français"
expect(page).to have_field('poll_name_fr', with: 'Name en Français')
expect(page).to have_field('poll_summary_fr', with: 'Summary en Français')
expect(page).to have_field('poll_description_fr', with: 'Description en Français')
end
scenario "Update a translation", :js do
visit @edit_poll_url
click_link "Español"
fill_in 'poll_name_es', with: 'Nombre correcto en Español'
fill_in 'poll_summary_es', with: 'Resumen correcto en Español'
fill_in 'poll_description_es', with: 'Descripción correcta en Español'
click_button 'Update poll'
expect(page).to have_content "Poll updated successfully"
visit poll_path(poll)
expect(page).to have_content("Name in English")
expect(page).to have_content("Summary in English")
expect(page).to have_content("Description in English")
select('Español', from: 'locale-switcher')
expect(page).to have_content("Nombre correcto en Español")
expect(page).to have_content("Resumen correcto en Español")
expect(page).to have_content("Descripción correcta en Español")
end
scenario "Remove a translation", :js do
visit @edit_poll_url
click_link "Español"
click_link "Remove language"
expect(page).not_to have_link "Español"
click_button "Update poll"
visit @edit_poll_url
expect(page).not_to have_link "Español"
end
context "Globalize javascript interface" do
scenario "Highlight current locale", :js do
visit @edit_poll_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_poll_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_poll_url
expect(page).to have_field('poll_description_en', with: 'Description in English')
click_link "Español"
expect(page).to have_field('poll_description_es', with: 'Descripción en Español')
end
scenario "Select a locale and add it to the poll form", :js do
visit @edit_poll_url
select "Français", from: "translation_locale"
expect(page).to have_link "Français"
click_link "Français"
expect(page).to have_field('poll_description_fr')
end
end
end
end

View File

@@ -188,6 +188,10 @@ def update_button_text
"Update milestone"
when "AdminNotification"
"Update notification"
when "Poll"
"Update poll"
when "Poll::Question"
"Save"
else
"Save changes"
end