1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 14:19:39 +02:00

Allow CSV file upload in import flow (#986)

* Add .tool-versions to gitignore

* Add dropzone js for drag and drop file uploads

* UI for csv file uploads for import

* dropzone controller and use lucide_icon instead of svg

* Preview for file chosen

* File upload

* Remove dropzone

* Normalize I18n keys and fix lint issues

* Add system tests

* Cleanup

* Remove unwanted
This commit is contained in:
Tony Vincent 2024-07-16 15:23:45 +02:00 committed by GitHub
parent 41f9e23f8c
commit cdbca5aff3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 307 additions and 41 deletions

View file

@ -65,6 +65,18 @@ class ImportsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Import CSV loaded", flash[:notice]
end
test "should upload CSV file if valid" do
Tempfile.open([ "transactions.csv", ".csv" ]) do |temp|
CSV.open(temp, "wb", headers: true) do |csv|
valid_csv_str.split("\n").each { |row| csv << row.split(",") }
end
patch upload_import_url(@empty_import), params: { import: { raw_csv_str: Rack::Test::UploadedFile.new(temp, ".csv") } }
assert_redirected_to configure_import_path(@empty_import)
assert_equal "CSV File loaded", flash[:notice]
end
end
test "should flash error message if invalid CSV input" do
patch load_import_url(@empty_import), params: { import: { raw_csv_str: malformed_csv_str } }
@ -72,6 +84,23 @@ class ImportsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Raw csv str is not a valid CSV format", flash[:error]
end
test "should flash error message if invalid CSV file upload" do
Tempfile.open([ "transactions.csv", ".csv" ]) do |temp|
temp.write(malformed_csv_str)
temp.rewind
patch upload_import_url(@empty_import), params: { import: { raw_csv_str: Rack::Test::UploadedFile.new(temp, ".csv") } }
assert_response :unprocessable_entity
assert_equal "Raw csv str is not a valid CSV format", flash[:error]
end
end
test "should flash error message if no fileprovided for upload" do
patch upload_import_url(@empty_import), params: { import: { raw_csv_str: nil } }
assert_response :unprocessable_entity
assert_equal "Please select a file to upload", flash[:error]
end
test "should get configure" do
get configure_import_url(@loaded_import)
assert_response :success