From b4d13816facb40009836ee65ed512b36d5c5dad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 16 May 2019 11:53:46 +0200 Subject: [PATCH] Add feature specs --- .../local_census_records/imports_spec.rb | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 spec/features/admin/local_census_records/imports_spec.rb diff --git a/spec/features/admin/local_census_records/imports_spec.rb b/spec/features/admin/local_census_records/imports_spec.rb new file mode 100644 index 000000000..76d990d8b --- /dev/null +++ b/spec/features/admin/local_census_records/imports_spec.rb @@ -0,0 +1,91 @@ +require "rails_helper" + +feature "Imports", type: :feature do + + let(:base_files_path) { %w[spec fixtures files local_census_records import] } + + background do + admin = create(:administrator) + login_as(admin.user) + end + + describe "New" do + scenario "Should show import form" do + visit new_admin_local_census_records_import_path + + expect(page).to have_field("local_census_records_import_file", type: "file") + end + end + + describe "Create" do + before { visit new_admin_local_census_records_import_path } + + scenario "Should show success notice after successful import" do + within "form#new_local_census_records_import" do + path = base_files_path << "valid.csv" + file = File.join(Rails.root, *path) + attach_file("local_census_records_import_file", file) + click_button "Save" + end + + expect(page).to have_content "Local census records import process executed successfully!" + end + + scenario "Should show alert when file is not present" do + within "form#new_local_census_records_import" do + click_button "Save" + end + + expect(page).to have_content "can't be blank" + end + + scenario "Should show alert when file is not supported" do + within "form#new_local_census_records_import" do + path = ["spec", "fixtures", "files", "clippy.jpg"] + file = File.join(Rails.root, *path) + attach_file("local_census_records_import_file", file) + click_button "Save" + end + + expect(page).to have_content "Given file format is wrong. The allowed file format is: csv." + end + + scenario "Should show successfully created local census records at created group" do + within "form#new_local_census_records_import" do + path = base_files_path << "valid.csv" + file = File.join(Rails.root, *path) + attach_file("local_census_records_import_file", file) + click_button "Save" + end + + expect(page).to have_content "Created records (4)" + expect(page).to have_selector("#created-local-census-records tbody tr", count: 4) + end + + scenario "Should show invalid local census records at errored group" do + within "form#new_local_census_records_import" do + path = base_files_path << "invalid.csv" + file = File.join(Rails.root, *path) + attach_file("local_census_records_import_file", file) + click_button "Save" + end + + expect(page).to have_content "Errored rows (4)" + expect(page).to have_selector("#invalid-local-census-records tbody tr", count: 4) + end + + scenario "Should show error messages inside cells at errored group" do + within "form#new_local_census_records_import" do + path = base_files_path << "invalid.csv" + file = File.join(Rails.root, *path) + attach_file("local_census_records_import_file", file) + click_button "Save" + end + rows = all("#invalid-local-census-records tbody tr") + expect(rows[0]).to have_content("can't be blank") + expect(rows[1]).to have_content("can't be blank") + expect(rows[2]).to have_content("can't be blank") + expect(rows[3]).to have_content("can't be blank") + end + end +end