This commit is contained in:
carla 2026-02-03 15:23:35 +01:00
parent 96daf2a089
commit 7041aa320a
2 changed files with 492 additions and 287 deletions

View file

@ -150,18 +150,19 @@ defmodule MvWeb.ImportExportLiveTest do
|> form("#csv-upload-form", %{})
|> render_submit()
# Check that import has started or shows appropriate message
# Check that import has started using data-testid
# Either import-progress-container exists (import started) OR we see a CSV error
html = render(view)
# Either import started successfully OR we see a specific error (not admin error)
import_started = html =~ "Import in progress" or html =~ "running" or html =~ "progress"
import_started = has_element?(view, "[data-testid='import-progress-container']")
no_admin_error = not (html =~ "Only administrators can import")
# If import failed, it should be a CSV parsing error, not an admin error
if html =~ "Failed to prepare CSV import" do
# This is acceptable - CSV might have issues, but admin check passed
assert no_admin_error
else
# Import should have started
assert import_started or html =~ "CSV File"
# Import should have started - check for progress container
assert import_started
end
end
@ -175,18 +176,18 @@ defmodule MvWeb.ImportExportLiveTest do
|> form("#csv-upload-form", %{})
|> render_submit()
# Check that import has started or shows appropriate message
# Check that import has started using data-testid
html = render(view)
# Either import started successfully OR we see a specific error (not admin error)
import_started = html =~ "Import in progress" or html =~ "running" or html =~ "progress"
import_started = has_element?(view, "[data-testid='import-progress-container']")
no_admin_error = not (html =~ "Only administrators can import")
# If import failed, it should be a CSV parsing error, not an admin error
if html =~ "Failed to prepare CSV import" do
# This is acceptable - CSV might have issues, but admin check passed
assert no_admin_error
else
# Import should have started
assert import_started or html =~ "CSV File"
# Import should have started - check for progress container
assert import_started
end
end
@ -295,15 +296,14 @@ defmodule MvWeb.ImportExportLiveTest do
# In test mode, chunks are processed synchronously and messages are sent via send/2
# render(view) processes handle_info messages, so we call it multiple times
# to ensure all messages are processed
# Use the same approach as "success rendering" test which works
Process.sleep(1000)
# Check that import-results-panel exists (import completed)
assert has_element?(view, "[data-testid='import-results-panel']")
# Verify success count is shown
html = render(view)
# Should show success count (inserted count)
assert html =~ "Inserted" or html =~ "inserted" or html =~ "2"
# Should show completed status
assert html =~ "completed" or html =~ "done" or html =~ "Import completed" or
has_element?(view, "[data-testid='import-results-panel']")
assert html =~ "Successfully inserted" or html =~ "inserted"
end
test "error handling: invalid CSV shows errors with line numbers", %{
@ -320,7 +320,13 @@ defmodule MvWeb.ImportExportLiveTest do
|> render_submit()
# Wait for chunk processing
Process.sleep(500)
Process.sleep(1000)
# Check that import-results-panel exists (import completed with errors)
assert has_element?(view, "[data-testid='import-results-panel']")
# Check that error list exists
assert has_element?(view, "[data-testid='import-error-list']")
html = render(view)
# Should show failure count > 0
@ -349,13 +355,16 @@ defmodule MvWeb.ImportExportLiveTest do
# Wait for chunk processing
Process.sleep(1000)
# Check that import-results-panel exists (import completed)
assert has_element?(view, "[data-testid='import-results-panel']")
html = render(view)
# Should show failed count == 100
assert html =~ "100" or html =~ "failed"
# Errors should be capped at 50 (but we can't easily check exact count in HTML)
# The important thing is that processing completes without crashing
assert html =~ "done" or html =~ "complete" or html =~ "finished"
# Import is done when import-results-panel exists
end
test "chunk scheduling: progress updates show chunk processing", %{
@ -374,16 +383,17 @@ defmodule MvWeb.ImportExportLiveTest do
# Wait a bit for processing to start
Process.sleep(200)
# Check that status area exists (with aria-live for accessibility)
# Check that import-progress-container exists (with aria-live for accessibility)
assert has_element?(view, "[data-testid='import-progress-container']")
# Check that progress text is shown when running
html = render(view)
assert has_element?(view, "[data-testid='import-progress-text']") or
html =~ "Processing chunk"
assert html =~ "aria-live" or html =~ "status" or html =~ "progress" or
html =~ "Processing" or html =~ "chunk"
# Final state should be :done
# Final state should show import-results-panel
Process.sleep(500)
final_html = render(view)
assert final_html =~ "done" or final_html =~ "complete" or final_html =~ "finished"
assert has_element?(view, "[data-testid='import-results-panel']")
end
end
@ -432,11 +442,12 @@ defmodule MvWeb.ImportExportLiveTest do
# Wait for processing to complete
Process.sleep(1000)
# Check that import-results-panel exists (import completed)
assert has_element?(view, "[data-testid='import-results-panel']")
# Verify success count is shown
html = render(view)
# Should show success count (inserted count)
assert html =~ "Inserted" or html =~ "inserted" or html =~ "2"
# Should show completed status
assert html =~ "completed" or html =~ "done" or html =~ "Import completed"
assert html =~ "Successfully inserted" or html =~ "inserted"
end
test "error rendering: invalid CSV shows failure count and error list with line numbers", %{
@ -455,14 +466,18 @@ defmodule MvWeb.ImportExportLiveTest do
# Wait for processing
Process.sleep(1000)
# Check that import-results-panel exists (import completed with errors)
assert has_element?(view, "[data-testid='import-results-panel']")
# Check that error list exists
assert has_element?(view, "[data-testid='import-error-list']")
html = render(view)
# Should show failure count
assert html =~ "Failed" or html =~ "failed"
# Should show error list with line numbers (from service, not recalculated)
assert html =~ "Line" or html =~ "line" or html =~ "2" or html =~ "3"
# Should show error messages
assert html =~ "error" or html =~ "Error" or html =~ "Errors"
end
test "warning rendering: CSV with unknown custom field shows warnings block", %{
@ -495,12 +510,13 @@ defmodule MvWeb.ImportExportLiveTest do
# Wait for processing
Process.sleep(1000)
# Check that import-results-panel exists (import completed)
assert has_element?(view, "[data-testid='import-results-panel']")
html = render(view)
# Should show warnings block (if warnings were generated)
# Warnings are generated when unknown custom field columns are detected
# Check if warnings section exists OR if import completed successfully
has_warnings = html =~ "Warning" or html =~ "warning" or html =~ "Warnings"
import_completed = html =~ "completed" or html =~ "done" or html =~ "Import Results"
# If warnings exist, they should contain the column name
if has_warnings do
@ -509,7 +525,7 @@ defmodule MvWeb.ImportExportLiveTest do
end
# Import should complete (either with or without warnings)
assert import_completed
# Verified by import-results-panel existence above
end
test "A11y: file input has label", %{conn: conn} do
@ -569,9 +585,12 @@ defmodule MvWeb.ImportExportLiveTest do
# Wait for processing
Process.sleep(1000)
# Check that import-results-panel exists (import completed successfully)
assert has_element?(view, "[data-testid='import-results-panel']")
html = render(view)
# Should succeed (BOM is stripped automatically)
assert html =~ "completed" or html =~ "done" or html =~ "Inserted"
assert html =~ "Successfully inserted" or html =~ "inserted"
# Should not show error about BOM
refute html =~ "BOM" or html =~ "encoding"
end