Use JavaScripts in tests using CKEditor

We were filling in textareas, so we were only testing how the
application behaves for about 1%-2% of our users.
This commit is contained in:
Javi Martín
2021-03-29 13:49:09 +02:00
parent b2bc4d19f5
commit 287c488734
17 changed files with 75 additions and 74 deletions

View File

@@ -35,7 +35,7 @@ module CommonActions
def fill_in_proposal
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yPQfcG-eimk"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
check "proposal_terms_of_service"

View File

@@ -21,6 +21,6 @@ module Emails
fill_in "Subject", with: (options[:subject] || "This is a different subject")
fill_in "E-mail address that will appear as sending the newsletter",
with: (options[:from] || "no-reply@consul.dev")
fill_in "Email content", with: (options[:body] || "This is a different body")
fill_in_ckeditor "Email content", with: (options[:body] || "This is a different body")
end
end

View File

@@ -1034,7 +1034,7 @@ describe "Admin budget investments", :admin do
end
context "Edit" do
scenario "Change title, incompatible, description or heading" do
scenario "Change title, incompatible, description or heading", :js do
budget_investment = create(:budget_investment, :incompatible)
create(:budget_heading, group: budget_investment.group, name: "Barbate")
@@ -1042,7 +1042,7 @@ describe "Admin budget investments", :admin do
click_link "Edit"
fill_in "Title", with: "Potatoes"
fill_in "Description", with: "Carrots"
fill_in_ckeditor "Description", with: "Carrots"
select "#{budget_investment.group.name}: Barbate", from: "budget_investment[heading_id]"
uncheck "budget_investment_incompatible"
check "budget_investment_selected"

View File

@@ -46,9 +46,9 @@ describe "Admin dashboard actions", :admin do
click_link "Create resource or action"
end
scenario "Creates a new action" do
scenario "Creates a new action", :js do
fill_in "Title", with: action.title
fill_in "Description", with: action.description
fill_in_ckeditor "Description", with: action.description
click_button "Save"

View File

@@ -58,7 +58,7 @@ describe "Admin newsletter emails", :admin do
end
end
scenario "Create" do
scenario "Create", :js do
visit admin_newsletters_path
click_link "New newsletter"
@@ -76,7 +76,7 @@ describe "Admin newsletter emails", :admin do
expect(page).to have_content "This is a body"
end
scenario "Update" do
scenario "Update", :js do
newsletter = create(:newsletter)
visit admin_newsletters_path
@@ -161,7 +161,7 @@ describe "Admin newsletter emails", :admin do
end
end
scenario "Select list of users to send newsletter" do
scenario "Select list of users to send newsletter", :js do
UserSegments::SEGMENTS.each do |user_segment|
visit new_admin_newsletter_path

View File

@@ -1,14 +1,14 @@
require "rails_helper"
describe "Answers", :admin do
scenario "Create" do
scenario "Create", :js do
question = create(:poll_question)
visit admin_question_path(question)
click_link "Add answer"
fill_in "Answer", with: "The answer is always 42"
fill_in "Description", with: "The Hitchhiker's Guide To The Universe"
fill_in_ckeditor "Description", with: "The Hitchhiker's Guide To The Universe"
click_button "Save"
@@ -16,7 +16,7 @@ describe "Answers", :admin do
expect(page).to have_content "The Hitchhiker's Guide To The Universe"
end
scenario "Create second answer and place after the first one" do
scenario "Create second answer and place after the first one", :js do
question = create(:poll_question)
create(:poll_question_answer, title: "First", question: question, given_order: 1)
@@ -24,7 +24,7 @@ describe "Answers", :admin do
click_link "Add answer"
fill_in "Answer", with: "Second"
fill_in "Description", with: "Description"
fill_in_ckeditor "Description", with: "Description"
click_button "Save"

View File

@@ -29,10 +29,11 @@ describe "Admin custom pages", :admin do
end
context "Create" do
scenario "Valid custom page" do
scenario "Valid custom page", :js do
visit admin_root_path
within("#side_menu") do
click_link "Site content"
click_link "Custom pages"
end
@@ -44,7 +45,7 @@ describe "Admin custom pages", :admin do
fill_in "Title", with: "An example custom page"
fill_in "Subtitle", with: "Page subtitle"
fill_in "site_customization_page_slug", with: "example-page"
fill_in "Content", with: "This page is about..."
fill_in_ckeditor "Content", with: "This page is about..."
click_button "Create Custom page"

View File

@@ -518,7 +518,7 @@ describe "Budget Investments" do
expect(page).to have_current_path(budget_investments_path(budget))
end
scenario "Create budget investment too fast" do
scenario "Create budget investment too fast", :js do
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
login_as(author)
@@ -526,7 +526,7 @@ describe "Budget Investments" do
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "I am a bot"
fill_in "Description", with: "This is the description"
fill_in_ckeditor "Description", with: "This is the description"
check "budget_investment_terms_of_service"
click_button "Create Investment"
@@ -535,14 +535,14 @@ describe "Budget Investments" do
expect(page).to have_current_path(new_budget_investment_path(budget))
end
scenario "Create" do
scenario "Create", :js do
login_as(author)
visit new_budget_investment_path(budget)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper"
fill_in "Description", with: "I want to live in a high tower over the clouds"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
fill_in "budget_investment_location", with: "City center"
fill_in "budget_investment_organization_name", with: "T.I.A."
fill_in "budget_investment_tag_list", with: "Towers"

View File

@@ -201,13 +201,13 @@ describe "Debates" do
expect(page).to have_content("-6 votes")
end
scenario "Create" do
scenario "Create", :js do
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "A title for a debate"
fill_in "Initial debate text", with: "This is very important because..."
fill_in_ckeditor "Initial debate text", with: "This is very important because..."
check "debate_terms_of_service"
click_button "Start a debate"
@@ -236,7 +236,7 @@ describe "Debates" do
expect(page).to have_current_path(debates_path)
end
scenario "Create debate too fast" do
scenario "Create debate too fast", :js do
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
author = create(:user)
@@ -244,7 +244,7 @@ describe "Debates" do
visit new_debate_path
fill_in "Debate title", with: "I am a bot"
fill_in "Initial debate text", with: "This is the description"
fill_in_ckeditor "Initial debate text", with: "This is the description"
check "debate_terms_of_service"
click_button "Start a debate"
@@ -281,13 +281,13 @@ describe "Debates" do
expect(page.html).not_to include "<p>This is"
end
scenario "Autolinking is applied to description" do
scenario "Autolinking is applied to description", :js do
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "Testing auto link"
fill_in "Initial debate text", with: "<p>This is a link www.example.org</p>"
fill_in_ckeditor "Initial debate text", with: "This is a link www.example.org"
check "debate_terms_of_service"
click_button "Start a debate"
@@ -347,7 +347,7 @@ describe "Debates" do
expect(page).to have_content "You do not have permission to"
end
scenario "Update should be posible for the author of an editable debate" do
scenario "Update should be posible for the author of an editable debate", :js do
debate = create(:debate)
login_as(debate.author)
@@ -355,7 +355,7 @@ describe "Debates" do
expect(page).to have_current_path(edit_debate_path(debate))
fill_in "Debate title", with: "End child poverty"
fill_in "Initial debate text", with: "Let's do something to end child poverty"
fill_in_ckeditor "Initial debate text", with: "Let's do something to end child poverty"
click_button "Save changes"

View File

@@ -342,13 +342,13 @@ describe "Emails" do
let(:budget) { create(:budget) }
let!(:heading) { create(:budget_heading, name: "More hospitals", budget: budget) }
scenario "Investment created" do
scenario "Investment created", :js do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a hospital"
fill_in "Description", with: "We have lots of people that require medical attention"
fill_in_ckeditor "Description", with: "We have lots of people that require medical attention"
check "budget_investment_terms_of_service"
click_button "Create Investment"
@@ -464,7 +464,7 @@ describe "Emails" do
end
context "Newsletter", :admin do
scenario "Send newsletter email to selected users" do
scenario "Send newsletter email to selected users", :js do
user_with_newsletter_in_segment_1 = create(:user, :with_proposal, newsletter: true)
user_with_newsletter_in_segment_2 = create(:user, :with_proposal, newsletter: true)
user_with_newsletter_not_in_segment = create(:user, newsletter: true)
@@ -476,7 +476,7 @@ describe "Emails" do
expect(page).to have_content "Newsletter created successfully"
click_link "Send"
accept_confirm { click_link "Send" }
expect(page).to have_content "Newsletter sent successfully"

View File

@@ -33,7 +33,7 @@ describe "Budget Investments" do
context "Create" do
before { heading.budget.update(phase: "accepting") }
scenario "Creating budget investments on behalf of someone, selecting a budget" do
scenario "Creating budget investments on behalf of someone, selecting a budget", :js do
user = create(:user, :level_two)
login_managed_user(user)
@@ -52,7 +52,7 @@ describe "Budget Investments" do
select "Health", from: "budget_investment_heading_id"
fill_in "Title", with: "Build a park in my neighborhood"
fill_in "Description", with: "There is no parks here..."
fill_in_ckeditor "Description", with: "There is no parks here..."
fill_in "budget_investment_location", with: "City center"
fill_in "budget_investment_organization_name", with: "T.I.A."
fill_in "budget_investment_tag_list", with: "green"

View File

@@ -6,7 +6,7 @@ describe "Proposals" do
end
context "Create" do
scenario "Creating proposals on behalf of someone" do
scenario "Creating proposals on behalf of someone", :js do
user = create(:user, :level_two)
login_managed_user(user)
@@ -21,7 +21,7 @@ describe "Proposals" do
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yRYFKcMa_Ek"
check "proposal_terms_of_service"

View File

@@ -357,7 +357,7 @@ describe "Proposals" do
expect(page).to have_css "meta[property='og:title'][content=\'#{proposal.title}\']", visible: :hidden
end
scenario "Create and publish" do
scenario "Create and publish", :js do
author = create(:user)
login_as(author)
@@ -365,7 +365,7 @@ describe "Proposals" do
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yPQfcG-eimk"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
fill_in "proposal_tag_list", with: "Refugees, Solidarity"
@@ -411,7 +411,7 @@ describe "Proposals" do
expect(page).to have_current_path(proposals_path)
end
scenario "Create proposal too fast" do
scenario "Create proposal too fast", :js do
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
author = create(:user)
@@ -420,7 +420,7 @@ describe "Proposals" do
visit new_proposal_path
fill_in "Proposal title", with: "I am a bot"
fill_in "Proposal summary", with: "This is the summary"
fill_in "Proposal text", with: "This is the description"
fill_in_ckeditor "Proposal text", with: "This is the description"
fill_in "proposal_responsible_name", with: "Some other robot"
check "proposal_terms_of_service"
@@ -431,14 +431,14 @@ describe "Proposals" do
expect(page).to have_current_path(new_proposal_path)
end
scenario "Responsible name is stored for anonymous users" do
scenario "Responsible name is stored for anonymous users", :js do
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_responsible_name", with: "Isabel Garcia"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
check "proposal_terms_of_service"
@@ -452,7 +452,7 @@ describe "Proposals" do
expect(Proposal.last.responsible_name).to eq("Isabel Garcia")
end
scenario "Responsible name field is not shown for verified users" do
scenario "Responsible name field is not shown for verified users", :js do
author = create(:user, :level_two)
login_as(author)
@@ -461,7 +461,7 @@ describe "Proposals" do
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
check "proposal_terms_of_service"
click_button "Create proposal"
@@ -505,14 +505,14 @@ describe "Proposals" do
expect(page.html).not_to include "&lt;p&gt;This is"
end
scenario "Autolinking is applied to description" do
scenario "Autolinking is applied to description", :js do
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in "Proposal title", with: "Testing auto link"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "<p>This is a link www.example.org</p>"
fill_in_ckeditor "Proposal text", with: "This is a link www.example.org"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
check "proposal_terms_of_service"
@@ -563,7 +563,7 @@ describe "Proposals" do
end
context "Geozones" do
scenario "Default whole city" do
scenario "Default whole city", :js do
author = create(:user)
login_as(author)
@@ -581,7 +581,7 @@ describe "Proposals" do
end
end
scenario "Specific geozone" do
scenario "Specific geozone", :js do
create(:geozone, name: "California")
create(:geozone, name: "New York")
login_as(create(:user))
@@ -590,7 +590,7 @@ describe "Proposals" do
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yPQfcG-eimk"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
check "proposal_terms_of_service"
@@ -749,7 +749,7 @@ describe "Proposals" do
Setting["max_votes_for_proposal_edit"] = 1000
end
scenario "Update should be posible for the author of an editable proposal" do
scenario "Update should be posible for the author of an editable proposal", :js do
proposal = create(:proposal)
login_as(proposal.author)
@@ -758,7 +758,7 @@ describe "Proposals" do
fill_in "Proposal title", with: "End child poverty"
fill_in "Proposal summary", with: "Basically..."
fill_in "Proposal text", with: "Let's do something to end child poverty"
fill_in_ckeditor "Proposal text", with: "Let's do something to end child poverty"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
click_button "Save changes"
@@ -1584,7 +1584,7 @@ describe "Successful proposals" do
Setting["feature.user.skip_verification"] = "true"
end
scenario "Create" do
scenario "Create", :js do
author = create(:user)
login_as(author)
@@ -1598,7 +1598,7 @@ describe "Successful proposals" do
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yPQfcG-eimk"
fill_in "proposal_tag_list", with: "Refugees, Solidarity"
check "proposal_terms_of_service"

View File

@@ -61,14 +61,14 @@ describe "Tags" do
expect(page).to have_content(tag_economia.name)
end
scenario "Create with custom tags" do
scenario "Create with custom tags", :js do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper"
fill_in "Description", with: "I want to live in a high tower over the clouds"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
check "budget_investment_terms_of_service"
fill_in "budget_investment_tag_list", with: "#{tag_medio_ambiente.name}, #{tag_economia.name}"
@@ -149,14 +149,14 @@ describe "Tags" do
end
end
scenario "Create with too many tags" do
scenario "Create with too many tags", :js do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper"
fill_in "Description", with: "I want to live in a high tower over the clouds"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
check "budget_investment_terms_of_service"
fill_in "budget_investment_tag_list", with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"
@@ -167,14 +167,14 @@ describe "Tags" do
expect(page).to have_content "tags must be less than or equal to 6"
end
scenario "Create with dangerous strings" do
scenario "Create with dangerous strings", :js do
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper"
fill_in "Description", with: "I want to live in a high tower over the clouds"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
check "budget_investment_terms_of_service"
fill_in "budget_investment_tag_list", with: "user_id=1, &a=3, <script>alert('hey');</script>"

View File

@@ -60,13 +60,13 @@ describe "Tags" do
expect(page).to have_content "Hacienda"
end
scenario "Create" do
scenario "Create", :js do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in "Debate title", with: "Title"
fill_in "Initial debate text", with: "Description"
fill_in_ckeditor "Initial debate text", with: "Description"
check "debate_terms_of_service"
fill_in "debate_tag_list", with: "Impuestos, Economía, Hacienda"
@@ -79,13 +79,13 @@ describe "Tags" do
expect(page).to have_content "Impuestos"
end
scenario "Create with too many tags" do
scenario "Create with too many tags", :js do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in "Debate title", with: "Title"
fill_in "Initial debate text", with: "Description"
fill_in_ckeditor "Initial debate text", with: "Description"
check "debate_terms_of_service"
fill_in "debate_tag_list", with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"
@@ -96,14 +96,14 @@ describe "Tags" do
expect(page).to have_content "tags must be less than or equal to 6"
end
scenario "Create with dangerous strings" do
scenario "Create with dangerous strings", :js do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in "Debate title", with: "A test of dangerous strings"
fill_in "Initial debate text", with: "A description suitable for this test"
fill_in_ckeditor "Initial debate text", with: "A description suitable for this test"
check "debate_terms_of_service"
fill_in "debate_tag_list", with: "user_id=1, &a=3, <script>alert('hey');</script>"

View File

@@ -59,14 +59,14 @@ describe "Tags" do
expect(page).to have_content "Hacienda"
end
scenario "Create with custom tags" do
scenario "Create with custom tags", :js do
user = create(:user)
login_as(user)
visit new_proposal_path
fill_in "Proposal title", with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "This is very important because..."
fill_in_ckeditor "Proposal text", with: "This is very important because..."
fill_in "proposal_responsible_name", with: "Isabel Garcia"
fill_in "proposal_tag_list", with: "Economía, Hacienda"
check "proposal_terms_of_service"
@@ -108,13 +108,13 @@ describe "Tags" do
end
end
scenario "Create with too many tags" do
scenario "Create with too many tags", :js do
user = create(:user)
login_as(user)
visit new_proposal_path
fill_in "Proposal title", with: "Title"
fill_in "Proposal text", with: "Description"
fill_in_ckeditor "Proposal text", with: "Description"
check "proposal_terms_of_service"
fill_in "proposal_tag_list", with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"
@@ -125,7 +125,7 @@ describe "Tags" do
expect(page).to have_content "tags must be less than or equal to 6"
end
scenario "Create with dangerous strings" do
scenario "Create with dangerous strings", :js do
author = create(:user)
login_as(author)
@@ -133,7 +133,7 @@ describe "Tags" do
fill_in "Proposal title", with: "A test of dangerous strings"
fill_in "Proposal summary", with: "In summary, what we want is..."
fill_in "Proposal text", with: "A description suitable for this test"
fill_in_ckeditor "Proposal text", with: "A description suitable for this test"
fill_in "proposal_responsible_name", with: "Isabel Garcia"
check "proposal_terms_of_service"

View File

@@ -53,13 +53,13 @@ describe "Tags" do
expect(page).to have_content "Hacienda"
end
scenario "Create" do
scenario "Create", :js do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in "Debate title", with: "Title"
fill_in "Initial debate text", with: "Description"
fill_in_ckeditor "Initial debate text", with: "Description"
check "debate_terms_of_service"
fill_in "debate_tag_list", with: "Impuestos, Economía, Hacienda"
@@ -72,13 +72,13 @@ describe "Tags" do
expect(page).to have_content "Impuestos"
end
scenario "Create with too many tags" do
scenario "Create with too many tags", :js do
user = create(:user)
login_as(user)
visit new_debate_path
fill_in "Debate title", with: "Title"
fill_in "Initial debate text", with: "Description"
fill_in_ckeditor "Initial debate text", with: "Description"
check "debate_terms_of_service"
fill_in "debate_tag_list", with: "Impuestos, Economía, Hacienda, Sanidad, Educación, Política, Igualdad"