Enable JS in shared translatable test
Due to its markdown editor, the admin draft version page requires JS to correctly render the draft version form.
This commit is contained in:
@@ -9,7 +9,7 @@ class Legislation::DraftVersion < ActiveRecord::Base
|
||||
translates :body, touch: true
|
||||
translates :body_html, touch: true
|
||||
translates :toc_html, touch: true
|
||||
globalize_accessors locales: [:en, :es, :fr, :nl, :val, :pt_br]
|
||||
globalize_accessors
|
||||
|
||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||
has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy
|
||||
|
||||
@@ -11,7 +11,7 @@ module ActionDispatch::Routing::UrlFor
|
||||
[resource.investment.budget, resource.investment, resource]
|
||||
when "Legislation::Annotation"
|
||||
[resource.draft_version.process, resource.draft_version, resource]
|
||||
when "Legislation::Proposal", "Legislation::Question"
|
||||
when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion"
|
||||
[resource.process, resource]
|
||||
when "Topic"
|
||||
[resource.community, resource]
|
||||
|
||||
@@ -25,8 +25,12 @@ section "Creating legislation processes" do
|
||||
|
||||
Legislation::Process.find_each do |process|
|
||||
(1..3).each do |i|
|
||||
process.draft_versions.create!(title: "Version #{i}",
|
||||
body: Faker::Lorem.paragraphs.join("\n\n"))
|
||||
process.draft_versions.create!(title_en: "Version #{i}",
|
||||
title_es: "Versión #{i}",
|
||||
body_en: ["Draft version in English",
|
||||
*Faker::Lorem.paragraphs].join("\n\n"),
|
||||
body_es: ["Versión borrador en Español",
|
||||
*Faker::Lorem.paragraphs].join("\n\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,11 @@ require 'rails_helper'
|
||||
|
||||
feature 'Admin legislation draft versions' do
|
||||
|
||||
it_behaves_like "translatable",
|
||||
"legislation_draft_version",
|
||||
"edit_admin_legislation_process_draft_version_path",
|
||||
%w[title changelog]
|
||||
|
||||
background do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
@@ -107,73 +112,14 @@ feature 'Admin legislation draft versions' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Translations" do
|
||||
context "Special translation behaviour" do
|
||||
|
||||
let!(:draft_version) { create(:legislation_draft_version,
|
||||
title_en: "Title in English",
|
||||
title_es: "Título en Español",
|
||||
changelog_en: "Changes in English",
|
||||
changelog_es: "Cambios en Español",
|
||||
body_en: "Body in English",
|
||||
body_es: "Texto en Español") }
|
||||
let!(:draft_version) { create(:legislation_draft_version) }
|
||||
|
||||
before do
|
||||
@edit_draft_version_url = edit_admin_legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||
end
|
||||
scenario 'Add body translation through markup editor', :js do
|
||||
edit_path = edit_admin_legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||
|
||||
scenario "Add a translation", :js do
|
||||
visit @edit_draft_version_url
|
||||
|
||||
select "Français", from: "translation_locale"
|
||||
fill_in 'legislation_draft_version_title_fr', with: 'Titre en Français'
|
||||
|
||||
click_button 'Save changes'
|
||||
|
||||
visit @edit_draft_version_url
|
||||
expect(page).to have_field('legislation_draft_version_title_en', with: 'Title in English')
|
||||
|
||||
click_link "Español"
|
||||
expect(page).to have_field('legislation_draft_version_title_es', with: 'Título en Español')
|
||||
|
||||
click_link "Français"
|
||||
expect(page).to have_field('legislation_draft_version_title_fr', with: 'Titre en Français')
|
||||
end
|
||||
|
||||
scenario "Update a translation", :js do
|
||||
draft_version.update!(status: 'published')
|
||||
draft_version.process.update!(title_es: 'Título de proceso')
|
||||
|
||||
visit @edit_draft_version_url
|
||||
|
||||
click_link "Español"
|
||||
fill_in 'legislation_draft_version_title_es', with: 'Título correcto en Español'
|
||||
|
||||
click_button 'Save changes'
|
||||
|
||||
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||
|
||||
expect(page).to have_content("Title in English")
|
||||
|
||||
select('Español', from: 'locale-switcher')
|
||||
|
||||
expect(page).to have_content('Título correcto en Español')
|
||||
end
|
||||
|
||||
scenario "Remove a translation", :js do
|
||||
visit @edit_draft_version_url
|
||||
|
||||
click_link "Español"
|
||||
click_link "Remove language"
|
||||
|
||||
expect(page).not_to have_link "Español"
|
||||
|
||||
click_button "Save changes"
|
||||
visit @edit_draft_version_url
|
||||
expect(page).not_to have_link "Español"
|
||||
end
|
||||
|
||||
scenario 'Add translation through markup editor', :js do
|
||||
visit @edit_draft_version_url
|
||||
visit edit_path
|
||||
|
||||
select "Français", from: "translation_locale"
|
||||
|
||||
@@ -184,57 +130,12 @@ feature 'Admin legislation draft versions' do
|
||||
click_link 'Close text editor'
|
||||
click_button "Save changes"
|
||||
|
||||
visit @edit_draft_version_url
|
||||
visit edit_path
|
||||
|
||||
click_link "Français"
|
||||
click_link 'Launch text editor'
|
||||
|
||||
expect(page).to have_field('legislation_draft_version_body_fr', with: 'Texte en Français')
|
||||
end
|
||||
|
||||
context "Globalize javascript interface" do
|
||||
|
||||
scenario "Highlight current locale", :js do
|
||||
visit @edit_draft_version_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_draft_version_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_draft_version_url
|
||||
|
||||
expect(page).to have_field('legislation_draft_version_title_en', with: 'Title in English')
|
||||
|
||||
click_link "Español"
|
||||
|
||||
expect(page).to have_field('legislation_draft_version_title_es', with: 'Título en Español')
|
||||
end
|
||||
|
||||
scenario "Select a locale and add it to the draft_version form", :js do
|
||||
visit @edit_draft_version_url
|
||||
|
||||
select "Français", from: "translation_locale"
|
||||
|
||||
expect(page).to have_link "Français"
|
||||
|
||||
click_link "Français"
|
||||
|
||||
expect(page).to have_field('legislation_draft_version_title_fr')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -84,7 +84,7 @@ shared_examples "translatable" do |factory_name, path_name, fields|
|
||||
expect(page).not_to have_link "Español"
|
||||
end
|
||||
|
||||
scenario 'Change value of a translated field to blank' do
|
||||
scenario 'Change value of a translated field to blank', :js do
|
||||
possible_blanks = fields.select do |field|
|
||||
translatable.dup.tap { |duplicate| duplicate.send(:"#{field}=", '') }.valid?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user