From df9955e0c60e766abf8a0046f96dbce3501b7bba Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 21 Sep 2018 20:52:35 +0200 Subject: [PATCH] make use of the new spec helper it_behaves_like translatable --- spec/features/admin/poll/polls_spec.rb | 5 + spec/features/admin/poll/questions_spec.rb | 42 +++++ .../poll_question_answers_spec.rb | 17 +- .../translations/poll_questions_spec.rb | 147 ------------------ spec/features/translations/polls_spec.rb | 131 ---------------- spec/shared/features/translatable.rb | 4 + 6 files changed, 65 insertions(+), 281 deletions(-) delete mode 100644 spec/features/translations/poll_questions_spec.rb delete mode 100644 spec/features/translations/polls_spec.rb diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index cfad58f96..b28aff019 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -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 diff --git a/spec/features/admin/poll/questions_spec.rb b/spec/features/admin/poll/questions_spec.rb index 2b3762c53..230ba5c28 100644 --- a/spec/features/admin/poll/questions_spec.rb +++ b/spec/features/admin/poll/questions_spec.rb @@ -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 diff --git a/spec/features/translations/poll_question_answers_spec.rb b/spec/features/translations/poll_question_answers_spec.rb index 3de1bfb38..cd33106c1 100644 --- a/spec/features/translations/poll_question_answers_spec.rb +++ b/spec/features/translations/poll_question_answers_spec.rb @@ -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 diff --git a/spec/features/translations/poll_questions_spec.rb b/spec/features/translations/poll_questions_spec.rb deleted file mode 100644 index 0acd8cf1b..000000000 --- a/spec/features/translations/poll_questions_spec.rb +++ /dev/null @@ -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 diff --git a/spec/features/translations/polls_spec.rb b/spec/features/translations/polls_spec.rb deleted file mode 100644 index d702205a1..000000000 --- a/spec/features/translations/polls_spec.rb +++ /dev/null @@ -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 diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb index 9757b134c..ab0a5e75c 100644 --- a/spec/shared/features/translatable.rb +++ b/spec/shared/features/translatable.rb @@ -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