Test data introduced from the user's point of view

Users don't care about database content; they care about what they see
on the screen.

Writing tests this way we also avoid potencial database inconsistencies
due to accessing the database after starting the browser.
This commit is contained in:
Javi Martín
2021-04-10 16:43:43 +02:00
parent 7b15cc290d
commit 405c6e6d14
9 changed files with 31 additions and 22 deletions

View File

@@ -186,7 +186,7 @@ describe "Admin collaborative legislation", :admin do
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}']")
expect(page).to have_css("img[alt='An example legislation process']")
end
scenario "Default colors are present" do

View File

@@ -2,16 +2,19 @@ require "rails_helper"
describe "Admin Active polls", :admin do
scenario "Add" do
expect(ActivePoll.first).to be nil
visit admin_polls_path
click_link "Polls description"
expect(page).to have_ckeditor "Description", with: ""
fill_in_ckeditor "Description", with: "Active polls description"
click_button "Save"
expect(page).to have_content "Polls description updated successfully."
expect(ActivePoll.first.description).to eq "<p>Active polls description</p>\r\n"
click_link "Polls description"
expect(page).to have_ckeditor "Description", with: "Active polls description"
end
scenario "Edit" do

View File

@@ -82,7 +82,10 @@ describe "Admin tags", :admin do
click_button "Create topic"
end
expect(Tag.category.where(name: "wow_category")).to exist
within "tbody" do
expect(page).to have_content "Existence"
expect(page).to have_content "wow_category"
end
end
end

View File

@@ -25,7 +25,7 @@ describe "Cards", :admin do
expect(page).to have_content "Card description"
expect(page).to have_content "Link text"
expect(page).to have_content "consul.dev"
expect(page).to have_link "Show image", href: Widget::Card.last.image_url(:large)
expect(page).to have_link "Show image", title: "clippy.jpg"
end
end
end

View File

@@ -359,13 +359,12 @@ describe "Emails" do
expect(page).to have_content "Investment created successfully"
email = open_last_email
investment = Budget::Investment.last
expect(email).to have_subject("Thank you for creating an investment!")
expect(email).to deliver_to(investment.author.email)
expect(email).to deliver_to(author.email)
expect(email).to have_body_text(author.name)
expect(email).to have_body_text(investment.title)
expect(email).to have_body_text(investment.budget.name)
expect(email).to have_body_text("Build a hospital")
expect(email).to have_body_text(budget.name)
expect(email).to have_body_text(budget_path(budget))
end
@@ -383,12 +382,11 @@ describe "Emails" do
click_button "Save changes"
expect(page).to have_content "Dossier updated"
investment.reload
email = open_last_email
expect(email).to have_subject("Your investment project '#{investment.code}' has been marked as unfeasible")
expect(email).to deliver_to(investment.author.email)
expect(email).to have_body_text(investment.unfeasibility_explanation)
expect(email).to have_body_text "This is not legal as stated in Article 34.9"
end
scenario "Selected investment" do

View File

@@ -152,7 +152,7 @@ describe "Legislation Proposals" do
expect(page).to have_content "Legislation proposal with image"
expect(page).to have_content "Including an image on a legislation proposal"
expect(page).to have_css("img[alt='#{Legislation::Proposal.last.image.title}']")
expect(page).to have_css "img[alt='clippy.jpg']"
end
scenario "Show votes score on index and show" do

View File

@@ -99,12 +99,11 @@ describe "Managed User" do
expect(page).to have_content "We have sent an email"
expect(page).not_to have_content "Autogenerated password is"
user = User.last
within(".account-info") do
expect(page).to have_content "Identified as"
expect(page).to have_content user.username.to_s
expect(page).to have_content user.email.to_s
expect(page).to have_content user.document_number.to_s
expect(page).to have_content "pepe"
expect(page).to have_content "pepe@gmail.com"
expect(page).to have_content "12345678Z"
end
end
@@ -127,11 +126,10 @@ describe "Managed User" do
expect(page).not_to have_content "We have sent an email"
expect(page).to have_content "Autogenerated password is"
user = User.last
within(".account-info") do
expect(page).to have_content "Identified as"
expect(page).to have_content user.username.to_s
expect(page).to have_content user.document_number.to_s
expect(page).to have_content "peppa"
expect(page).to have_content "12345678Z"
end
end
end

View File

@@ -446,7 +446,12 @@ describe "Proposals" do
click_link "No, I want to publish the proposal"
click_link "Not now, go to my proposal"
expect(Proposal.last.responsible_name).to eq("Isabel Garcia")
click_link "Dashboard"
click_link "Edit my proposal"
within_window(window_opened_by { click_link "Edit proposal" }) do
expect(page).to have_field "Full name of the person submitting the proposal", with: "Isabel Garcia"
end
end
scenario "Responsible name field is not shown for verified users" do

View File

@@ -102,7 +102,9 @@ describe "Tags" do
click_link "No, I want to publish the proposal"
click_link "Not now, go to my proposal"
within "#tags_proposal_#{Proposal.last.id}" do
expect(page).to have_css "h1", exact_text: "Help refugees"
within ".tags" do
expect(page).to have_content "Education"
expect(page).not_to have_content "Health"
end