refactor
This commit is contained in:
parent
aaf9c7127d
commit
a15ff055cc
4 changed files with 182 additions and 95 deletions
|
|
@ -19,6 +19,26 @@ defmodule MvWeb.GlobalSettingsLiveTest do
|
|||
|> render_upload(filename)
|
||||
end
|
||||
|
||||
# Helper function to wait for import completion by checking for results panel
|
||||
# Uses deterministic checks instead of Process.sleep/1
|
||||
defp wait_for_import_completion(view, max_attempts \\ 10) do
|
||||
Enum.reduce_while(1..max_attempts, nil, fn attempt, _acc ->
|
||||
html = render(view)
|
||||
|
||||
if has_element?(view, "[data-testid='import-results-panel']") do
|
||||
{:halt, html}
|
||||
else
|
||||
if attempt < max_attempts do
|
||||
# Process any pending messages
|
||||
:timer.sleep(50)
|
||||
{:cont, nil}
|
||||
else
|
||||
{:halt, html}
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
describe "Global Settings LiveView" do
|
||||
setup %{conn: conn} do
|
||||
user = create_test_user(%{email: "admin@example.com"})
|
||||
|
|
@ -333,18 +353,13 @@ defmodule MvWeb.GlobalSettingsLiveTest do
|
|||
|> form("#csv-upload-form", %{})
|
||||
|> render_submit()
|
||||
|
||||
# Wait for chunk processing to complete
|
||||
# Process all chunks by waiting for final state
|
||||
Process.sleep(500)
|
||||
# Wait for import completion deterministically
|
||||
html = wait_for_import_completion(view)
|
||||
|
||||
# Check final status
|
||||
html = render(view)
|
||||
# Should show done status or success message
|
||||
assert html =~ "done" or html =~ "complete" or html =~ "success" or
|
||||
html =~ "finished" or html =~ "imported" or html =~ "Inserted"
|
||||
|
||||
# Should show success count > 0
|
||||
assert html =~ "2" or html =~ "inserted" or html =~ "success"
|
||||
# Check final status using data-testid
|
||||
assert has_element?(view, "[data-testid='import-results-panel']")
|
||||
# Should show success count
|
||||
assert html =~ "Successfully inserted"
|
||||
end
|
||||
|
||||
test "error handling: invalid CSV shows errors with line numbers", %{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue