JavaScript is used by about 98% of web users, so by testing without it enabled, we're only testing that the application works for a very reduced number of users. We proceeded this way in the past because CONSUL started using Rails 4.2 and truncating the database between JavaScript tests with database cleaner, which made these tests terribly slow. When we upgraded to Rails 5.1 and introduced system tests, we started using database transactions in JavaScript tests, making these tests much faster. So now we can use JavaScript tests everywhere without critically slowing down our test suite.
49 lines
1.7 KiB
Ruby
49 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Admin download user emails" do
|
|
let(:admin_user) { create(:user, newsletter: false, email: "admin@consul.dev") }
|
|
|
|
before do
|
|
create(:administrator, user: admin_user)
|
|
login_as(admin_user)
|
|
end
|
|
|
|
context "Download only emails from segment users with newsletter flag & present email " do
|
|
before do
|
|
create(:user, email: "user@consul.dev")
|
|
|
|
create(:administrator, user: create(:user, newsletter: true, email: "admin_news1@consul.dev"))
|
|
create(:administrator, user: create(:user, newsletter: true, email: "admin_news2@consul.dev"))
|
|
|
|
create(:administrator, user: create(:user, newsletter: false, email: "no_news@consul.dev"))
|
|
|
|
admin_without_email = create(:user, newsletter: true, email: "no_email@consul.dev")
|
|
create(:administrator, user: admin_without_email)
|
|
admin_without_email.update_column(:email, nil)
|
|
end
|
|
|
|
scenario "returns the selected users segment csv file", :no_js do
|
|
visit admin_emails_download_index_path
|
|
|
|
within("#admin_download_emails") do
|
|
select "Administrators", from: "users_segment"
|
|
click_button "Download emails list"
|
|
end
|
|
|
|
header = page.response_headers["Content-Disposition"]
|
|
expect(header).to match(/^attachment/)
|
|
expect(header).to match(/filename="Administrators.csv"$/)
|
|
|
|
file_contents = page.body.split(",")
|
|
expect(file_contents).to match_array ["admin_news1@consul.dev", "admin_news2@consul.dev"]
|
|
end
|
|
end
|
|
|
|
scenario "Download button is not disabled after being clicked" do
|
|
visit admin_emails_download_index_path
|
|
click_button "Download emails list"
|
|
|
|
expect(page).to have_button "Download emails list", disabled: false
|
|
end
|
|
end
|