Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because between tests we now rollback transactions instead of truncating the database.
This commit is contained in:
100
spec/system/admin/legislation/draft_versions_spec.rb
Normal file
100
spec/system/admin/legislation/draft_versions_spec.rb
Normal file
@@ -0,0 +1,100 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Admin legislation draft versions" do
|
||||
before do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
end
|
||||
|
||||
context "Feature flag" do
|
||||
scenario "Disabled with a feature flag" do
|
||||
Setting["process.legislation"] = nil
|
||||
process = create(:legislation_process)
|
||||
expect { visit admin_legislation_process_draft_versions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||
end
|
||||
end
|
||||
|
||||
context "Index" do
|
||||
scenario "Displaying legislation process draft versions" do
|
||||
process = create(:legislation_process, title: "An example legislation process")
|
||||
draft_version = create(:legislation_draft_version, process: process, title: "Version 1")
|
||||
|
||||
visit admin_legislation_processes_path(filter: "all")
|
||||
|
||||
click_link "An example legislation process"
|
||||
click_link "Drafting"
|
||||
click_link "Version 1"
|
||||
|
||||
expect(page).to have_content(draft_version.title)
|
||||
expect(page).to have_content(draft_version.changelog)
|
||||
end
|
||||
end
|
||||
|
||||
context "Create" do
|
||||
scenario "Valid legislation draft version" do
|
||||
create(:legislation_process, title: "An example legislation process")
|
||||
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "All"
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
|
||||
click_link "An example legislation process"
|
||||
click_link "Drafting"
|
||||
|
||||
click_link "Create version"
|
||||
|
||||
fill_in "Version title", with: "Version 3"
|
||||
fill_in "Changes", with: "Version 3 changes"
|
||||
fill_in "Text", with: "Version 3 body"
|
||||
|
||||
within("form .end") do
|
||||
click_button "Create version"
|
||||
end
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
expect(page).to have_content "Version 3"
|
||||
end
|
||||
end
|
||||
|
||||
context "Update" do
|
||||
scenario "Valid legislation draft version", :js do
|
||||
process = create(:legislation_process, title: "An example legislation process")
|
||||
create(:legislation_draft_version, title: "Version 1", process: process)
|
||||
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "All"
|
||||
|
||||
expect(page).not_to have_link "All"
|
||||
|
||||
click_link "An example legislation process"
|
||||
click_link "Drafting"
|
||||
|
||||
click_link "Version 1"
|
||||
|
||||
fill_in "Version title", with: "Version 1b"
|
||||
|
||||
click_link "Launch text editor"
|
||||
|
||||
fill_in "Text", with: "# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote"
|
||||
|
||||
within(".fullscreen") do
|
||||
click_link "Close text editor"
|
||||
end
|
||||
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).to have_content "Version 1b"
|
||||
end
|
||||
end
|
||||
end
|
||||
300
spec/system/admin/legislation/processes_spec.rb
Normal file
300
spec/system/admin/legislation/processes_spec.rb
Normal file
@@ -0,0 +1,300 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Admin collaborative legislation" do
|
||||
before do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
end
|
||||
|
||||
it_behaves_like "admin_milestoneable",
|
||||
:legislation_process,
|
||||
"admin_legislation_process_milestones_path"
|
||||
|
||||
context "Feature flag" do
|
||||
scenario "Disabled with a feature flag" do
|
||||
Setting["process.legislation"] = nil
|
||||
expect { visit admin_legislation_processes_path }
|
||||
.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||
end
|
||||
end
|
||||
|
||||
context "Index" do
|
||||
scenario "Displaying collaborative legislation" do
|
||||
process_1 = create(:legislation_process, title: "Process open")
|
||||
process_2 = create(:legislation_process, title: "Process for the future",
|
||||
start_date: Date.current + 5.days)
|
||||
process_3 = create(:legislation_process, title: "Process closed",
|
||||
start_date: Date.current - 10.days,
|
||||
end_date: Date.current - 6.days)
|
||||
|
||||
visit admin_legislation_processes_path(filter: "active")
|
||||
|
||||
expect(page).to have_content(process_1.title)
|
||||
expect(page).to have_content(process_2.title)
|
||||
expect(page).not_to have_content(process_3.title)
|
||||
|
||||
visit admin_legislation_processes_path(filter: "all")
|
||||
|
||||
expect(page).to have_content(process_1.title)
|
||||
expect(page).to have_content(process_2.title)
|
||||
expect(page).to have_content(process_3.title)
|
||||
end
|
||||
|
||||
scenario "Processes are sorted by descending start date" do
|
||||
process_1 = create(:legislation_process, title: "Process 1", start_date: Date.yesterday)
|
||||
process_2 = create(:legislation_process, title: "Process 2", start_date: Date.current)
|
||||
process_3 = create(:legislation_process, title: "Process 3", start_date: Date.tomorrow)
|
||||
|
||||
visit admin_legislation_processes_path(filter: "all")
|
||||
|
||||
expect(page).to have_content process_1.start_date
|
||||
expect(page).to have_content process_2.start_date
|
||||
expect(page).to have_content process_3.start_date
|
||||
|
||||
expect(page).to have_content process_1.end_date
|
||||
expect(page).to have_content process_2.end_date
|
||||
expect(page).to have_content process_3.end_date
|
||||
|
||||
expect(process_3.title).to appear_before(process_2.title)
|
||||
expect(process_2.title).to appear_before(process_1.title)
|
||||
end
|
||||
end
|
||||
|
||||
context "Create" do
|
||||
scenario "Valid legislation process" do
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
expect(page).not_to have_content "An example legislation process"
|
||||
|
||||
click_link "New process"
|
||||
|
||||
fill_in "Process Title", with: "An example legislation process"
|
||||
fill_in "Summary", with: "Summary of the process"
|
||||
fill_in "Description", with: "Describing the process"
|
||||
|
||||
base_date = Date.current
|
||||
fill_in "legislation_process[start_date]", with: base_date.strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[end_date]", with: (base_date + 5.days).strftime("%d/%m/%Y")
|
||||
|
||||
fill_in "legislation_process[debate_start_date]",
|
||||
with: base_date.strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[debate_end_date]",
|
||||
with: (base_date + 2.days).strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[draft_start_date]",
|
||||
with: (base_date - 3.days).strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[draft_end_date]",
|
||||
with: (base_date - 1.day).strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[draft_publication_date]",
|
||||
with: (base_date + 3.days).strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[allegations_start_date]",
|
||||
with: (base_date + 3.days).strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[allegations_end_date]",
|
||||
with: (base_date + 5.days).strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[result_publication_date]",
|
||||
with: (base_date + 7.days).strftime("%d/%m/%Y")
|
||||
|
||||
click_button "Create process"
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
expect(page).to have_content "Process created successfully"
|
||||
|
||||
click_link "Click to visit"
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
expect(page).not_to have_content "Summary of the process"
|
||||
expect(page).to have_content "Describing the process"
|
||||
|
||||
visit legislation_processes_path
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
expect(page).to have_content "Summary of the process"
|
||||
expect(page).not_to have_content "Describing the process"
|
||||
end
|
||||
|
||||
scenario "Legislation process in draft phase" do
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
expect(page).not_to have_content "An example legislation process"
|
||||
|
||||
click_link "New process"
|
||||
|
||||
fill_in "Process Title", with: "An example legislation process in draft phase"
|
||||
fill_in "Summary", with: "Summary of the process"
|
||||
fill_in "Description", with: "Describing the process"
|
||||
|
||||
base_date = Date.current - 2.days
|
||||
fill_in "legislation_process[start_date]", with: base_date.strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[end_date]", with: (base_date + 5.days).strftime("%d/%m/%Y")
|
||||
|
||||
fill_in "legislation_process[draft_start_date]", with: base_date.strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[draft_end_date]", with: (base_date + 3.days).strftime("%d/%m/%Y")
|
||||
check "legislation_process[draft_phase_enabled]"
|
||||
|
||||
click_button "Create process"
|
||||
|
||||
expect(page).to have_content "An example legislation process in draft phase"
|
||||
expect(page).to have_content "Process created successfully"
|
||||
|
||||
click_link "Click to visit"
|
||||
|
||||
expect(page).to have_content "An example legislation process in draft phase"
|
||||
expect(page).not_to have_content "Summary of the process"
|
||||
expect(page).to have_content "Describing the process"
|
||||
|
||||
visit legislation_processes_path
|
||||
|
||||
expect(page).not_to have_content "An example legislation process in draft phase"
|
||||
expect(page).not_to have_content "Summary of the process"
|
||||
expect(page).not_to have_content "Describing the process"
|
||||
end
|
||||
|
||||
scenario "Create a legislation process with an image", :js do
|
||||
visit new_admin_legislation_process_path
|
||||
fill_in "Process Title", with: "An example legislation process"
|
||||
fill_in "Summary", with: "Summary of the process"
|
||||
|
||||
base_date = Date.current
|
||||
fill_in "legislation_process[start_date]", with: base_date.strftime("%d/%m/%Y")
|
||||
fill_in "legislation_process[end_date]", with: (base_date + 5.days).strftime("%d/%m/%Y")
|
||||
imageable_attach_new_file(create(:image), Rails.root.join("spec/fixtures/files/clippy.jpg"))
|
||||
|
||||
click_button "Create process"
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
expect(page).to have_content "Process created successfully"
|
||||
|
||||
click_link "Click to visit"
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
expect(page).not_to have_content "Summary of the process"
|
||||
expect(page).to have_css("img[alt='#{Legislation::Process.last.title}']")
|
||||
end
|
||||
|
||||
scenario "Default colors are present" do
|
||||
visit new_admin_legislation_process_path
|
||||
|
||||
expect(find("#legislation_process_background_color").value).to eq "#e7f2fc"
|
||||
expect(find("#legislation_process_font_color").value).to eq "#222222"
|
||||
end
|
||||
end
|
||||
|
||||
context "Update" do
|
||||
let!(:process) do
|
||||
create(:legislation_process,
|
||||
title: "An example legislation process",
|
||||
summary: "Summarizing the process",
|
||||
description: "Description of the process")
|
||||
end
|
||||
|
||||
scenario "Remove summary text" do
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "An example legislation process"
|
||||
|
||||
expect(page).to have_selector("h2", text: "An example legislation process")
|
||||
expect(find("#legislation_process_debate_phase_enabled")).to be_checked
|
||||
expect(find("#legislation_process_published")).to be_checked
|
||||
|
||||
fill_in "Summary", with: ""
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).to have_content "Process updated successfully"
|
||||
|
||||
visit legislation_processes_path
|
||||
expect(page).not_to have_content "Summarizing the process"
|
||||
expect(page).to have_content "Description of the process"
|
||||
end
|
||||
|
||||
scenario "Deactivate draft publication" do
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "An example legislation process"
|
||||
|
||||
expect(find("#legislation_process_draft_publication_enabled")).to be_checked
|
||||
|
||||
uncheck "legislation_process_draft_publication_enabled"
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).to have_content "Process updated successfully"
|
||||
expect(find("#debate_start_date").value).not_to be_blank
|
||||
expect(find("#debate_end_date").value).not_to be_blank
|
||||
|
||||
click_link "Click to visit"
|
||||
|
||||
expect(page).not_to have_content "Draft publication"
|
||||
end
|
||||
|
||||
scenario "Change proposal categories" do
|
||||
visit edit_admin_legislation_process_path(process)
|
||||
within(".admin-content") { click_link "Proposals" }
|
||||
|
||||
fill_in "Categories", with: "recycling,bicycles,pollution"
|
||||
click_button "Save changes"
|
||||
|
||||
visit admin_legislation_process_proposals_path(process)
|
||||
|
||||
expect(page).to have_field("Categories", with: "bicycles, pollution, recycling")
|
||||
|
||||
within(".admin-content") { click_link "Information" }
|
||||
fill_in "Summary", with: "Summarizing the process"
|
||||
click_button "Save changes"
|
||||
|
||||
visit admin_legislation_process_proposals_path(process)
|
||||
|
||||
expect(page).to have_field("Categories", with: "bicycles, pollution, recycling")
|
||||
end
|
||||
|
||||
scenario "Edit milestones summary", :js do
|
||||
visit admin_legislation_process_milestones_path(process)
|
||||
|
||||
expect(page).not_to have_link "Remove language"
|
||||
expect(page).not_to have_field "translation_locale"
|
||||
|
||||
fill_in_ckeditor "Summary", with: "There is still a long journey ahead of us"
|
||||
|
||||
click_button "Update Process"
|
||||
|
||||
expect(page).to have_current_path admin_legislation_process_milestones_path(process)
|
||||
|
||||
visit milestones_legislation_process_path(process)
|
||||
|
||||
expect(page).to have_content "There is still a long journey ahead of us"
|
||||
end
|
||||
end
|
||||
|
||||
context "Special interface translation behaviour" do
|
||||
let!(:process) { create(:legislation_process) }
|
||||
|
||||
before { Setting["feature.translation_interface"] = true }
|
||||
|
||||
scenario "Cant manage translations on homepage form" do
|
||||
visit edit_admin_legislation_process_homepage_path(process)
|
||||
|
||||
expect(page).not_to have_css "#add_language"
|
||||
expect(page).not_to have_link "Remove language"
|
||||
end
|
||||
|
||||
scenario "Cant manage translations on milestones summary form" do
|
||||
visit admin_legislation_process_milestones_path(process)
|
||||
|
||||
expect(page).not_to have_css "#add_language"
|
||||
expect(page).not_to have_link "Remove language"
|
||||
end
|
||||
end
|
||||
end
|
||||
82
spec/system/admin/legislation/proposals_spec.rb
Normal file
82
spec/system/admin/legislation/proposals_spec.rb
Normal file
@@ -0,0 +1,82 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Admin collaborative legislation" do
|
||||
before do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
end
|
||||
|
||||
context "Index" do
|
||||
scenario "Displaying legislation proposals" do
|
||||
proposal = create(:legislation_proposal, cached_votes_score: 10)
|
||||
|
||||
visit admin_legislation_process_proposals_path(proposal.legislation_process_id)
|
||||
|
||||
within "#legislation_proposal_#{proposal.id}" do
|
||||
expect(page).to have_content(proposal.title)
|
||||
expect(page).to have_content(proposal.id)
|
||||
expect(page).to have_content(proposal.cached_votes_score)
|
||||
expect(page).to have_content("Select")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Selecting legislation proposals", :js do
|
||||
proposal = create(:legislation_proposal, cached_votes_score: 10)
|
||||
|
||||
visit admin_legislation_process_proposals_path(proposal.legislation_process_id)
|
||||
click_link "Select"
|
||||
|
||||
within "#legislation_proposal_#{proposal.id}" do
|
||||
expect(page).to have_content("Selected")
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Sorting legislation proposals by title", js: true do
|
||||
process = create(:legislation_process)
|
||||
create(:legislation_proposal, title: "bbbb", legislation_process_id: process.id)
|
||||
create(:legislation_proposal, title: "aaaa", legislation_process_id: process.id)
|
||||
create(:legislation_proposal, title: "cccc", legislation_process_id: process.id)
|
||||
|
||||
visit admin_legislation_process_proposals_path(process.id)
|
||||
select "Title", from: "order-selector-participation"
|
||||
|
||||
within("#legislation_proposals_list") do
|
||||
within all(".legislation_proposal")[0] { expect(page).to have_content("aaaa") }
|
||||
within all(".legislation_proposal")[1] { expect(page).to have_content("bbbb") }
|
||||
within all(".legislation_proposal")[2] { expect(page).to have_content("cccc") }
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Sorting legislation proposals by supports", js: true do
|
||||
process = create(:legislation_process)
|
||||
create(:legislation_proposal, cached_votes_score: 10, legislation_process_id: process.id)
|
||||
create(:legislation_proposal, cached_votes_score: 30, legislation_process_id: process.id)
|
||||
create(:legislation_proposal, cached_votes_score: 20, legislation_process_id: process.id)
|
||||
|
||||
visit admin_legislation_process_proposals_path(process.id)
|
||||
select "Total supports", from: "order-selector-participation"
|
||||
|
||||
within("#legislation_proposals_list") do
|
||||
within all(".legislation_proposal")[0] { expect(page).to have_content("30") }
|
||||
within all(".legislation_proposal")[1] { expect(page).to have_content("20") }
|
||||
within all(".legislation_proposal")[2] { expect(page).to have_content("10") }
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Sorting legislation proposals by Id", js: true do
|
||||
process = create(:legislation_process)
|
||||
proposal1 = create(:legislation_proposal, title: "bbbb", legislation_process_id: process.id)
|
||||
proposal2 = create(:legislation_proposal, title: "aaaa", legislation_process_id: process.id)
|
||||
proposal3 = create(:legislation_proposal, title: "cccc", legislation_process_id: process.id)
|
||||
|
||||
visit admin_legislation_process_proposals_path(process.id, order: :title)
|
||||
select "Id", from: "order-selector-participation"
|
||||
|
||||
within("#legislation_proposals_list") do
|
||||
within all(".legislation_proposal")[0] { expect(page).to have_content(proposal1.id) }
|
||||
within all(".legislation_proposal")[1] { expect(page).to have_content(proposal2.id) }
|
||||
within all(".legislation_proposal")[2] { expect(page).to have_content(proposal3.id) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
206
spec/system/admin/legislation/questions_spec.rb
Normal file
206
spec/system/admin/legislation/questions_spec.rb
Normal file
@@ -0,0 +1,206 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Admin legislation questions" do
|
||||
before do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
end
|
||||
|
||||
let!(:process) { create(:legislation_process, title: "An example legislation process") }
|
||||
|
||||
context "Feature flag" do
|
||||
before do
|
||||
Setting["process.legislation"] = nil
|
||||
end
|
||||
|
||||
scenario "Disabled with a feature flag" do
|
||||
expect { visit admin_legislation_process_questions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||
end
|
||||
end
|
||||
|
||||
context "Index" do
|
||||
scenario "Displaying legislation process questions" do
|
||||
create(:legislation_question, process: process, title: "Question 1")
|
||||
create(:legislation_question, process: process, title: "Question 2")
|
||||
|
||||
visit admin_legislation_processes_path(filter: "all")
|
||||
|
||||
click_link "An example legislation process"
|
||||
click_link "Debate"
|
||||
|
||||
expect(page).to have_content("Question 1")
|
||||
expect(page).to have_content("Question 2")
|
||||
end
|
||||
end
|
||||
|
||||
context "Create" do
|
||||
scenario "Valid legislation question" do
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "All"
|
||||
|
||||
expect(page).to have_content "An example legislation process"
|
||||
|
||||
click_link "An example legislation process"
|
||||
click_link "Debate"
|
||||
|
||||
click_link "Create question"
|
||||
|
||||
fill_in "Question", with: "Question 3"
|
||||
click_button "Create question"
|
||||
|
||||
expect(page).to have_content "Question 3"
|
||||
end
|
||||
end
|
||||
|
||||
context "Update" do
|
||||
scenario "Valid legislation question", :js do
|
||||
create(:legislation_question, title: "Question 2", process: process)
|
||||
|
||||
visit admin_root_path
|
||||
|
||||
within("#side_menu") do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "All"
|
||||
|
||||
expect(page).not_to have_link "All"
|
||||
|
||||
click_link "An example legislation process"
|
||||
click_link "Debate"
|
||||
|
||||
click_link "Question 2"
|
||||
|
||||
fill_in "Question", with: "Question 2b"
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).to have_content "Question 2b"
|
||||
end
|
||||
end
|
||||
|
||||
context "Delete" do
|
||||
scenario "Legislation question", :js do
|
||||
create(:legislation_question, title: "Question 1", process: process)
|
||||
question = create(:legislation_question, title: "Question 2", process: process)
|
||||
question_option = create(:legislation_question_option, question: question, value: "Yes")
|
||||
create(:legislation_answer, question: question, question_option: question_option)
|
||||
|
||||
visit edit_admin_legislation_process_question_path(process, question)
|
||||
|
||||
click_link "Delete"
|
||||
|
||||
expect(page).to have_content "Questions"
|
||||
expect(page).to have_content "Question 1"
|
||||
expect(page).not_to have_content "Question 2"
|
||||
end
|
||||
end
|
||||
|
||||
context "Legislation options" do
|
||||
let!(:question) { create(:legislation_question) }
|
||||
|
||||
let(:edit_question_url) do
|
||||
edit_admin_legislation_process_question_path(question.process, question)
|
||||
end
|
||||
|
||||
let(:field_en) { fields_for(:en).first }
|
||||
let(:field_es) { fields_for(:es).first }
|
||||
|
||||
def fields_for(locale)
|
||||
within("#nested_question_options") do
|
||||
page.all(
|
||||
"[data-locale='#{locale}'] [id^='legislation_question_question_option'][id$='value']"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Edit an existing option", :js do
|
||||
create(:legislation_question_option, question: question, value: "Original")
|
||||
|
||||
visit edit_question_url
|
||||
find("#nested_question_options input").set("Changed")
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).not_to have_css "#error_explanation"
|
||||
|
||||
visit edit_question_url
|
||||
expect(page).to have_field(field_en[:id], with: "Changed")
|
||||
end
|
||||
|
||||
scenario "Remove an option", :js do
|
||||
create(:legislation_question_option, question: question, value: "Yes")
|
||||
create(:legislation_question_option, question: question, value: "No")
|
||||
|
||||
visit edit_question_url
|
||||
|
||||
expect(page).to have_field fields_for(:en).first[:id], with: "Yes"
|
||||
expect(page).to have_field fields_for(:en).last[:id], with: "No"
|
||||
|
||||
page.first(:link, "Remove option").click
|
||||
|
||||
expect(page).not_to have_field fields_for(:en).first[:id], with: "Yes"
|
||||
expect(page).to have_field fields_for(:en).last[:id], with: "No"
|
||||
|
||||
click_button "Save changes"
|
||||
visit edit_question_url
|
||||
|
||||
expect(page).not_to have_field fields_for(:en).first[:id], with: "Yes"
|
||||
expect(page).to have_field fields_for(:en).last[:id], with: "No"
|
||||
end
|
||||
|
||||
context "Special translation behaviour" do
|
||||
before do
|
||||
question.update!(title_en: "Title in English", title_es: "Título en Español")
|
||||
end
|
||||
|
||||
scenario "Add translation for question option", :js do
|
||||
visit edit_question_url
|
||||
|
||||
click_on "Add option"
|
||||
|
||||
find("#nested_question_options input").set("Option 1")
|
||||
|
||||
select "Español", from: :select_language
|
||||
|
||||
find("#nested_question_options input").set("Opción 1")
|
||||
|
||||
click_button "Save changes"
|
||||
visit edit_question_url
|
||||
|
||||
expect(page).to have_field(field_en[:id], with: "Option 1")
|
||||
|
||||
select "Español", from: :select_language
|
||||
|
||||
expect(page).to have_field(field_es[:id], with: "Opción 1")
|
||||
end
|
||||
|
||||
scenario "Add new question option after changing active locale", :js do
|
||||
visit edit_question_url
|
||||
|
||||
select "Español", from: :select_language
|
||||
|
||||
click_on "Add option"
|
||||
|
||||
find("#nested_question_options input").set("Opción 1")
|
||||
|
||||
select "English", from: :select_language
|
||||
|
||||
find("#nested_question_options input").set("Option 1")
|
||||
|
||||
click_button "Save changes"
|
||||
|
||||
visit edit_question_url
|
||||
|
||||
expect(page).to have_field(field_en[:id], with: "Option 1")
|
||||
|
||||
select "Español", from: :select_language
|
||||
|
||||
expect(page).to have_field(field_es[:id], with: "Opción 1")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user