Skip to content

Commit

Permalink
Use JavaScripts in tests using CKEditor
Browse files Browse the repository at this point in the history
We were filling in textareas, so we were only testing how the
application behaves for about 1%-2% of our users.
  • Loading branch information
javierm committed Apr 7, 2021
1 parent b2bc4d1 commit 287c488
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 74 deletions.
2 changes: 1 addition & 1 deletion spec/support/common_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate_officer
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"
Expand Down
2 changes: 1 addition & 1 deletion spec/support/common_actions/emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def fill_in_newsletter_form(options = {})
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] || "[email protected]")
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
4 changes: 2 additions & 2 deletions spec/system/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,15 @@
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")

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
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"
Expand Down
4 changes: 2 additions & 2 deletions spec/system/admin/dashboard/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
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"

Expand Down
6 changes: 3 additions & 3 deletions spec/system/admin/emails/newsletters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
end
end

scenario "Create" do
scenario "Create", :js do
visit admin_newsletters_path
click_link "New newsletter"

Expand All @@ -76,7 +76,7 @@
expect(page).to have_content "This is a body"
end

scenario "Update" do
scenario "Update", :js do
newsletter = create(:newsletter)

visit admin_newsletters_path
Expand Down Expand Up @@ -161,7 +161,7 @@
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

Expand Down
8 changes: 4 additions & 4 deletions spec/system/admin/poll/questions/answers/answers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
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"

expect(page).to have_content "The answer is always 42"
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)

visit admin_question_path(question)
click_link "Add answer"

fill_in "Answer", with: "Second"
fill_in "Description", with: "Description"
fill_in_ckeditor "Description", with: "Description"

click_button "Save"

Expand Down
5 changes: 3 additions & 2 deletions spec/system/admin/site_customization/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
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

Expand All @@ -44,7 +45,7 @@
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"

Expand Down
8 changes: 4 additions & 4 deletions spec/system/budgets/investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ def investments_order
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)
visit new_budget_investment_path(budget)

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"
Expand All @@ -535,14 +535,14 @@ def investments_order
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"
Expand Down
16 changes: 8 additions & 8 deletions spec/system/debates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@
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"
Expand Down Expand Up @@ -236,15 +236,15 @@
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)
login_as(author)

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"
Expand Down Expand Up @@ -281,13 +281,13 @@
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"
Expand Down Expand Up @@ -347,15 +347,15 @@
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)

visit edit_debate_path(debate)
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"

Expand Down
8 changes: 4 additions & 4 deletions spec/system/emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@
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"
Expand Down Expand Up @@ -464,7 +464,7 @@
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)
Expand All @@ -476,7 +476,7 @@

expect(page).to have_content "Newsletter created successfully"

click_link "Send"
accept_confirm { click_link "Send" }

expect(page).to have_content "Newsletter sent successfully"

Expand Down
4 changes: 2 additions & 2 deletions spec/system/management/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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)
Expand All @@ -52,7 +52,7 @@

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"
Expand Down
4 changes: 2 additions & 2 deletions spec/system/management/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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)

Expand All @@ -21,7 +21,7 @@

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"

Expand Down

0 comments on commit 287c488

Please sign in to comment.