From 8d9a3e1ff1c6e58f23b4d6136f38b0edd32603d4 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 07:55:13 +0100 Subject: [PATCH 1/8] test: port the e2e suite to ExUnit with playwright_ex The browser tests run as ExUnit tests in e2e_pw/ (MIX_ENV=e2e mix test), against the server of test/e2e/server.exs started in the same VM. The suite lives outside test/ so that a plain mix test, including on Elixir 1.15, does not load it. The e2e CI job runs on Elixir 1.19, as playwright_ex needs 1.18 or later. --- .formatter.exs | 2 +- .github/workflows/e2e.yml | 27 +- config/config.exs | 9 + config/runtime.exs | 6 + e2e_pw/basic_test.exs | 36 ++ e2e_pw/dead_view_test.exs | 26 ++ e2e_pw/event_reply_test.exs | 247 +++++++++++ e2e_pw/event_test.exs | 114 ++++++ e2e_pw/form_test.exs | 654 ++++++++++++++++++++++++++++++ e2e_pw/headless_test.exs | 41 ++ e2e_pw/navigation_test.exs | 54 +++ e2e_pw/persistent_layout_test.exs | 80 ++++ e2e_pw/prop_diff_test.exs | 229 +++++++++++ e2e_pw/reconnect_test.exs | 72 ++++ e2e_pw/slot_test.exs | 39 ++ e2e_pw/stream_test.exs | 463 +++++++++++++++++++++ e2e_pw/support/case.ex | 15 + e2e_pw/support/utils.ex | 56 +++ e2e_pw/test_helper.exs | 10 + e2e_pw/upload_test.exs | 403 ++++++++++++++++++ mix.exs | 14 +- mix.lock | 1 + test/e2e/server.exs | 210 ++++++++++ test/e2e/test_helper.exs | 210 +--------- 24 files changed, 2801 insertions(+), 217 deletions(-) create mode 100644 config/runtime.exs create mode 100644 e2e_pw/basic_test.exs create mode 100644 e2e_pw/dead_view_test.exs create mode 100644 e2e_pw/event_reply_test.exs create mode 100644 e2e_pw/event_test.exs create mode 100644 e2e_pw/form_test.exs create mode 100644 e2e_pw/headless_test.exs create mode 100644 e2e_pw/navigation_test.exs create mode 100644 e2e_pw/persistent_layout_test.exs create mode 100644 e2e_pw/prop_diff_test.exs create mode 100644 e2e_pw/reconnect_test.exs create mode 100644 e2e_pw/slot_test.exs create mode 100644 e2e_pw/stream_test.exs create mode 100644 e2e_pw/support/case.ex create mode 100644 e2e_pw/support/utils.ex create mode 100644 e2e_pw/test_helper.exs create mode 100644 e2e_pw/upload_test.exs create mode 100644 test/e2e/server.exs diff --git a/.formatter.exs b/.formatter.exs index 16f4a357..2a226c4c 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -3,5 +3,5 @@ import_deps: [:phoenix], line_length: 120, plugins: [Phoenix.LiveView.HTMLFormatter, Styler], - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] + inputs: ["{mix,.formatter}.exs", "{config,e2e_pw,lib,test}/**/*.{ex,exs}"] ] diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index d842dd06..89dce277 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -20,8 +20,9 @@ jobs: - name: Set up Elixir uses: erlef/setup-beam@v1 with: - elixir-version: "1.15" - otp-version: "26" + # playwright_ex needs Elixir ~> 1.18 + elixir-version: "1.19" + otp-version: "28" - name: Restore Elixir dependency cache uses: actions/cache@v6 @@ -44,8 +45,26 @@ jobs: - name: Install npm dependencies (root) run: npm install + # mix.lock pins the playwright_ex driver and so the browser revisions + - name: Restore Playwright driver and browser cache + uses: actions/cache@v6 + with: + path: | + ~/.cache/playwright + ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('**/mix.lock') }} + - name: Install E2E dependencies and browsers - run: npm run e2e:install + run: mix playwright.install chromium --with-deps + # Up to two retries of the failed tests, as the `retries: 2` of Playwright Test - name: Run E2E tests - run: npm run e2e:test + run: | + npm run e2e:build + mix test || { [ $? -eq 2 ] && mix test --failed; } || { [ $? -eq 2 ] && mix test --failed; } + + - uses: actions/upload-artifact@v7 + if: failure() + with: + name: test-results + path: test-results diff --git a/config/config.exs b/config/config.exs index 1a6a7f38..14d2ab2a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -24,3 +24,12 @@ config :live_vue, # if false, we will always update full props and not send diffs # defaults to true as it greatly reduces payload size enable_props_diff: true + +if config_env() == :e2e do + config :playwright, :expect, timeout: 1000 + # The Playwright suite in e2e_pw/ + config :playwright, :test, + base_url: "http://localhost:4004/", + trace: :retain_on_failure, + screenshot: :only_on_failure +end diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 00000000..db446c09 --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,6 @@ +import Config + +# Desktop Chrome for every test. Here, as config.exs runs before Playwright.device/1 is compiled. +if config_env() == :e2e do + config :playwright, :test, Playwright.device("Desktop Chrome") +end diff --git a/e2e_pw/basic_test.exs b/e2e_pw/basic_test.exs new file mode 100644 index 00000000..7ff2a4b2 --- /dev/null +++ b/e2e_pw/basic_test.exs @@ -0,0 +1,36 @@ +defmodule LiveVue.E2E.BasicTest do + use LiveVue.E2E.Case, async: true + + describe "LiveVue Basic E2E Tests" do + test "renders Vue component inside LiveView and handles increment events", %{page: page} do + Page.goto!(page, "/test") + sync_lv(page) + + # Verify Vue component is mounted and displays initial count + Expect.to_be_visible!(Page.locator(page, ~s([phx-hook="VueHook"]))) + Expect.to_have_text!(Page.locator(page, "[data-pw-counter]"), "0") + + # Verify the diff slider is present and has default value + diff_slider = Page.locator(page, ~s(input[type="range"])) + Expect.to_be_visible!(diff_slider) + Expect.to_have_value!(diff_slider, "1") + + # Test incrementing by default value (1) + Locator.click!(Page.locator(page, "button")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, ~s([phx-hook="VueHook"] [data-pw-counter])), "1") + + # Test incrementing by a different value (3) + Locator.fill!(diff_slider, "3") + Locator.click!(Page.locator(page, "button")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, ~s([phx-hook="VueHook"] [data-pw-counter])), "4") + + # Test incrementing by maximum value (10) + Locator.fill!(diff_slider, "10") + Locator.click!(Page.locator(page, "button")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, ~s([phx-hook="VueHook"] [data-pw-counter])), "14") + end + end +end diff --git a/e2e_pw/dead_view_test.exs b/e2e_pw/dead_view_test.exs new file mode 100644 index 00000000..c3debe0b --- /dev/null +++ b/e2e_pw/dead_view_test.exs @@ -0,0 +1,26 @@ +defmodule LiveVue.E2E.DeadViewTest do + use LiveVue.E2E.Case, async: true + + alias Playwright.Response + + describe "LiveVue Dead View Tests" do + test "renders Vue component inside regular Phoenix controller view (dead view)", %{page: page} do + # Navigate to the dead view page + response = Page.goto!(page, "/dead-view") + + # First check if the page loaded successfully (no 500 error) + assert Response.status(response) == 200 + + # Verify the server-rendered content from the controller + Expect.to_have_text!(Page.locator(page, "[data-pw-server-message]"), "Hello from dead view!") + + # Wait for Vue to initialize and hydrate the component + # In dead views, Vue still mounts via the VueHook initialization + Page.wait_for_timeout!(page, 500) + + # Verify the Vue component rendered correctly + Expect.to_be_visible!(Page.locator(page, "[data-pw-dead-view]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-vue-message]"), "Hello from dead view!") + end + end +end diff --git a/e2e_pw/event_reply_test.exs b/e2e_pw/event_reply_test.exs new file mode 100644 index 00000000..e41627f4 --- /dev/null +++ b/e2e_pw/event_reply_test.exs @@ -0,0 +1,247 @@ +defmodule LiveVue.E2E.EventReplyTest do + use LiveVue.E2E.Case, async: true + + describe "useEventReply E2E Tests" do + setup %{page: page} do + Page.goto!(page, "/event-reply-test") + sync_lv(page) + :ok + end + + test "component initializes correctly", %{page: page} do + # Verify component is mounted + Expect.to_be_visible!(Page.locator(page, "[data-pw-event-reply-test]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-server-counter]"), "Server Counter: 0") + + # Initial state should be empty + Expect.to_have_text!(Page.locator(page, "[data-pw-increment-loading]"), "Loading: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-increment-data]"), "Data: null") + end + + test "increment event with reply works correctly", %{page: page} do + # Click increment by 1 + Locator.click!(Page.locator(page, "[data-pw-increment-1]")) + sync_lv(page) + + # Check server state updated + Expect.to_have_text!(Page.locator(page, "[data-pw-server-counter]"), "Server Counter: 1") + + # Check client state received reply + Expect.to_have_text!(Page.locator(page, "[data-pw-increment-loading]"), "Loading: false") + Expect.to_contain_text!(Page.locator(page, "[data-pw-increment-data]"), ~s("counter":1)) + + # Click increment by 5 + Locator.click!(Page.locator(page, "[data-pw-increment-5]")) + sync_lv(page) + + # Check server counter is now 6 + Expect.to_have_text!(Page.locator(page, "[data-pw-server-counter]"), "Server Counter: 6") + Expect.to_contain_text!(Page.locator(page, "[data-pw-increment-data]"), ~s("counter":6)) + end + + test "user data fetching with different IDs", %{page: page} do + # Fetch user 1 + Locator.click!(Page.locator(page, "[data-pw-fetch-user-1]")) + sync_lv(page) + + Expect.to_have_text!(Page.locator(page, "[data-pw-user-loading]"), "Loading: false") + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("name":"John Doe")) + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("email":"john@example.com")) + + # Fetch user 2 + Locator.click!(Page.locator(page, "[data-pw-fetch-user-2]")) + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("name":"Jane Smith")) + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("email":"jane@example.com")) + + # Fetch unknown user + Locator.click!(Page.locator(page, "[data-pw-fetch-user-999]")) + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("name":"Unknown User")) + end + + test "server error response handling works correctly", %{page: page} do + # Trigger server error response + Locator.click!(Page.locator(page, "[data-pw-trigger-error]")) + sync_lv(page) + + # Should receive error in data (server returns error as valid response data) + Expect.to_have_text!(Page.locator(page, "[data-pw-error-loading]"), "Loading: false") + + Expect.to_contain_text!( + Page.locator(page, "[data-pw-error-data]"), + ~s("error":"Something went wrong on the server") + ) + end + + test "no parameters event works", %{page: page} do + # Test ping without parameters + Locator.click!(Page.locator(page, "[data-pw-ping]")) + sync_lv(page) + + Expect.to_have_text!(Page.locator(page, "[data-pw-ping-loading]"), "Loading: false") + Expect.to_contain_text!(Page.locator(page, "[data-pw-ping-data]"), ~s("response":"pong")) + end + + test "different data types are handled correctly", %{page: page} do + # Test string - now wrapped in {data: "Hello World"} + Locator.click!(Page.locator(page, "[data-pw-test-string]")) + sync_lv(page) + Expect.to_contain_text!(Page.locator(page, "[data-pw-datatype-data]"), ~s("data":"Hello World")) + + # Test number - now wrapped in {data: 42} + Locator.click!(Page.locator(page, "[data-pw-test-number]")) + sync_lv(page) + Expect.to_contain_text!(Page.locator(page, "[data-pw-datatype-data]"), ~s("data":42)) + + # Test boolean - now wrapped in {data: true} + Locator.click!(Page.locator(page, "[data-pw-test-boolean]")) + sync_lv(page) + Expect.to_contain_text!(Page.locator(page, "[data-pw-datatype-data]"), ~s("data":true)) + + # Test array - now wrapped in {data: [1,2,3,"four",true]} + Locator.click!(Page.locator(page, "[data-pw-test-array]")) + sync_lv(page) + Expect.to_contain_text!(Page.locator(page, "[data-pw-datatype-data]"), ~s("data":[1,2,3,"four",true])) + + # Test object - now wrapped in {data: {nested: {value: "test"}, count: 5}} + Locator.click!(Page.locator(page, "[data-pw-test-object]")) + sync_lv(page) + # Check for key components since JSON key order isn't guaranteed + object_data = Page.locator(page, "[data-pw-datatype-data]") + Expect.to_contain_text!(object_data, ~s("data":)) + Expect.to_contain_text!(object_data, ~s("nested":{"value":"test"})) + Expect.to_contain_text!(object_data, ~s("count":5)) + + # Test null - now wrapped in {data: null} + Locator.click!(Page.locator(page, "[data-pw-test-null]")) + sync_lv(page) + Expect.to_contain_text!(Page.locator(page, "[data-pw-datatype-data]"), ~s("data":null)) + end + + test "input validation with server-side logic", %{page: page} do + # Test short input (invalid) + Locator.click!(Page.locator(page, "[data-pw-validate-short]")) + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "[data-pw-validate-data]"), ~s("valid":false)) + Expect.to_contain_text!(Page.locator(page, "[data-pw-validate-data]"), ~s("error":"Input too short")) + + # Test valid input + Locator.click!(Page.locator(page, "[data-pw-validate-valid]")) + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "[data-pw-validate-data]"), ~s("valid":true)) + Expect.to_contain_text!(Page.locator(page, "[data-pw-validate-data]"), ~s("message":"Input is valid")) + + # Test long input (invalid) + Locator.click!(Page.locator(page, "[data-pw-validate-long]")) + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "[data-pw-validate-data]"), ~s("valid":false)) + Expect.to_contain_text!(Page.locator(page, "[data-pw-validate-data]"), ~s("error":"Input too long")) + end + + test "cancellation functionality works", %{page: page} do + # Start slow event + Locator.click!(Page.locator(page, "[data-pw-start-slow]")) + + # Should be loading immediately + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: true") + + # Cancel before it completes + Locator.click!(Page.locator(page, "[data-pw-cancel-slow]")) + + # Should not be loading after cancel + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: false") + + # Data should remain null (cancelled) + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-data]"), "Data: null") + + # Wait a bit to ensure the server response would have arrived + Page.wait_for_timeout!(page, 500) + sync_lv(page) + + # Data should still be null (response ignored) + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-data]"), "Data: null") + end + + test "concurrent execution prevention works", %{page: page} do + # Start first slow event + Locator.click!(Page.locator(page, "[data-pw-concurrent-first]")) + + # Should be loading + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: true") + + # Try to start second event - should be rejected + Locator.click!(Page.locator(page, "[data-pw-concurrent-second]")) + + # Should still show loading from first event only + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: true") + + # Wait for first event to complete + Page.wait_for_timeout!(page, 1200) + sync_lv(page) + + # Should now show completed first event + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: false") + Expect.to_contain_text!(Page.locator(page, "[data-pw-slow-data]"), ~s("message":"Slow response after 1000ms")) + end + + test "multiple different composables work independently", %{page: page} do + # Execute multiple different events in quick succession + Locator.click!(Page.locator(page, "[data-pw-increment-1]")) + Locator.click!(Page.locator(page, "[data-pw-fetch-user-1]")) + Locator.click!(Page.locator(page, "[data-pw-ping]")) + + Page.wait_for_timeout!(page, 100) + + # All should complete successfully and independently + Expect.to_contain_text!(Page.locator(page, "[data-pw-increment-data]"), ~s("counter":1)) + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("name":"John Doe")) + Expect.to_contain_text!(Page.locator(page, "[data-pw-ping-data]"), ~s("response":"pong")) + + # All should be not loading + Expect.to_have_text!(Page.locator(page, "[data-pw-increment-loading]"), "Loading: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-user-loading]"), "Loading: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-ping-loading]"), "Loading: false") + end + + test "component state persists across LiveView updates", %{page: page} do + # Execute an event to get some data + Locator.click!(Page.locator(page, "[data-pw-increment-5]")) + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "[data-pw-increment-data]"), ~s("counter":5)) + + # Trigger another server update that doesn't affect this composable + Locator.click!(Page.locator(page, "[data-pw-fetch-user-1]")) + sync_lv(page) + + # Original increment data should still be there + Expect.to_contain_text!(Page.locator(page, "[data-pw-increment-data]"), ~s("counter":5)) + Expect.to_contain_text!(Page.locator(page, "[data-pw-user-data]"), ~s("name":"John Doe")) + end + + test "loading states are accurate", %{page: page} do + # All should start as not loading + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: false") + + # Start slow event and verify loading state immediately + Locator.click!(Page.locator(page, "[data-pw-start-slow]")) + + # Should be loading now + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: true") + + # Wait for completion + Page.wait_for_timeout!(page, 2200) + sync_lv(page) + + # Should be done loading + Expect.to_have_text!(Page.locator(page, "[data-pw-slow-loading]"), "Loading: false") + Expect.to_contain_text!(Page.locator(page, "[data-pw-slow-data]"), "Slow response after 2000ms") + end + end +end diff --git a/e2e_pw/event_test.exs b/e2e_pw/event_test.exs new file mode 100644 index 00000000..e800fdb3 --- /dev/null +++ b/e2e_pw/event_test.exs @@ -0,0 +1,114 @@ +defmodule LiveVue.E2E.EventTest do + use LiveVue.E2E.Case, async: true + + describe "useLiveEvent" do + test "should receive notification events from server", %{page: page} do + Page.goto!(page, "/events") + sync_lv(page) + + # Verify initial state + Expect.to_contain_text!(Page.locator(page, "#notification-count"), "Notification Count: 0") + Expect.to_contain_text!(Page.locator(page, "#custom-count"), "Custom Event Count: 0") + + # Send a notification event + Page.fill!(page, "#message-input", "Hello from test!") + Page.click!(page, "#send-notification-btn") + sync_lv(page) + + # Verify notification event was received + Expect.to_contain_text!(Page.locator(page, "#notification-count"), "Notification Count: 1") + Expect.to_contain_text!(Page.locator(page, ".notification-event"), "Hello from test!") + + # Verify the message appears in both LiveView state and Vue component + Expect.to_contain_text!(Page.locator(page, "#message-display"), "Message: Hello from test!") + Expect.to_contain_text!(Page.locator(page, "#event-count"), "Event Count: 1") + + # Send another notification + Page.fill!(page, "#message-input", "Second message") + Page.click!(page, "#send-notification-btn") + sync_lv(page) + + # Verify both notifications are received + Expect.to_contain_text!(Page.locator(page, "#notification-count"), "Notification Count: 2") + Expect.to_have_count!(Page.locator(page, ".notification-event"), 2) + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".notification-event"), 1), "Second message") + end + + test "should receive custom events from server", %{page: page} do + Page.goto!(page, "/events") + sync_lv(page) + + # Send a custom event + Page.fill!(page, "#custom-data-input", "Custom data payload") + Page.click!(page, "#send-custom-btn") + sync_lv(page) + + # Verify custom event was received + Expect.to_contain_text!(Page.locator(page, "#custom-count"), "Custom Event Count: 1") + Expect.to_contain_text!(Page.locator(page, ".custom-event"), "Custom data payload (count: 1)") + Expect.to_contain_text!(Page.locator(page, "#event-count"), "Event Count: 1") + + # Send another custom event + Page.fill!(page, "#custom-data-input", "Another payload") + Page.click!(page, "#send-custom-btn") + sync_lv(page) + + # Verify both custom events are received + Expect.to_contain_text!(Page.locator(page, "#custom-count"), "Custom Event Count: 2") + Expect.to_have_count!(Page.locator(page, ".custom-event"), 2) + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".custom-event"), 1), "Another payload (count: 2)") + end + + test "should handle mixed notification and custom events", %{page: page} do + Page.goto!(page, "/events") + sync_lv(page) + + # Send notification + Page.fill!(page, "#message-input", "Mixed test notification") + Page.click!(page, "#send-notification-btn") + sync_lv(page) + + # Send custom event + Page.fill!(page, "#custom-data-input", "Mixed test custom") + Page.click!(page, "#send-custom-btn") + sync_lv(page) + + # Send another notification + Page.fill!(page, "#message-input", "Second notification") + Page.click!(page, "#send-notification-btn") + sync_lv(page) + + # Verify all events are received correctly + Expect.to_contain_text!(Page.locator(page, "#notification-count"), "Notification Count: 2") + Expect.to_contain_text!(Page.locator(page, "#custom-count"), "Custom Event Count: 1") + Expect.to_contain_text!(Page.locator(page, "#event-count"), "Event Count: 3") + + # Verify event contents + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".notification-event"), 0), "Mixed test notification") + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".custom-event"), 0), "Mixed test custom (count: 2)") + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".notification-event"), 1), "Second notification") + end + + test "should handle rapid sequential events", %{page: page} do + Page.goto!(page, "/events") + sync_lv(page) + + # Send multiple events rapidly + for i <- 1..5 do + Page.fill!(page, "#message-input", "Rapid message #{i}") + Page.click!(page, "#send-notification-btn") + end + + sync_lv(page) + + # Verify all events are received + Expect.to_contain_text!(Page.locator(page, "#notification-count"), "Notification Count: 5") + Expect.to_have_count!(Page.locator(page, ".notification-event"), 5) + Expect.to_contain_text!(Page.locator(page, "#event-count"), "Event Count: 5") + + # Verify first and last messages + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".notification-event"), 0), "Rapid message 1") + Expect.to_contain_text!(Locator.nth(Page.locator(page, ".notification-event"), 4), "Rapid message 5") + end + end +end diff --git a/e2e_pw/form_test.exs b/e2e_pw/form_test.exs new file mode 100644 index 00000000..b8393421 --- /dev/null +++ b/e2e_pw/form_test.exs @@ -0,0 +1,654 @@ +defmodule LiveVue.E2E.FormTest do + use LiveVue.E2E.Case, async: true + + describe "useLiveForm E2E Tests" do + setup %{page: page} do + Page.goto!(page, "/form-test") + sync_lv(page) + :ok + end + + test "form initializes with empty state and is invalid", %{page: page} do + # Verify form component is mounted + Expect.to_be_visible!(Page.locator(page, "[data-pw-form]")) + + # Check initial form state + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-touched]"), "Touched: false") + + # Submit button should be disabled initially + Expect.to_be_disabled!(Page.locator(page, "[data-pw-submit]")) + end + + test "basic field validation and form state tracking", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + + # Fill name field (but not enough characters) - use type instead of fill + Locator.type!(name_input, "A") + Locator.blur!(name_input) + # Give time for debounced events + Page.wait_for_timeout!(page, 500) + sync_lv(page) + + # Form should be touched and dirty but not valid + Expect.to_have_text!(Page.locator(page, "[data-pw-is-touched]"), "Touched: true") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: true") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Should show validation error after server validation + Expect.to_be_visible!(Page.locator(page, "[data-pw-name-error]")) + + # Fill valid data + Locator.clear!(name_input) + Locator.type!(name_input, "John Doe") + Locator.type!(email_input, "john@example.com") + # Accept terms is now required + Locator.check!(accept_terms_checkbox) + # Give time for debounced events + Page.wait_for_timeout!(page, 500) + sync_lv(page) + + # Form should now be valid + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + Expect.to_be_enabled!(Page.locator(page, "[data-pw-submit]")) + end + + test "nested field validation (profile bio)", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + bio_input = Page.locator(page, "[data-pw-bio-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + + # Fill required fields first + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.check!(accept_terms_checkbox) + + # Fill bio with insufficient content + Locator.fill!(bio_input, "Short") + Locator.blur!(bio_input) + sync_lv(page) + + # Should show bio validation error + Expect.to_be_visible!(Page.locator(page, "[data-pw-bio-error]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Fill with valid bio + Locator.fill!(bio_input, "This is a valid bio with enough characters to pass validation") + Locator.blur!(bio_input) + sync_lv(page) + + # Form should be valid now + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + end + + test "array field operations - skills", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + + # Fill required fields + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + + # Initially no skills + Expect.to_have_count!(Page.locator(page, "[data-pw-skill-item]"), 0) + + # Add a skill + Locator.click!(Page.locator(page, "[data-pw-add-skill]")) + Expect.to_have_count!(Page.locator(page, "[data-pw-skill-item]"), 1) + + # Fill the skill + Locator.fill!(Page.locator(page, ~s([data-pw-skill-input="0"])), "JavaScript") + sync_lv(page) + + # Add another skill + Locator.click!(Page.locator(page, "[data-pw-add-skill]")) + Expect.to_have_count!(Page.locator(page, "[data-pw-skill-item]"), 2) + + # Fill second skill + Locator.fill!(Page.locator(page, ~s([data-pw-skill-input="1"])), "TypeScript") + sync_lv(page) + + # Remove first skill + Locator.click!(Page.locator(page, ~s([data-pw-remove-skill="0"]))) + Expect.to_have_count!(Page.locator(page, "[data-pw-skill-item]"), 1) + + # Remaining skill should be TypeScript + Expect.to_have_value!(Page.locator(page, ~s([data-pw-skill-input="0"])), "TypeScript") + end + + test "nested array field operations - items with tags", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + + # Fill required fields + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + + # Add an item + Locator.click!(Page.locator(page, "[data-pw-add-item]")) + Expect.to_have_count!(Page.locator(page, "[data-pw-item]"), 1) + + # Fill item title + Locator.fill!(Page.locator(page, ~s([data-pw-item-title="0"])), "First Item") + + # Add tags to the item + Locator.click!(Page.locator(page, ~s([data-pw-add-tag="0"]))) + Locator.click!(Page.locator(page, ~s([data-pw-add-tag="0"]))) + Expect.to_have_count!(Page.locator(page, "[data-pw-tag-item]"), 2) + + # Fill tags + Locator.fill!(Page.locator(page, ~s([data-pw-tag-input="0-0"])), "important") + Locator.fill!(Page.locator(page, ~s([data-pw-tag-input="0-1"])), "urgent") + + # Add second item + Locator.click!(Page.locator(page, "[data-pw-add-item]")) + Expect.to_have_count!(Page.locator(page, "[data-pw-item]"), 2) + + # Fill second item + Locator.fill!(Page.locator(page, ~s([data-pw-item-title="1"])), "Second Item") + Locator.click!(Page.locator(page, ~s([data-pw-add-tag="1"]))) + Locator.fill!(Page.locator(page, ~s([data-pw-tag-input="1-0"])), "normal") + + # Remove first tag from first item + Locator.click!(Page.locator(page, ~s([data-pw-remove-tag="0-0"]))) + + # Should have one tag left in first item + first_item_tags = Page.locator(page, ~s([data-pw-item="0"] [data-pw-tag-item])) + Expect.to_have_count!(first_item_tags, 1) + Expect.to_have_value!(Page.locator(page, ~s([data-pw-tag-input="0-0"])), "urgent") + + # Remove first item entirely + Locator.click!(Page.locator(page, ~s([data-pw-remove-item="0"]))) + Expect.to_have_count!(Page.locator(page, "[data-pw-item]"), 1) + + # Remaining item should be "Second Item" + Expect.to_have_value!(Page.locator(page, ~s([data-pw-item-title="0"])), "Second Item") + end + + test "form validation lifecycle with server errors", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + + # Fill invalid data that will trigger server validation + # Too short + Locator.fill!(name_input, "A") + # Invalid format + Locator.fill!(email_input, "invalid-email") + Locator.blur!(name_input) + Locator.blur!(email_input) + Locator.check!(accept_terms_checkbox) + sync_lv(page) + + # Should show validation errors + Expect.to_be_visible!(Page.locator(page, "[data-pw-name-error]")) + Expect.to_be_visible!(Page.locator(page, "[data-pw-email-error]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Fix the name + Locator.fill!(name_input, "John Doe") + Locator.blur!(name_input) + sync_lv(page) + + # Name error should be gone, email error should remain + page |> Page.locator("[data-pw-name-error]") |> Expect.not_() |> Expect.to_be_visible!() + Expect.to_be_visible!(Page.locator(page, "[data-pw-email-error]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Fix the email + Locator.fill!(email_input, "john@example.com") + Locator.blur!(email_input) + sync_lv(page) + + # All errors should be gone + page |> Page.locator("[data-pw-name-error]") |> Expect.not_() |> Expect.to_be_visible!() + page |> Page.locator("[data-pw-email-error]") |> Expect.not_() |> Expect.to_be_visible!() + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + end + + test "form submission with valid data", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + age_input = Page.locator(page, "[data-pw-age-input]") + bio_input = Page.locator(page, "[data-pw-bio-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + + # Fill valid form data + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.fill!(age_input, "30") + Locator.fill!(bio_input, "This is a comprehensive bio with sufficient content for validation") + Locator.check!(accept_terms_checkbox) + # let's wait for the debounce to finish + Page.wait_for_timeout!(page, 150) + sync_lv(page) + + # Add some skills + Locator.click!(Page.locator(page, "[data-pw-add-skill]")) + Locator.fill!(Page.locator(page, ~s([data-pw-skill-input="0"])), "JavaScript") + Locator.click!(Page.locator(page, "[data-pw-add-skill]")) + Locator.fill!(Page.locator(page, ~s([data-pw-skill-input="1"])), "Vue.js") + + # Add an item with tags + Locator.click!(Page.locator(page, "[data-pw-add-item]")) + Locator.fill!(Page.locator(page, ~s([data-pw-item-title="0"])), "Build awesome apps") + Locator.click!(Page.locator(page, ~s([data-pw-add-tag="0"]))) + Locator.fill!(Page.locator(page, ~s([data-pw-tag-input="0-0"])), "development") + + sync_lv(page) + + # Form should be valid + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + Expect.to_be_enabled!(Page.locator(page, "[data-pw-submit]")) + + # Submit the form + Locator.click!(Page.locator(page, "[data-pw-submit]")) + sync_lv(page) + + # Form should be reset after successful submission + Expect.to_have_value!(Page.locator(page, "[data-pw-name-input]"), "") + Expect.to_have_value!(Page.locator(page, "[data-pw-email-input]"), "") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-touched]"), "Touched: false") + end + + test "form reset functionality", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + + # Fill some data + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.click!(Page.locator(page, "[data-pw-add-skill]")) + Locator.fill!(Page.locator(page, ~s([data-pw-skill-input="0"])), "JavaScript") + + sync_lv(page) + + # Form should be dirty + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: true") + + # Reset the form + Locator.click!(Page.locator(page, "[data-pw-reset]")) + + # Form should be clean + Expect.to_have_value!(Page.locator(page, "[data-pw-name-input]"), "") + Expect.to_have_value!(Page.locator(page, "[data-pw-email-input]"), "") + Expect.to_have_count!(Page.locator(page, "[data-pw-skill-item]"), 0) + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-touched]"), "Touched: false") + end + + test "debounced validation events", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + + # Type rapidly to test debouncing + Locator.focus!(name_input) + Locator.press_sequentially!(name_input, "John", delay: 50) + + # Should not trigger validation immediately + Page.wait_for_timeout!(page, 100) + + # Continue typing + Locator.press_sequentially!(name_input, " Doe", delay: 50) + + # Wait for debounce period (300ms) plus some buffer + Page.wait_for_timeout!(page, 400) + sync_lv(page) + + # Should have final value and validation should have occurred + Expect.to_have_value!(name_input, "John Doe") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: true") + end + + test "accessibility attributes are properly set", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + + # Fill invalid data to trigger errors + Locator.fill!(name_input, "A") + Locator.fill!(email_input, "invalid") + Locator.blur!(name_input) + Locator.blur!(email_input) + sync_lv(page) + + # Check aria-invalid attributes + Expect.to_have_attribute!(name_input, "aria-invalid", "true") + Expect.to_have_attribute!(email_input, "aria-invalid", "true") + + # Check aria-describedby attributes + Expect.to_have_attribute!(name_input, "aria-describedby") + Expect.to_have_attribute!(email_input, "aria-describedby") + + # Fix the errors + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.blur!(name_input) + Locator.blur!(email_input) + sync_lv(page) + + # Aria-invalid should be false + Expect.to_have_attribute!(name_input, "aria-invalid", "false") + Expect.to_have_attribute!(email_input, "aria-invalid", "false") + end + + test "form maintains state during LiveView updates", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + + # Start filling the form + Locator.focus!(name_input) + Locator.fill!(name_input, "John") + + # Trigger a server action that might update the form + Locator.fill!(email_input, "john@example.com") + Locator.blur!(email_input) + sync_lv(page) + + # Continue editing the name field while server processes + Locator.focus!(name_input) + Locator.fill!(name_input, "John Doe") + + # The name field should retain the user's input + Expect.to_have_value!(name_input, "John Doe") + Expect.to_have_value!(email_input, "john@example.com") + end + + test "complex nested validation with items and tags", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + + # Fill required fields + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.check!(accept_terms_checkbox) + + # Add item with invalid title (too short) + Locator.click!(Page.locator(page, "[data-pw-add-item]")) + # Too short + Locator.fill!(Page.locator(page, ~s([data-pw-item-title="0"])), "Hi") + Locator.blur!(Page.locator(page, ~s([data-pw-item-title="0"]))) + sync_lv(page) + + # Form should be invalid due to item validation + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Fix the item title + Locator.fill!(Page.locator(page, ~s([data-pw-item-title="0"])), "Valid Item Title") + Locator.blur!(Page.locator(page, ~s([data-pw-item-title="0"]))) + sync_lv(page) + + # Form should be valid now + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + + # Add a short tag (which should be invalid) + Locator.click!(Page.locator(page, ~s([data-pw-add-tag="0"]))) + Locator.fill!(Page.locator(page, ~s([data-pw-tag-input="0-0"])), "a") + Locator.blur!(Page.locator(page, ~s([data-pw-tag-input="0-0"]))) + sync_lv(page) + + # Form should be invalid due to short tag + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Fill the tag + Locator.fill!(Page.locator(page, ~s([data-pw-tag-input="0-0"])), "valid-tag") + Locator.blur!(Page.locator(page, ~s([data-pw-tag-input="0-0"]))) + sync_lv(page) + + # Form should be valid again + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + end + + test "single checkbox functionality", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + newsletter_checkbox = Page.locator(page, "[data-pw-newsletter]") + + # Fill required fields first + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + sync_lv(page) + + # Initially checkboxes should be unchecked + accept_terms_checkbox |> Expect.not_() |> Expect.to_be_checked!() + newsletter_checkbox |> Expect.not_() |> Expect.to_be_checked!() + + # Form should be invalid because acceptTerms is required + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + + # Check accept terms + Locator.check!(accept_terms_checkbox) + sync_lv(page) + + # Form should now be valid + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + Expect.to_be_checked!(accept_terms_checkbox) + newsletter_checkbox |> Expect.not_() |> Expect.to_be_checked!() + + # Check newsletter (optional) + Locator.check!(newsletter_checkbox) + sync_lv(page) + + # Form should still be valid, both checkboxes checked + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + Expect.to_be_checked!(accept_terms_checkbox) + Expect.to_be_checked!(newsletter_checkbox) + + # Uncheck accept terms - form should become invalid + Locator.uncheck!(accept_terms_checkbox) + sync_lv(page) + + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: false") + accept_terms_checkbox |> Expect.not_() |> Expect.to_be_checked!() + Expect.to_be_checked!(newsletter_checkbox) + + # Should show error message for accept terms + Expect.to_be_visible!(Page.locator(page, "[data-pw-accept-terms-error]")) + end + + test "multi-checkbox array functionality", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + email_pref_checkbox = Page.locator(page, "[data-pw-preferences-email]") + sms_pref_checkbox = Page.locator(page, "[data-pw-preferences-sms]") + push_pref_checkbox = Page.locator(page, "[data-pw-preferences-push]") + + sync_debounced_form = fn -> + Page.wait_for_timeout!(page, 350) + sync_lv(page) + end + + # Fill required fields + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.check!(accept_terms_checkbox) + sync_lv(page) + + # Initially all preference checkboxes should be unchecked + email_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + sms_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + push_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + + # Check email preference + Locator.check!(email_pref_checkbox) + sync_debounced_form.() + + Expect.to_be_checked!(email_pref_checkbox) + sms_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + push_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + + # Check SMS preference as well + Locator.check!(sms_pref_checkbox) + sync_debounced_form.() + + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(sms_pref_checkbox) + push_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + + # Check all preferences + Locator.check!(push_pref_checkbox) + sync_debounced_form.() + + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(sms_pref_checkbox) + Expect.to_be_checked!(push_pref_checkbox) + + # Uncheck middle one (SMS) + Locator.uncheck!(sms_pref_checkbox) + sync_debounced_form.() + + Expect.to_be_checked!(email_pref_checkbox) + sms_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + Expect.to_be_checked!(push_pref_checkbox) + + # Uncheck all + Locator.uncheck!(email_pref_checkbox) + Locator.uncheck!(push_pref_checkbox) + sync_debounced_form.() + + email_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + sms_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + push_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + end + + test "checkbox state persistence during form operations", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + newsletter_checkbox = Page.locator(page, "[data-pw-newsletter]") + email_pref_checkbox = Page.locator(page, "[data-pw-preferences-email]") + sms_pref_checkbox = Page.locator(page, "[data-pw-preferences-sms]") + + # Fill form with valid data and check some boxes + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.check!(accept_terms_checkbox) + Locator.check!(newsletter_checkbox) + Locator.check!(email_pref_checkbox) + Locator.check!(sms_pref_checkbox) + sync_lv(page) + + # Verify all are checked + Expect.to_be_checked!(accept_terms_checkbox) + Expect.to_be_checked!(newsletter_checkbox) + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(sms_pref_checkbox) + + # Add some dynamic content (array items) to trigger more server updates + Locator.click!(Page.locator(page, "[data-pw-add-skill]")) + Locator.fill!(Page.locator(page, ~s([data-pw-skill-input="0"])), "JavaScript") + sync_lv(page) + + # Checkbox states should be preserved + Expect.to_be_checked!(accept_terms_checkbox) + Expect.to_be_checked!(newsletter_checkbox) + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(sms_pref_checkbox) + + # Make some changes to trigger validation + # Too short, will cause validation error + Locator.fill!(name_input, "J") + Locator.blur!(name_input) + sync_lv(page) + + # Checkbox states should still be preserved even with validation errors + Expect.to_be_checked!(accept_terms_checkbox) + Expect.to_be_checked!(newsletter_checkbox) + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(sms_pref_checkbox) + + # Fix the name + Locator.fill!(name_input, "John Doe") + Locator.blur!(name_input) + sync_lv(page) + + # Checkbox states should still be preserved + Expect.to_be_checked!(accept_terms_checkbox) + Expect.to_be_checked!(newsletter_checkbox) + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(sms_pref_checkbox) + end + + test "checkbox form reset functionality", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + newsletter_checkbox = Page.locator(page, "[data-pw-newsletter]") + email_pref_checkbox = Page.locator(page, "[data-pw-preferences-email]") + push_pref_checkbox = Page.locator(page, "[data-pw-preferences-push]") + + # Fill form and check boxes + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.check!(accept_terms_checkbox) + Locator.check!(newsletter_checkbox) + Locator.check!(email_pref_checkbox) + Locator.check!(push_pref_checkbox) + sync_lv(page) + + # Verify everything is set + Expect.to_be_checked!(accept_terms_checkbox) + Expect.to_be_checked!(newsletter_checkbox) + Expect.to_be_checked!(email_pref_checkbox) + Expect.to_be_checked!(push_pref_checkbox) + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: true") + + # Reset the form + Locator.click!(Page.locator(page, "[data-pw-reset]")) + + # All checkboxes should be unchecked + accept_terms_checkbox |> Expect.not_() |> Expect.to_be_checked!() + newsletter_checkbox |> Expect.not_() |> Expect.to_be_checked!() + email_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + push_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: false") + end + + test "checkbox form submission with all checkbox states", %{page: page} do + name_input = Page.locator(page, "[data-pw-name-input]") + email_input = Page.locator(page, "[data-pw-email-input]") + age_input = Page.locator(page, "[data-pw-age-input]") + accept_terms_checkbox = Page.locator(page, "[data-pw-accept-terms]") + newsletter_checkbox = Page.locator(page, "[data-pw-newsletter]") + email_pref_checkbox = Page.locator(page, "[data-pw-preferences-email]") + sms_pref_checkbox = Page.locator(page, "[data-pw-preferences-sms]") + + # Fill form with valid data + Locator.fill!(name_input, "John Doe") + Locator.fill!(email_input, "john@example.com") + Locator.fill!(age_input, "30") + Locator.check!(accept_terms_checkbox) + Locator.check!(newsletter_checkbox) + Locator.check!(email_pref_checkbox) + Locator.check!(sms_pref_checkbox) + + # Add bio to make form valid + bio_input = Page.locator(page, "[data-pw-bio-input]") + Locator.fill!(bio_input, "This is a comprehensive bio with sufficient content for validation") + + sync_lv(page) + + # Form should be valid + Expect.to_have_text!(Page.locator(page, "[data-pw-is-valid]"), "Valid: true") + Expect.to_be_enabled!(Page.locator(page, "[data-pw-submit]")) + + # Submit the form + Locator.click!(Page.locator(page, "[data-pw-submit]")) + sync_lv(page) + + # Form should be reset after successful submission + accept_terms_checkbox |> Expect.not_() |> Expect.to_be_checked!() + newsletter_checkbox |> Expect.not_() |> Expect.to_be_checked!() + email_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + sms_pref_checkbox |> Expect.not_() |> Expect.to_be_checked!() + Expect.to_have_text!(Page.locator(page, "[data-pw-is-dirty]"), "Dirty: false") + Expect.to_have_text!(Page.locator(page, "[data-pw-is-touched]"), "Touched: false") + end + end +end diff --git a/e2e_pw/headless_test.exs b/e2e_pw/headless_test.exs new file mode 100644 index 00000000..d53b3d90 --- /dev/null +++ b/e2e_pw/headless_test.exs @@ -0,0 +1,41 @@ +defmodule LiveVue.E2E.HeadlessTest do + use LiveVue.E2E.Case, async: true + + test "headless component exposes reactive props via useLiveVue(elementId)", %{page: page} do + Page.goto!(page, "/headless") + sync_lv(page) + + Expect.to_have_text!(Page.locator(page, "[data-pw-count]"), "0") + Expect.to_have_text!(Page.locator(page, "[data-pw-label]"), "Hello") + + Locator.click!(Page.locator(page, "[data-pw-increment]")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, "[data-pw-count]"), "1") + + Locator.click!(Page.locator(page, "[data-pw-increment]")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, "[data-pw-count]"), "2") + end + + test "headless component updates non-numeric props reactively", %{page: page} do + Page.goto!(page, "/headless") + sync_lv(page) + + Expect.to_have_text!(Page.locator(page, "[data-pw-label]"), "Hello") + + Locator.fill!(Page.locator(page, "[data-pw-label-input]"), "Updated") + Locator.click!(Page.locator(page, "[data-pw-update-label]")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, "[data-pw-label]"), "Updated") + end + + test "headless component renders no visible UI", %{page: page} do + Page.goto!(page, "/headless") + sync_lv(page) + + headless_el = Page.locator(page, "#data-source") + Expect.to_be_attached!(headless_el) + headless_el |> Expect.not_() |> Expect.to_have_attribute!("data-name") + Expect.to_have_text!(headless_el, "") + end +end diff --git a/e2e_pw/navigation_test.exs b/e2e_pw/navigation_test.exs new file mode 100644 index 00000000..f0907d2b --- /dev/null +++ b/e2e_pw/navigation_test.exs @@ -0,0 +1,54 @@ +defmodule LiveVue.E2E.NavigationTest do + use LiveVue.E2E.Case, async: true + + describe "useLiveNavigation" do + test "should patch query params and navigate between routes", %{page: page} do + # Start at the first navigation route + Page.goto!(page, "/navigation/test1") + sync_lv(page) + + # Verify initial state + Expect.to_contain_text!(Page.locator(page, "#current-params"), ~s("page":"test1")) + Expect.to_contain_text!(Page.locator(page, "#current-query"), "{}") + + # Test patch functionality - should update query params + Page.click!(page, "#patch-btn") + sync_lv(page) + + # Verify query params were updated + Expect.to_contain_text!(Page.locator(page, "#current-query"), ~s("foo":"bar")) + Expect.to_contain_text!(Page.locator(page, "#current-query"), ~s("timestamp")) + # URL should still have the same page param but with query params + Expect.to_have_url!(page, ~r"/navigation/test1\?.*foo=bar") + + # Test navigate functionality - should change to alt route + Page.click!(page, "#navigate-btn") + sync_lv(page) + + # Verify navigation to alt route + Expect.to_contain_text!(Page.locator(page, "#current-params"), ~s("page":"test2")) + Expect.to_contain_text!(Page.locator(page, "#current-query"), ~s("baz":"qux")) + Expect.to_have_url!(page, ~r"/navigation/alt/test2\?.*baz=qux") + + # Test navigate back + Page.click!(page, "#navigate-back-btn") + sync_lv(page) + + # Verify navigation back to original route + Expect.to_contain_text!(Page.locator(page, "#current-params"), ~s("page":"test1")) + Expect.to_contain_text!(Page.locator(page, "#current-query"), "{}") + Expect.to_have_url!(page, "/navigation/test1") + end + + test "should handle direct route access with params", %{page: page} do + # Test direct access to alt route with query params + Page.goto!(page, "/navigation/alt/direct?test=value&count=42") + sync_lv(page) + + # Verify params and query params are correctly parsed + Expect.to_contain_text!(Page.locator(page, "#current-params"), ~s("page":"direct")) + Expect.to_contain_text!(Page.locator(page, "#current-query"), ~s("test":"value")) + Expect.to_contain_text!(Page.locator(page, "#current-query"), ~s("count":"42")) + end + end +end diff --git a/e2e_pw/persistent_layout_test.exs b/e2e_pw/persistent_layout_test.exs new file mode 100644 index 00000000..1ca2bce6 --- /dev/null +++ b/e2e_pw/persistent_layout_test.exs @@ -0,0 +1,80 @@ +defmodule LiveVue.E2E.PersistentLayoutTest do + use LiveVue.E2E.Case, async: true + + defp wait_for_page(page, text) do + Expect.to_have_text!(Page.locator(page, "[data-pw-page]"), text, timeout: 5000) + end + + test "SSR renders the injected layout tree before hydration", %{browser: browser} do + context = Browser.new_context!(browser, java_script_enabled: false) + page = BrowserContext.new_page!(context) + + Page.goto!(page, "/persistent-layout/page1") + + Expect.to_have_text!(Page.locator(page, "[data-pw-layout-counter]"), "0") + Expect.to_have_text!(Page.locator(page, "[data-pw-page]"), "page1") + Expect.to_have_text!(Page.locator(page, "[data-pw-nested]"), "I'm nested!") + Expect.to_contain_text!(Page.locator(page, "[data-pw-sidebar-content]"), "Sidebar") + + BrowserContext.close!(context) + end + + test "layout state persists across push_patch navigation", %{page: page} do + Page.goto!(page, "/persistent-layout/page1") + sync_lv(page) + wait_for_page(page, "page1") + + # Increment layout counter a few times + Locator.click!(Page.locator(page, "[data-pw-layout-btn]")) + Locator.click!(Page.locator(page, "[data-pw-layout-btn]")) + Locator.click!(Page.locator(page, "[data-pw-layout-btn]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-layout-counter]"), "3") + + # Navigate to page2 via push_patch + eval_lv(page, ~s|{:noreply, Phoenix.LiveView.push_patch(socket, to: "/persistent-layout/page2")}|) + sync_lv(page) + wait_for_page(page, "page2") + + # Layout counter should be preserved (Vue state survived navigation) + Expect.to_have_text!(Page.locator(page, "[data-pw-layout-counter]"), "3") + + # Page component should see layout counter via slot props + Expect.to_have_text!(Page.locator(page, "[data-pw-page-layout-count]"), "3") + + # Incrementing layout counter should update in both places + Locator.click!(Page.locator(page, "[data-pw-layout-btn]")) + Expect.to_have_text!(Page.locator(page, "[data-pw-layout-counter]"), "4") + Expect.to_have_text!(Page.locator(page, "[data-pw-page-layout-count]"), "4") + end + + test "nested injection: component injected into an injected component", %{page: page} do + Page.goto!(page, "/persistent-layout/page1") + sync_lv(page) + wait_for_page(page, "page1") + + # Nested component should render inside the page component's slot + Expect.to_have_text!(Page.locator(page, "[data-pw-nested]"), "I'm nested!") + + # Navigate — nested should survive (it's inside the persistent layout tree) + eval_lv(page, ~s|{:noreply, Phoenix.LiveView.push_patch(socket, to: "/persistent-layout/page2")}|) + sync_lv(page) + wait_for_page(page, "page2") + + # Nested component should still be there + Expect.to_have_text!(Page.locator(page, "[data-pw-nested]"), "I'm nested!", timeout: 5000) + end + + test "named slot injection via v-inject:slotname", %{page: page} do + Page.goto!(page, "/persistent-layout/page1") + sync_lv(page) + wait_for_page(page, "page1") + + # Sidebar should render in the named slot with slot props + Expect.to_contain_text!(Page.locator(page, "[data-pw-sidebar-content]"), "Sidebar") + Expect.to_contain_text!(Page.locator(page, "[data-pw-sidebar-content]"), "layout: 0") + + # Incrementing layout counter should update sidebar's slot props too + Locator.click!(Page.locator(page, "[data-pw-layout-btn]")) + Expect.to_contain_text!(Page.locator(page, "[data-pw-sidebar-content]"), "layout: 1") + end +end diff --git a/e2e_pw/prop_diff_test.exs b/e2e_pw/prop_diff_test.exs new file mode 100644 index 00000000..52d766b1 --- /dev/null +++ b/e2e_pw/prop_diff_test.exs @@ -0,0 +1,229 @@ +defmodule LiveVue.E2E.PropDiffTest do + use LiveVue.E2E.Case, async: true + + # Read and parse props from the page + defp get_props(page) do + sync_lv(page) + + props_json = Locator.text_content!(Page.locator(page, ~s([data-testid="props-json"]))) + Jason.decode!(props_json) + end + + describe "LiveVue Prop Diff E2E Tests" do + setup %{page: page} do + Page.goto!(page, "/prop-diff-test") + sync_lv(page) + + # Verify Vue component is mounted + Expect.to_be_visible!(Page.locator(page, ~s([phx-hook="VueHook"]))) + :ok + end + + test "initial render displays all props correctly", %{page: page} do + # Check initial props are rendered + props = get_props(page) + + assert props["simple_string"] == "hello" + assert props["simple_number"] == 42 + assert props["simple_boolean"] == true + assert props["simple_list"] == ["a", "b", "c"] + assert props["simple_map"] == %{"key1" => "value1", "key2" => "value2"} + assert props["nested_data"]["user"] == %{"name" => "John", "age" => 30} + assert props["nested_data"]["settings"] == %{"theme" => "dark", "notifications" => true} + + assert props["list_of_maps"] == [ + %{"id" => 1, "name" => "Alice", "role" => "admin"}, + %{"id" => 2, "name" => "Bob", "role" => "user"} + ] + end + + test "simple string change is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-string"]))) + + props = get_props(page) + + assert props["simple_string"] == "changed" + # Other props should remain unchanged + assert props["simple_number"] == 42 + assert props["simple_boolean"] == true + end + + test "simple number change is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-number"]))) + + props = get_props(page) + + assert props["simple_number"] == 99 + # Other props should remain unchanged + assert props["simple_string"] == "hello" + assert props["simple_boolean"] == true + end + + test "boolean toggle is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-toggle-boolean"]))) + + props = get_props(page) + + assert props["simple_boolean"] == false + + # Toggle back + Locator.click!(Page.locator(page, ~s([data-testid="btn-toggle-boolean"]))) + + props2 = get_props(page) + assert props2["simple_boolean"] == true + end + + test "array addition is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-add-to-list"]))) + + props = get_props(page) + + assert props["simple_list"] == ["a", "b", "c", "d"] + end + + test "array removal is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-remove-from-list"]))) + + props = get_props(page) + + assert props["simple_list"] == ["b", "c"] + end + + test "array replacement is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-replace-in-list"]))) + + props = get_props(page) + + assert props["simple_list"] == ["a", "REPLACED", "c"] + end + + test "map addition is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-add-to-map"]))) + + props = get_props(page) + + assert props["simple_map"] == %{ + "key1" => "value1", + "key2" => "value2", + "key3" => "value3" + } + end + + test "map removal is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-remove-from-map"]))) + + props = get_props(page) + + assert props["simple_map"] == %{"key2" => "value2"} + end + + test "nested object property change is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-nested-name"]))) + + props = get_props(page) + + assert props["nested_data"]["user"]["name"] == "Jane" + # Other nested properties should remain unchanged + assert props["nested_data"]["user"]["age"] == 30 + assert props["nested_data"]["settings"] == %{"theme" => "dark", "notifications" => true} + end + + test "nested object number change is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-nested-age"]))) + + props = get_props(page) + + assert props["nested_data"]["user"]["age"] == 25 + # Other properties should remain unchanged + assert props["nested_data"]["user"]["name"] == "John" + end + + test "adding nested property is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-add-nested-setting"]))) + + props = get_props(page) + + assert props["nested_data"]["settings"] == %{ + "theme" => "dark", + "notifications" => true, + "language" => "en" + } + end + + test "setting value to nil is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-set-nil"]))) + + props = get_props(page) + + assert props["simple_string"] == nil + # Other props should remain unchanged + assert props["simple_number"] == 42 + assert props["simple_boolean"] == true + end + + test "adding item to list of maps is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-add-list-item"]))) + + props = get_props(page) + + assert props["list_of_maps"] == [ + %{"id" => 1, "name" => "Alice", "role" => "admin"}, + %{"id" => 2, "name" => "Bob", "role" => "user"}, + %{"id" => 3, "name" => "Charlie", "role" => "guest"} + ] + end + + test "updating item in list of maps is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-update-list-item"]))) + + props = get_props(page) + + assert props["list_of_maps"] == [ + %{"id" => 1, "name" => "Alice Updated", "role" => "admin"}, + %{"id" => 2, "name" => "Bob", "role" => "user"} + ] + end + + test "removing item from list of maps is applied via diff", %{page: page} do + Locator.click!(Page.locator(page, ~s([data-testid="btn-remove-list-item"]))) + + props = get_props(page) + + assert props["list_of_maps"] == [%{"id" => 1, "name" => "Alice", "role" => "admin"}] + end + + test "multiple consecutive changes are applied correctly", %{page: page} do + # Make multiple changes in sequence + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-string"]))) + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-number"]))) + Locator.click!(Page.locator(page, ~s([data-testid="btn-add-to-list"]))) + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-nested-name"]))) + + props = get_props(page) + + assert props["simple_string"] == "changed" + assert props["simple_number"] == 99 + assert props["simple_list"] == ["a", "b", "c", "d"] + assert props["nested_data"]["user"]["name"] == "Jane" + + # Unchanged properties should remain the same + assert props["simple_boolean"] == true + assert props["nested_data"]["user"]["age"] == 30 + end + + test "Vue component can access all updated props reactively", %{page: page} do + # Verify that Vue component reactively updates when props change + initial = get_props(page) + + # Make a change + Locator.click!(Page.locator(page, ~s([data-testid="btn-change-string"]))) + + # Wait for Vue to update (should be immediate) + updated = get_props(page) + + # Verify the change is reflected immediately in the Vue component + assert updated["simple_string"] == "changed" + refute updated["simple_string"] == initial["simple_string"] + end + end +end diff --git a/e2e_pw/reconnect_test.exs b/e2e_pw/reconnect_test.exs new file mode 100644 index 00000000..faae46c0 --- /dev/null +++ b/e2e_pw/reconnect_test.exs @@ -0,0 +1,72 @@ +defmodule LiveVue.E2E.ReconnectTest do + use LiveVue.E2E.Case, async: true + + defp reconnect(page) do + Page.evaluate!(page, """ + () => { + return new Promise(resolve => { + window.liveSocket.disconnect(() => { + setTimeout(() => { + window.liveSocket.connect() + resolve() + }, 200) + }) + }) + } + """) + + sync_lv(page) + end + + describe "LiveVue Reconnect" do + test "props are refreshed from server after socket reconnect", %{page: page} do + Page.goto!(page, "/reconnect") + sync_lv(page) + + # Verify initial state + Expect.to_have_text!(Page.locator(page, "[data-pw-count]"), "0") + Expect.to_have_text!(Page.locator(page, "[data-pw-label]"), "initial") + + # Update state — this sends a diff via data-props-diff + Locator.click!(Page.locator(page, "button")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, "[data-pw-count]"), "1") + Expect.to_have_text!(Page.locator(page, "[data-pw-label]"), "updated") + + # Disconnect and reconnect. + # Without the fix, the stale data-props-diff from the last update + # would be re-applied, leaving Vue showing the old state. + reconnect(page) + + # New process mounted with initial state — Vue must reflect that + Expect.to_have_text!(Page.locator(page, "[data-pw-count]"), "0") + Expect.to_have_text!(Page.locator(page, "[data-pw-label]"), "initial") + end + + test "streams are restored after socket reconnect", %{page: page} do + Page.goto!(page, "/reconnect") + sync_lv(page) + + # Verify initial stream: 3 items + Expect.to_have_text!(Page.locator(page, "[data-pw-item-count]"), "3") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='1']"), "Alpha") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='2']"), "Beta") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='3']"), "Gamma") + + # Update — adds a 4th stream item + Locator.click!(Page.locator(page, "button")) + sync_lv(page) + Expect.to_have_text!(Page.locator(page, "[data-pw-item-count]"), "4") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='4']"), "Delta") + + # Reconnect — new process re-mounts with only the original 3 items + reconnect(page) + + Expect.to_have_text!(Page.locator(page, "[data-pw-item-count]"), "3") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='1']"), "Alpha") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='2']"), "Beta") + Expect.to_have_text!(Page.locator(page, "[data-pw-item='3']"), "Gamma") + Expect.to_have_count!(Page.locator(page, "[data-pw-item='4']"), 0) + end + end +end diff --git a/e2e_pw/slot_test.exs b/e2e_pw/slot_test.exs new file mode 100644 index 00000000..c7edfe4e --- /dev/null +++ b/e2e_pw/slot_test.exs @@ -0,0 +1,39 @@ +defmodule LiveVue.E2E.SlotTest do + use LiveVue.E2E.Case, async: true + + defp slot(page, label) do + page + |> Page.locator(~s|[data-pw-label]:has-text("#{label}")|) + |> Locator.locator("..") + |> Locator.locator("[data-pw-slot]") + end + + describe "LiveVue Slot Non-ASCII Character Tests" do + test "renders non-ASCII characters in slots correctly", %{page: page} do + Page.goto!(page, "/slot-test") + sync_lv(page) + + # Test 1: Polish characters + polish_slot = slot(page, "Polish") + Expect.to_contain_text!(polish_slot, "Zażółć gęślą jaźń") + + # Test 2: Japanese characters + japanese_slot = slot(page, "Japanese") + Expect.to_contain_text!(japanese_slot, "こんにちは世界") + + # Test 3: Emoji + emoji_slot = slot(page, "Emoji") + Expect.to_contain_text!(emoji_slot, "Hello 🌍 World 🎉 Party 🚀") + + # Test 4: Mixed scripts (Russian, Chinese, Arabic) + mixed_slot = slot(page, "Mixed") + Expect.to_contain_text!(mixed_slot, "Привет мир!") + Expect.to_contain_text!(mixed_slot, "你好世界!") + Expect.to_contain_text!(mixed_slot, "مرحبا بالعالم") + + # Test 5: Special Latin characters + special_slot = slot(page, "Special") + Expect.to_contain_text!(special_slot, "Ñoño café résumé naïve") + end + end +end diff --git a/e2e_pw/stream_test.exs b/e2e_pw/stream_test.exs new file mode 100644 index 00000000..371c46d9 --- /dev/null +++ b/e2e_pw/stream_test.exs @@ -0,0 +1,463 @@ +defmodule LiveVue.E2E.StreamTest do + use LiveVue.E2E.Case, async: true + + alias Playwright.Dialog + + setup %{page: page} do + Page.goto!(page, "/streams") + sync_lv(page) + :ok + end + + describe "LiveVue Stream Integration" do + test "renders initial stream items", %{page: page} do + # Check that initial items are rendered + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-1"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-2"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-3"]))) + + # Check item content + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-name"])), "Item 1") + + Expect.to_have_text!( + Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-description"])), + "First item" + ) + + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-id"])), "ID: 1") + + # Check item count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (3)") + end + + test "adds new items to stream", %{page: page} do + # Fill form and add new item + Page.fill!(page, ~s([data-testid="name-input"]), "New Item") + Page.fill!(page, ~s([data-testid="description-input"]), "This is a new item") + Page.click!(page, ~s([data-testid="add-button"])) + + sync_lv(page) + + # Check that new item appears + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-4"]))) + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"])), "New Item") + + Expect.to_have_text!( + Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-description"])), + "This is a new item" + ) + + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-id"])), "ID: 4") + + # Check updated count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (4)") + + # Check that form was cleared + Expect.to_have_value!(Page.locator(page, ~s([data-testid="name-input"])), "") + Expect.to_have_value!(Page.locator(page, ~s([data-testid="description-input"])), "") + end + + test "adds multiple items in sequence", %{page: page} do + # Add first item + Page.fill!(page, ~s([data-testid="name-input"]), "Item A") + Page.fill!(page, ~s([data-testid="description-input"]), "Description A") + Page.click!(page, ~s([data-testid="add-button"])) + sync_lv(page) + + # Add second item + Page.fill!(page, ~s([data-testid="name-input"]), "Item B") + Page.fill!(page, ~s([data-testid="description-input"]), "Description B") + Page.click!(page, ~s([data-testid="add-button"])) + sync_lv(page) + + # Check both items exist + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-4"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-5"]))) + + # Check count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (5)") + end + + test "removes individual items from stream", %{page: page} do + # Remove item 2 + Page.click!(page, ~s([data-testid="remove-2"])) + sync_lv(page) + + # Check that item 2 is gone but others remain + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-1"]))) + page |> Page.locator(~s([data-testid="item-2"])) |> Expect.not_() |> Expect.to_be_visible!() + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-3"]))) + + # Check updated count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (2)") + end + + test "removes multiple items", %{page: page} do + # Remove items 1 and 3 + Page.click!(page, ~s([data-testid="remove-1"])) + sync_lv(page) + Page.click!(page, ~s([data-testid="remove-3"])) + sync_lv(page) + + # Check only item 2 remains + page |> Page.locator(~s([data-testid="item-1"])) |> Expect.not_() |> Expect.to_be_visible!() + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-2"]))) + page |> Page.locator(~s([data-testid="item-3"])) |> Expect.not_() |> Expect.to_be_visible!() + + # Check count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (1)") + end + + test "clears entire stream", %{page: page} do + # Clear all items + Page.click!(page, ~s([data-testid="clear-button"])) + sync_lv(page) + + # Check that all items are gone + page |> Page.locator(~s([data-testid="item-1"])) |> Expect.not_() |> Expect.to_be_visible!() + page |> Page.locator(~s([data-testid="item-2"])) |> Expect.not_() |> Expect.to_be_visible!() + page |> Page.locator(~s([data-testid="item-3"])) |> Expect.not_() |> Expect.to_be_visible!() + + # Check empty state + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="empty-message"]))) + Expect.to_have_text!(Page.locator(page, ~s([data-testid="empty-message"])), "No items in the stream") + + # Check count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (0)") + end + + test "resets stream to default state", %{page: page} do + # First clear the stream + Page.click!(page, ~s([data-testid="clear-button"])) + sync_lv(page) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="empty-message"]))) + + # Then reset it + Page.click!(page, ~s([data-testid="reset-button"])) + sync_lv(page) + + # Check that original items are back + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-1"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-2"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-3"]))) + page |> Page.locator(~s([data-testid="empty-message"])) |> Expect.not_() |> Expect.to_be_visible!() + + # Check count + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (3)") + end + + test "handles complex workflow: add, remove, clear, reset", %{page: page} do + # Add a new item + Page.fill!(page, ~s([data-testid="name-input"]), "Workflow Item") + Page.fill!(page, ~s([data-testid="description-input"]), "Testing workflow") + Page.click!(page, ~s([data-testid="add-button"])) + sync_lv(page) + + # Verify we have 4 items + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + Expect.to_have_text!(items_heading, "Items (4)") + + # Remove one original item + Page.click!(page, ~s([data-testid="remove-2"])) + sync_lv(page) + Expect.to_have_text!(items_heading, "Items (3)") + + # Clear all + Page.click!(page, ~s([data-testid="clear-button"])) + sync_lv(page) + Expect.to_have_text!(items_heading, "Items (0)") + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="empty-message"]))) + + # Reset to defaults + Page.click!(page, ~s([data-testid="reset-button"])) + sync_lv(page) + Expect.to_have_text!(items_heading, "Items (3)") + page |> Page.locator(~s([data-testid="empty-message"])) |> Expect.not_() |> Expect.to_be_visible!() + + # Verify the original 3 items are back (not the added one) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-1"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-2"]))) + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="item-3"]))) + page |> Page.locator(~s([data-testid="item-4"])) |> Expect.not_() |> Expect.to_be_visible!() + end + + test "validates form input for adding items", %{page: page} do + # Try to add item with empty name + Page.fill!(page, ~s([data-testid="name-input"]), "") + Page.fill!(page, ~s([data-testid="description-input"]), "Description only") + + # This should trigger an alert (form validation) + Page.on(page, :dialog, fn dialog -> + assert Dialog.message(dialog) == "Please enter a name for the item" + Dialog.accept!(dialog) + end) + + Page.click!(page, ~s([data-testid="add-button"])) + + # Item should not be added + sync_lv(page) + items_heading = Page.locator(page, ~s|h3:has-text("Items")|) + # Still 3 items + Expect.to_have_text!(items_heading, "Items (3)") + end + + test "displays debug information correctly", %{page: page} do + # Check debug info shows correct type and length + Expect.to_be_visible!(Page.locator(page, ~s|.debug-info p:has-text("Items type:")|)) + Expect.to_be_visible!(Page.locator(page, ~s|.debug-info p:has-text("Items length:")|)) + + # Check raw items data is displayed + Expect.to_be_visible!(Page.locator(page, ~s([data-testid="raw-items"]))) + + raw_items_text = Locator.text_content!(Page.locator(page, ~s([data-testid="raw-items"]))) + assert raw_items_text =~ ~s("id") + assert raw_items_text =~ ~s("name") + assert raw_items_text =~ ~s("description") + end + + test "maintains item order during operations", %{page: page} do + # Get initial order + item1_name = Locator.text_content!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-name"]))) + item2_name = Locator.text_content!(Page.locator(page, ~s([data-testid="item-2"] [data-testid="item-name"]))) + item3_name = Locator.text_content!(Page.locator(page, ~s([data-testid="item-3"] [data-testid="item-name"]))) + + assert item1_name == "Item 1" + assert item2_name == "Item 2" + assert item3_name == "Item 3" + + # Add new item (should appear after existing ones) + Page.fill!(page, ~s([data-testid="name-input"]), "Item 4") + Page.fill!(page, ~s([data-testid="description-input"]), "Fourth item") + Page.click!(page, ~s([data-testid="add-button"])) + sync_lv(page) + + # Check that new item appears at the end + item4_name = Locator.text_content!(Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"]))) + assert item4_name == "Item 4" + + # Remove middle item and check order is maintained + Page.click!(page, ~s([data-testid="remove-2"])) + sync_lv(page) + + # Items 1, 3, 4 should still be in correct order + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-name"])), "Item 1") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-3"] [data-testid="item-name"])), "Item 3") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"])), "Item 4") + end + + test "maintains correct item order after stream reset", %{page: page} do + # Add some items and clear to modify the stream + Page.fill!(page, ~s([data-testid="name-input"]), "Extra Item") + Page.fill!(page, ~s([data-testid="description-input"]), "Extra description") + Page.click!(page, ~s([data-testid="add-button"])) + sync_lv(page) + + # Reset the stream + Page.click!(page, ~s([data-testid="reset-button"])) + sync_lv(page) + + # Verify items appear in correct order: Item 1, Item 2, Item 3 + all_items = Locator.all_text_contents!(Page.locator(page, ~s([data-testid="item-name"]))) + assert all_items == ["Item 1", "Item 2", "Item 3"] + + # Reset the stream + Page.click!(page, ~s([data-testid="reset-button-at-0"])) + sync_lv(page) + + # Verify items appear in correct order: Item 1, Item 2, Item 3 + all_reversed_items = Locator.all_text_contents!(Page.locator(page, ~s([data-testid="item-name"]))) + assert all_reversed_items == ["Item 3", "Item 2", "Item 1"] + end + end + + # Limit operation tests (a nested describe in the spec: its beforeEach runs after the outer one) + describe "LiveVue Stream Integration Limit Operations" do + setup %{page: page} do + Page.goto!(page, "/streams") + sync_lv(page) + :ok + end + + test "adds multiple items at start with positive limit", %{page: page} do + # Verify initial state: 3 items + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (3)") + + # Add 3 items at start with limit 5 (should keep first 5 items) + Page.click!(page, ~s([data-testid="add-multiple-start-button"])) + sync_lv(page) + + # Should have 5 items total (3 new + 3 original, but limited to 5) + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (5)") + + # Check that new items are at the start and in correct order + # Expected order: Start Item C, Start Item B, Start Item A, Item 1, Item 2 + # (Note: items are added at position 0 in reverse order) + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-6"] [data-testid="item-name"])), "Start Item C") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-5"] [data-testid="item-name"])), "Start Item B") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"])), "Start Item A") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-name"])), "Item 1") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-2"] [data-testid="item-name"])), "Item 2") + + # Item 3 should be removed due to limit 5 + page |> Page.locator(~s([data-testid="item-3"])) |> Expect.not_() |> Expect.to_be_visible!() + end + + test "adds multiple items at end with negative limit", %{page: page} do + # Verify initial state: 3 items + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (3)") + + # Add 3 items at end with negative limit -5 (should keep last 5 items) + Page.click!(page, ~s([data-testid="add-multiple-end-button"])) + sync_lv(page) + + # Should have 5 items total (3 original + 3 new, but limited to last 5) + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (5)") + + # Check that new items are at the end and original items remain + # Expected order: Item 2, Item 3, End Item X, End Item Y, End Item Z + # (Item 1 should be removed due to negative limit -5) + page |> Page.locator(~s([data-testid="item-1"])) |> Expect.not_() |> Expect.to_be_visible!() + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-2"] [data-testid="item-name"])), "Item 2") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-3"] [data-testid="item-name"])), "Item 3") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"])), "End Item X") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-5"] [data-testid="item-name"])), "End Item Y") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-6"] [data-testid="item-name"])), "End Item Z") + end + + test "adds single item with custom positive limit", %{page: page} do + # Set positive limit to 2 + Page.fill!(page, ~s([data-testid="positive-limit-input"]), "2") + + # Add item with positive limit 2 + Page.click!(page, ~s([data-testid="add-positive-limit-button"])) + sync_lv(page) + + # Should have only 2 items (limited to first 2) + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (2)") + + # Check which items remain (should be original Item 1 and new limited item) + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-name"])), "Item 1") + + Expect.to_have_text!( + Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"])), + "Limited Item +2" + ) + + # Items 2 and 3 should be removed + page |> Page.locator(~s([data-testid="item-2"])) |> Expect.not_() |> Expect.to_be_visible!() + page |> Page.locator(~s([data-testid="item-3"])) |> Expect.not_() |> Expect.to_be_visible!() + end + + test "adds single item with custom negative limit", %{page: page} do + # Set negative limit to 2 + Page.fill!(page, ~s([data-testid="negative-limit-input"]), "2") + + # Add item with negative limit -2 + Page.click!(page, ~s([data-testid="add-negative-limit-button"])) + sync_lv(page) + + # Should have only 2 items (limited to last 2) + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (2)") + + # Check which items remain (should be Item 3 and new limited item) + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-3"] [data-testid="item-name"])), "Item 3") + + Expect.to_have_text!( + Page.locator(page, ~s([data-testid="item-4"] [data-testid="item-name"])), + "Limited Item -2" + ) + + # Items 1 and 2 should be removed + page |> Page.locator(~s([data-testid="item-1"])) |> Expect.not_() |> Expect.to_be_visible!() + page |> Page.locator(~s([data-testid="item-2"])) |> Expect.not_() |> Expect.to_be_visible!() + end + + test "handles limit operations with existing items", %{page: page} do + # First add a regular item to have 4 items total + Page.fill!(page, ~s([data-testid="name-input"]), "Regular Item") + Page.fill!(page, ~s([data-testid="description-input"]), "Regular description") + Page.click!(page, ~s([data-testid="add-button"])) + sync_lv(page) + + # Should have 4 items + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (4)") + + # Now prepend with positive limit 3 + Page.fill!(page, ~s([data-testid="positive-limit-input"]), "3") + Page.click!(page, ~s([data-testid="add-positive-limit-button"])) + sync_lv(page) + + # Should have 3 items (first 3 kept) + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (3)") + + # Check that we have the first item, new regular item, and new limited item + Expect.to_have_text!( + Page.locator(page, ~s([data-testid="item-5"] [data-testid="item-name"])), + "Limited Item +3" + ) + + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-1"] [data-testid="item-name"])), "Item 1") + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-2"] [data-testid="item-name"])), "Item 2") + end + + test "validates limit input constraints", %{page: page} do + # Test that buttons are disabled for invalid inputs + page |> Page.locator(~s([data-testid="add-positive-limit-button"])) |> Expect.not_() |> Expect.to_be_disabled!() + page |> Page.locator(~s([data-testid="add-negative-limit-button"])) |> Expect.not_() |> Expect.to_be_disabled!() + + # Clear inputs should disable buttons + Page.fill!(page, ~s([data-testid="positive-limit-input"]), "") + Page.fill!(page, ~s([data-testid="negative-limit-input"]), "") + + Expect.to_be_disabled!(Page.locator(page, ~s([data-testid="add-positive-limit-button"]))) + Expect.to_be_disabled!(Page.locator(page, ~s([data-testid="add-negative-limit-button"]))) + + # Zero should disable buttons + Page.fill!(page, ~s([data-testid="positive-limit-input"]), "0") + Page.fill!(page, ~s([data-testid="negative-limit-input"]), "0") + + Expect.to_be_disabled!(Page.locator(page, ~s([data-testid="add-positive-limit-button"]))) + Expect.to_be_disabled!(Page.locator(page, ~s([data-testid="add-negative-limit-button"]))) + + # Valid values should enable buttons + Page.fill!(page, ~s([data-testid="positive-limit-input"]), "3") + Page.fill!(page, ~s([data-testid="negative-limit-input"]), "3") + + page |> Page.locator(~s([data-testid="add-positive-limit-button"])) |> Expect.not_() |> Expect.to_be_disabled!() + page |> Page.locator(~s([data-testid="add-negative-limit-button"])) |> Expect.not_() |> Expect.to_be_disabled!() + end + + test "handles limit operations in sequence", %{page: page} do + # Start with positive limit + Page.fill!(page, ~s([data-testid="positive-limit-input"]), "4") + Page.click!(page, ~s([data-testid="add-positive-limit-button"])) + sync_lv(page) + + # Should have 4 items + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (4)") + + # Then apply negative limit + Page.fill!(page, ~s([data-testid="negative-limit-input"]), "2") + Page.click!(page, ~s([data-testid="add-negative-limit-button"])) + sync_lv(page) + + # Should have 2 items (last 2) + Expect.to_have_text!(Page.locator(page, ~s|h3:has-text("Items")|), "Items (2)") + + # Verify it's the limited item and one original item + Expect.to_have_text!(Page.locator(page, ~s([data-testid="item-3"] [data-testid="item-name"])), "Item 3") + + Expect.to_have_text!( + Page.locator(page, ~s([data-testid="item-5"] [data-testid="item-name"])), + "Limited Item -2" + ) + end + end +end diff --git a/e2e_pw/support/case.ex b/e2e_pw/support/case.ex new file mode 100644 index 00000000..dc2d8e26 --- /dev/null +++ b/e2e_pw/support/case.ex @@ -0,0 +1,15 @@ +defmodule LiveVue.E2E.Case do + @moduledoc """ + Case template of the browser suite: `Playwright.Case` (a pooled browser and a context and page per + test, with the defaults of config/) and the suite's helpers. + """ + use ExUnit.CaseTemplate + + using opts do + quote do + use Playwright.Case, unquote(opts) + + import LiveVue.E2E.Utils + end + end +end diff --git a/e2e_pw/support/utils.ex b/e2e_pw/support/utils.ex new file mode 100644 index 00000000..1755490f --- /dev/null +++ b/e2e_pw/support/utils.ex @@ -0,0 +1,56 @@ +defmodule LiveVue.E2E.Utils do + @moduledoc "Helpers for the browser suite." + + alias Playwright.Expect + alias Playwright.Locator + alias Playwright.Page + alias Playwright.Promise + + # Wait for LiveView to be ready and Vue components to be mounted + def sync_lv(page) do + # Use longer timeout for connection - websocket setup can take time under load + connection_timeout = [timeout: 5000] + + promises = [ + Promise.async(fn -> + Expect.to_be_visible!(Locator.first(Page.locator(page, ".phx-connected")), connection_timeout) + end), + Promise.async(fn -> Expect.to_have_count!(Page.locator(page, ".phx-change-loading"), 0) end), + Promise.async(fn -> Expect.to_have_count!(Page.locator(page, ".phx-click-loading"), 0) end), + Promise.async(fn -> Expect.to_have_count!(Page.locator(page, ".phx-submit-loading"), 0) end) + ] + + Process.sleep(50) + promises |> Promise.all() |> Promise.await!() + end + + # Execute code inside LiveView process + def eval_lv(page, code, selector \\ "[data-phx-main]") do + Page.evaluate!( + page, + """ + ([code, selector]) => { + return new Promise(resolve => { + window.liveSocket.main.withinTargets(selector, (targetView, targetCtx) => { + targetView.pushEvent( + "event", + document.body, + targetCtx, + "sandbox:eval", + { value: code }, + {}, + ({ result, error }) => { + if (error) { + throw new Error(error) + } + resolve(result) + } + ) + }) + }) + } + """, + [code, selector] + ) + end +end diff --git a/e2e_pw/test_helper.exs b/e2e_pw/test_helper.exs new file mode 100644 index 00000000..7efc23e6 --- /dev/null +++ b/e2e_pw/test_helper.exs @@ -0,0 +1,10 @@ +# Browser suite for test/e2e. Run with `mix e2e.test`, or `MIX_ENV=e2e mix test` after +# `npm run e2e:build`. Starts the server of test/e2e/server.exs in this VM. +# The e2e env has no logger config: keep the server's request logs out of the test output. +Logger.configure(level: :warning) + +Code.require_file("../test/e2e/server.exs", __DIR__) +Code.require_file("support/utils.ex", __DIR__) +Code.require_file("support/case.ex", __DIR__) + +ExUnit.start(timeout: 30_000) diff --git a/e2e_pw/upload_test.exs b/e2e_pw/upload_test.exs new file mode 100644 index 00000000..1951c8fa --- /dev/null +++ b/e2e_pw/upload_test.exs @@ -0,0 +1,403 @@ +defmodule LiveVue.E2E.UploadTest do + use LiveVue.E2E.Case, async: true + + # `isVisible().catch(() => false)` + defp visible?(locator) do + case Locator.is_visible(locator) do + {:ok, visible} -> visible + {:error, _} -> false + end + end + + describe "useLiveUpload" do + test "should handle manual upload (auto_upload: false)", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Verify initial state + Expect.to_contain_text!(Page.locator(page, "#upload-mode"), "manual") + Expect.to_contain_text!(Page.locator(page, "#auto-upload"), "false") + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "0") + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "0") + + # Upload button should not be visible initially + page |> Page.locator("#upload-btn") |> Expect.not_() |> Expect.to_be_visible!() + + # Create a test file and simulate file selection + test_content = "This is test file content for manual upload" + + Page.set_input_files!(page, ~s(input[type="file"]), %{ + name: "test-manual.txt", + mimeType: "text/plain", + buffer: test_content + }) + + sync_lv(page) + + # Verify file is selected but not uploaded yet + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "0") + + # Upload button should now be visible + Expect.to_be_visible!(Page.locator(page, "#upload-btn")) + + # Verify file appears in file list + Expect.to_have_count!(Page.locator(page, ".file-entry"), 1) + Expect.to_contain_text!(Page.locator(page, ".file-name"), "test-manual.txt") + Expect.to_contain_text!(Page.locator(page, ".file-done"), "pending") + + # Click upload button to manually trigger upload + Page.click!(page, "#upload-btn") + sync_lv(page) + + # Wait for upload to complete and verify + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "1") + Expect.to_have_count!(Page.locator(page, ".uploaded-file"), 1) + Expect.to_contain_text!(Page.locator(page, ".uploaded-name"), "test-manual.txt") + end + + test "should handle automatic upload (auto_upload: true)", %{page: page} do + Page.goto!(page, "/upload/auto") + sync_lv(page) + + # Verify initial state + Expect.to_contain_text!(Page.locator(page, "#upload-mode"), "auto") + Expect.to_contain_text!(Page.locator(page, "#auto-upload"), "true") + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "0") + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "0") + + # Upload button should not be visible for auto upload + page |> Page.locator("#upload-btn") |> Expect.not_() |> Expect.to_be_visible!() + + # Create a test file and simulate file selection + test_content = "This is test file content for auto upload" + + Page.set_input_files!(page, ~s(input[type="file"]), %{ + name: "test-auto.txt", + mimeType: "text/plain", + buffer: test_content + }) + + sync_lv(page) + + # For auto upload, file should be uploaded automatically + # Wait a bit longer for the auto upload to process + Page.wait_for_timeout!(page, 2000) + sync_lv(page) + + # Verify file was selected and processed + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 1) + + # Check if the file was processed (either uploaded or marked as done) + file_status = Locator.text_content!(Page.locator(page, ".file-done")) + uploaded_count = Locator.text_content!(Page.locator(page, "#uploaded-count")) + + # For auto upload, the file should either be uploaded or marked as done + assert (is_binary(file_status) and file_status =~ "done") or + (is_binary(uploaded_count) and uploaded_count =~ "1") + end + + test "should handle multiple file selection and upload", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Select multiple files + Page.set_input_files!(page, ~s(input[type="file"]), [ + %{name: "file1.txt", mimeType: "text/plain", buffer: "Content of file 1"}, + %{name: "file2.txt", mimeType: "text/plain", buffer: "Content of file 2"} + ]) + + sync_lv(page) + + # Verify multiple files are selected + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "2") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 2) + + # Upload all files + Page.click!(page, "#upload-btn") + sync_lv(page) + + # Verify all files were uploaded + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "2") + Expect.to_have_count!(Page.locator(page, ".uploaded-file"), 2) + end + + test "should handle file cancellation", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Select a file + Page.set_input_files!(page, ~s(input[type="file"]), %{ + name: "cancel-test.txt", + mimeType: "text/plain", + buffer: "This file will be cancelled" + }) + + sync_lv(page) + + # Verify file is selected + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 1) + + # Cancel the file + Page.click!(page, "#cancel-all-btn") + sync_lv(page) + + # Verify file was cancelled + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "0") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 0) + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "0") + end + + test "should respect max_entries limit", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Verify max entries is displayed + Expect.to_contain_text!(Page.locator(page, "#max-entries"), "3") + + # Select exactly max_entries files (3) + Page.set_input_files!(page, ~s(input[type="file"]), [ + %{name: "file1.txt", mimeType: "text/plain", buffer: "1"}, + %{name: "file2.txt", mimeType: "text/plain", buffer: "2"}, + %{name: "file3.txt", mimeType: "text/plain", buffer: "3"} + ]) + + sync_lv(page) + + # Should accept exactly max_entries (3 files) + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "3") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 3) + end + + test "should handle file size errors", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Try to upload a file larger than max_file_size (1MB) + # 2MB file + large_content = String.duplicate("x", 2_000_000) + + Page.set_input_files!(page, ~s(input[type="file"]), %{ + name: "large-file.txt", + mimeType: "text/plain", + buffer: large_content + }) + + sync_lv(page) + + # File should be selected but may have errors + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 1) + + # Check if error handling is working (specific error messages may vary) + # The file might be rejected or show error state + has_errors = visible?(Page.locator(page, "#global-errors")) + has_entry_errors = visible?(Page.locator(page, ".entry-errors")) + + # At least one error display should be present for oversized files + assert has_errors or has_entry_errors + end + + test "should handle unsupported file type errors", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Try to upload a file type not in accept list (.exe not in .txt .pdf .jpg .png) + Page.set_input_files!(page, ~s(input[type="file"]), %{ + name: "program.exe", + mimeType: "application/octet-stream", + buffer: "fake exe content" + }) + + sync_lv(page) + + # File should be selected but may have errors + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + + # Check if error handling is working for unsupported file types + has_errors = visible?(Page.locator(page, "#global-errors")) + has_entry_errors = visible?(Page.locator(page, ".entry-errors")) + + # At least one error display should be present for unsupported file types + assert has_errors or has_entry_errors + end + + test "should handle too many files error", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Try to select more files than max_entries allows (4 files when max is 3) + Page.set_input_files!(page, ~s(input[type="file"]), [ + %{name: "file1.txt", mimeType: "text/plain", buffer: "1"}, + %{name: "file2.txt", mimeType: "text/plain", buffer: "2"}, + %{name: "file3.txt", mimeType: "text/plain", buffer: "3"}, + %{name: "file4.txt", mimeType: "text/plain", buffer: "4"} + ]) + + sync_lv(page) + + # Either only 3 files are accepted, or there's an error about too many files + _selected_count = Locator.text_content!(Page.locator(page, "#selected-count")) + assert Locator.count!(Page.locator(page, ".file-entry")) == 4 + + # Should either limit to max_entries or show error + # If more than 3 files are shown, there should be an error + has_errors = visible?(Page.locator(page, "#global-errors")) + assert has_errors + end + + test "should handle drag and drop file upload", %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + # Verify initial state + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "0") + + # Create a DataTransfer object with files for drag and drop simulation + test_content = "This is test file content for drag and drop" + + # Simulate drag and drop by dispatching a drop event with files + Page.evaluate!( + page, + """ + async content => { + const dropArea = document.querySelector("#drop-zone") + if (!dropArea) throw new Error("Drop area not found") + + // Create a File object + const file = new File([content], "drag-drop-test.txt", { type: "text/plain" }) + + // Create DataTransfer object and add the file + const dataTransfer = new DataTransfer() + dataTransfer.items.add(file) + + // Create and dispatch drop event + const dropEvent = new DragEvent("drop", { + bubbles: true, + cancelable: true, + dataTransfer: dataTransfer, + }) + + dropArea.dispatchEvent(dropEvent) + } + """, + test_content + ) + + sync_lv(page) + + # Verify file was added via drag and drop + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 1) + Expect.to_contain_text!(Page.locator(page, ".file-name"), "drag-drop-test.txt") + Expect.to_contain_text!(Page.locator(page, ".file-done"), "pending") + + # Upload button should now be visible for manual upload + Expect.to_be_visible!(Page.locator(page, "#upload-btn")) + + # Test that the upload works after drag and drop + Page.click!(page, "#upload-btn") + sync_lv(page) + + # Verify upload completed + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "1") + Expect.to_have_count!(Page.locator(page, ".uploaded-file"), 1) + Expect.to_contain_text!(Page.locator(page, ".uploaded-name"), "drag-drop-test.txt") + end + + test "should keep the original upload input usable across a simulated reconnect ref rotation", + %{page: page} do + Page.goto!(page, "/upload/manual") + sync_lv(page) + + original_ref = + Page.evaluate!(page, """ + () => { + const input = document.querySelector('input[type="file"]') + if (!input) throw new Error("Upload input not found") + window.__originalUploadInput = input + return input.getAttribute("data-phx-upload-ref") + } + """) + + eval_lv( + page, + """ + socket + |> Phoenix.LiveView.disallow_upload(:test_files) + |> Phoenix.LiveView.allow_upload(:test_files, + accept: ~w(.txt .pdf .jpg .png), + max_entries: 3, + max_file_size: 1_000_000, + auto_upload: false + ) + """ + ) + + Page.wait_for_function!( + page, + """ + previousRef => { + const input = document.querySelector('input[type="file"]') + return !!input && input.getAttribute("data-phx-upload-ref") !== previousRef + } + """, + original_ref + ) + + sync_lv(page) + + reconnect_state = + Page.evaluate!(page, """ + () => { + const currentInput = document.querySelector('input[type="file"]') + const originalInput = window.__originalUploadInput + + return { + originalStillAttached: !!originalInput?.isConnected, + sameNode: originalInput === currentInput, + currentRef: currentInput?.getAttribute("data-phx-upload-ref"), + } + } + """) + + assert reconnect_state["originalStillAttached"] == true + assert reconnect_state["sameNode"] == true + refute reconnect_state["currentRef"] == original_ref + + test_content = "Upload after reconnect through original input handle" + + Page.evaluate!( + page, + """ + content => { + const input = window.__originalUploadInput + if (!input) throw new Error("Saved upload input not found") + + const file = new File([content], "reconnect-race.txt", { type: "text/plain" }) + const dataTransfer = new DataTransfer() + dataTransfer.items.add(file) + input.files = dataTransfer.files + input.dispatchEvent(new Event("change", { bubbles: true, cancelable: true })) + } + """, + test_content + ) + + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "#selected-count"), "1") + Expect.to_have_count!(Page.locator(page, ".file-entry"), 1) + Expect.to_contain_text!(Page.locator(page, ".file-name"), "reconnect-race.txt") + + Page.click!(page, "#upload-btn") + sync_lv(page) + + Expect.to_contain_text!(Page.locator(page, "#uploaded-count"), "1") + Expect.to_have_count!(Page.locator(page, ".uploaded-file"), 1) + Expect.to_contain_text!(Page.locator(page, ".uploaded-name"), "reconnect-race.txt") + end + end +end diff --git a/mix.exs b/mix.exs index 29b6a0bf..c3884d0c 100644 --- a/mix.exs +++ b/mix.exs @@ -91,8 +91,8 @@ defmodule LiveVue.MixProject do } ], test_coverage: [tool: ExCoveralls], - test_paths: ["test"], - test_ignore_filters: [~r"/e2e/"] + test_paths: test_paths(Mix.env()), + test_ignore_filters: [~r"/e2e/", ~r"e2e_pw/support/"] ] end @@ -136,6 +136,11 @@ defmodule LiveVue.MixProject do ] end + # The browser suite lives outside test/ so that `mix test` under Elixir 1.15, which has no + # test_load_filters, does not load it. + defp test_paths(:e2e), do: ["e2e_pw"] + defp test_paths(_), do: ["test"] + defp elixirc_paths(:e2e), do: ["lib", "test/e2e/features"] defp elixirc_paths(_), do: ["lib"] @@ -168,7 +173,8 @@ defmodule LiveVue.MixProject do # e2e dependencies {:bandit, "~> 1.5", only: :e2e}, - {:phoenix_live_reload, "~> 1.2", only: :e2e} + {:phoenix_live_reload, "~> 1.2", only: :e2e}, + {:playwright, "~> 1.65.0-rc.2", hex: :playwright_ex, only: :e2e} ] end @@ -178,7 +184,7 @@ defmodule LiveVue.MixProject do setup: ["deps.get", "cmd npm install"], precommit: ["test", "format", "e2e.test", "assets.test"], "assets.test": ["cmd npm test"], - "e2e.test": ["cmd npm run e2e:test"], + "e2e.test": ["cmd npm run e2e:build", "cmd MIX_ENV=e2e mix test"], "release.patch": ["easy_publish.release patch --branch=main"], "release.minor": ["easy_publish.release minor --branch=main"], "release.major": ["easy_publish.release major --branch=main"] diff --git a/mix.lock b/mix.lock index a00d05c2..b50dfab5 100644 --- a/mix.lock +++ b/mix.lock @@ -47,6 +47,7 @@ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "phoenix_vite": {:hex, :phoenix_vite, "0.5.1", "f79b71dace8c94c434fef7e21db617a2e25e1e4e03be62f2cf4eeb79c739368d", [:mix], [{:bun, "~> 1.5 or ~> 2.0", [hex: :bun, repo: "hexpm", optional: true]}, {:igniter, "~> 0.6", [hex: :igniter, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "8f7c47f95f6a3384b4e10c9b1690b2a4e51aca938cf88f885a9514bce4339d4d"}, + "playwright": {:hex, :playwright_ex, "1.65.0-rc.2", "bdc53b1858b122d23e736f28b6ce4aa9d1fd2913abfad629de954f46abaee35b", [:mix], [], "hexpm", "916c76ab916de05ce06a2a2eb072ce80581e3685597d8dd8377200be860f6000"}, "plug": {:hex, :plug, "1.20.3", "56c480c633ec2ce10140e236e15233bf576e1d323887d7c96711bd02ab5160db", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "be266aee1b8536ef6409d58cf39a3121319f0ec47cfa1b24024485aa0e76ad76"}, "plug_crypto": {:hex, :plug_crypto, "2.2.0", "144014737daaf485407f5ed77daeaad74d651b216a28c87543f8cc7043f8efc8", [:mix], [], "hexpm", "83a95744ab1c75876542b6fab135fcc176280e0f301a111c1f757fddcec95d2c"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, diff --git a/test/e2e/server.exs b/test/e2e/server.exs new file mode 100644 index 00000000..1dcd29d1 --- /dev/null +++ b/test/e2e/server.exs @@ -0,0 +1,210 @@ +# The e2e app: endpoint, router, layout. Started by test/e2e/test_helper.exs (Playwright JS) +# and test/e2e_pw/test_helper.exs (ExUnit). +# Configure Phoenix JSON encoder +Application.put_env(:phoenix, :json_library, Jason) + +# Configure the test endpoint +Application.put_env(:live_vue, LiveVue.E2E.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4004], + adapter: Bandit.PhoenixAdapter, + server: true, + live_view: [signing_salt: "aaaaaaaa"], + secret_key_base: String.duplicate("a", 64), + debug_errors: true, + code_reloader: true, + pubsub_server: LiveVue.E2E.PubSub, + reloadable_apps: [:live_vue], + live_reload: [ + patterns: [ + ~r"lib/live_vue/.*(ex|exs)$", + ~r"test/e2e/features/.*\.(ex|exs|vue|js|ts)$" + ] + ] +) + +Application.put_env(:live_vue, :enable_props_diff, true) +Application.put_env(:live_vue, :ssr_module, LiveVue.SSR.QuickBEAM) +Application.put_env(:live_vue, :ssr_filepath, Path.expand("priv/static/server.mjs")) + +defmodule LiveVue.E2E.ErrorHTML do + def render(template, _), do: Phoenix.Controller.status_message_from_template(template) +end + +defmodule LiveVue.E2E.Layout do + @moduledoc false + use Phoenix.Component + use LiveVue + + def render("root.html", assigns) do + ~H""" + + + + + + + LiveVue E2E + + + {@inner_content} + + + """ + end + + def render("live.html", assigns) do + ~H""" + + + {@inner_content} + """ + end +end + +defmodule LiveVue.E2E.Hooks do + @moduledoc false + import Phoenix.LiveView + + alias Phoenix.LiveView.Socket + + require Logger + + def on_mount(:default, _params, _session, socket) do + socket + |> attach_hook(:eval_handler, :handle_event, &handle_eval_event/3) + |> then(&{:cont, &1}) + end + + defp handle_eval_event("sandbox:eval", %{"value" => code}, socket) do + {result, _} = Code.eval_string(code, [socket: socket], __ENV__) + Logger.debug("lv:#{inspect(self())} eval result: #{inspect(result)}") + + case result do + {:noreply, %Socket{} = socket} -> {:halt, %{}, socket} + %Socket{} = socket -> {:halt, %{}, socket} + result -> {:halt, %{"result" => result}, socket} + end + end + + defp handle_eval_event(_, _, socket), do: {:cont, socket} +end + +defmodule LiveVue.E2E.HealthController do + import Plug.Conn + + def init(opts), do: opts + + def index(conn, _params) do + send_resp(conn, 200, "OK") + end +end + +defmodule LiveVue.E2E.Router do + use Phoenix.Router + + import Phoenix.LiveView.Router + + alias LiveVue.E2E.Hooks + alias LiveVue.E2E.Layout + + pipeline :browser do + plug :accepts, ["html"] + plug :fetch_session + plug :fetch_live_flash + plug :protect_from_forgery + plug :put_root_layout, html: {Layout, :root} + end + + live_session :default, + layout: {Layout, :live}, + on_mount: {Hooks, :default} do + scope "/", LiveVue.E2E do + pipe_through(:browser) + + live "/test", TestLive + live "/prop-diff-test", PropDiffTestLive + live "/navigation/:page", NavigationLive + live "/navigation/alt/:page", NavigationLive + live "/events", EventLive + live "/upload/:mode", UploadTestLive + live "/streams", StreamLive + live "/form-test", FormTestLive + live "/event-reply-test", EventReplyTestLive + live "/slot-test", SlotTestLive + live "/memory-benchmark", MemoryBenchmarkLive + live "/reconnect", ReconnectLive + live "/headless", HeadlessLive + live "/persistent-layout/:page", PersistentLayoutLive + end + end + + scope "/", LiveVue.E2E do + pipe_through(:browser) + + get "/health", HealthController, :index + get "/dead-view", DeadViewController, :show + end +end + +defmodule LiveVue.E2E.Endpoint do + use Phoenix.Endpoint, otp_app: :live_vue + + @session_options [ + store: :cookie, + key: "_lv_e2e_key", + signing_salt: "aaaaaaaa", + same_site: "Lax" + ] + + socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] + + # Code reloading configuration + if code_reloading? do + socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket + plug Phoenix.LiveReloader + plug Phoenix.CodeReloader + end + + plug Plug.Static, from: {:phoenix, "priv/static"}, at: "/assets/phoenix" + plug Plug.Static, from: {:phoenix_live_view, "priv/static"}, at: "/assets/phoenix_live_view" + plug Plug.Static, from: "test/e2e/priv/static/assets", at: "/assets" + + plug :health_check + plug :halt + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Plug.Session, @session_options + plug LiveVue.E2E.Router + + defp health_check(%{request_path: "/health"} = conn, _opts) do + conn + |> Plug.Conn.send_resp(200, "OK") + |> Plug.Conn.halt() + end + + defp health_check(conn, _opts), do: conn + + defp halt(%{request_path: "/halt"}, _opts) do + send(:e2e_helper, :halt) + Process.sleep(:infinity) + end + + defp halt(conn, _opts), do: conn +end + +# Start PubSub and Endpoint +# Note: LiveView modules are compiled from test/e2e/features/*/live.ex via elixirc_paths in mix.exs +{:ok, _} = + Supervisor.start_link( + [ + LiveVue.SSR.QuickBEAM, + LiveVue.E2E.Endpoint, + {Phoenix.PubSub, name: LiveVue.E2E.PubSub} + ], + strategy: :one_for_one + ) diff --git a/test/e2e/test_helper.exs b/test/e2e/test_helper.exs index 762acc57..14cbc29b 100644 --- a/test/e2e/test_helper.exs +++ b/test/e2e/test_helper.exs @@ -1,214 +1,8 @@ -# Configure Phoenix JSON encoder -Application.put_env(:phoenix, :json_library, Jason) - -# Configure the test endpoint -Application.put_env(:live_vue, LiveVue.E2E.Endpoint, - http: [ip: {127, 0, 0, 1}, port: 4004], - adapter: Bandit.PhoenixAdapter, - server: true, - live_view: [signing_salt: "aaaaaaaa"], - secret_key_base: String.duplicate("a", 64), - debug_errors: true, - code_reloader: true, - pubsub_server: LiveVue.E2E.PubSub, - reloadable_apps: [:live_vue], - live_reload: [ - patterns: [ - ~r"lib/live_vue/.*(ex|exs)$", - ~r"test/e2e/features/.*\.(ex|exs|vue|js|ts)$" - ] - ] -) - -Application.put_env(:live_vue, :enable_props_diff, true) -Application.put_env(:live_vue, :ssr_module, LiveVue.SSR.QuickBEAM) -Application.put_env(:live_vue, :ssr_filepath, Path.expand("priv/static/server.mjs")) +# The server is shared with the ExUnit port in test/e2e_pw. +Code.require_file("server.exs", __DIR__) Process.register(self(), :e2e_helper) -defmodule LiveVue.E2E.ErrorHTML do - def render(template, _), do: Phoenix.Controller.status_message_from_template(template) -end - -defmodule LiveVue.E2E.Layout do - @moduledoc false - use Phoenix.Component - use LiveVue - - def render("root.html", assigns) do - ~H""" - - - - - - - LiveVue E2E - - - {@inner_content} - - - """ - end - - def render("live.html", assigns) do - ~H""" - - - {@inner_content} - """ - end -end - -defmodule LiveVue.E2E.Hooks do - @moduledoc false - import Phoenix.LiveView - - alias Phoenix.LiveView.Socket - - require Logger - - def on_mount(:default, _params, _session, socket) do - socket - |> attach_hook(:eval_handler, :handle_event, &handle_eval_event/3) - |> then(&{:cont, &1}) - end - - defp handle_eval_event("sandbox:eval", %{"value" => code}, socket) do - {result, _} = Code.eval_string(code, [socket: socket], __ENV__) - Logger.debug("lv:#{inspect(self())} eval result: #{inspect(result)}") - - case result do - {:noreply, %Socket{} = socket} -> {:halt, %{}, socket} - %Socket{} = socket -> {:halt, %{}, socket} - result -> {:halt, %{"result" => result}, socket} - end - end - - defp handle_eval_event(_, _, socket), do: {:cont, socket} -end - -defmodule LiveVue.E2E.HealthController do - import Plug.Conn - - def init(opts), do: opts - - def index(conn, _params) do - send_resp(conn, 200, "OK") - end -end - -defmodule LiveVue.E2E.Router do - use Phoenix.Router - - import Phoenix.LiveView.Router - - alias LiveVue.E2E.Hooks - alias LiveVue.E2E.Layout - - pipeline :browser do - plug :accepts, ["html"] - plug :fetch_session - plug :fetch_live_flash - plug :protect_from_forgery - plug :put_root_layout, html: {Layout, :root} - end - - live_session :default, - layout: {Layout, :live}, - on_mount: {Hooks, :default} do - scope "/", LiveVue.E2E do - pipe_through(:browser) - - live "/test", TestLive - live "/prop-diff-test", PropDiffTestLive - live "/navigation/:page", NavigationLive - live "/navigation/alt/:page", NavigationLive - live "/events", EventLive - live "/upload/:mode", UploadTestLive - live "/streams", StreamLive - live "/form-test", FormTestLive - live "/event-reply-test", EventReplyTestLive - live "/slot-test", SlotTestLive - live "/memory-benchmark", MemoryBenchmarkLive - live "/reconnect", ReconnectLive - live "/headless", HeadlessLive - live "/persistent-layout/:page", PersistentLayoutLive - end - end - - scope "/", LiveVue.E2E do - pipe_through(:browser) - - get "/health", HealthController, :index - get "/dead-view", DeadViewController, :show - end -end - -defmodule LiveVue.E2E.Endpoint do - use Phoenix.Endpoint, otp_app: :live_vue - - @session_options [ - store: :cookie, - key: "_lv_e2e_key", - signing_salt: "aaaaaaaa", - same_site: "Lax" - ] - - socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] - - # Code reloading configuration - if code_reloading? do - socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket - plug Phoenix.LiveReloader - plug Phoenix.CodeReloader - end - - plug Plug.Static, from: {:phoenix, "priv/static"}, at: "/assets/phoenix" - plug Plug.Static, from: {:phoenix_live_view, "priv/static"}, at: "/assets/phoenix_live_view" - plug Plug.Static, from: "test/e2e/priv/static/assets", at: "/assets" - - plug :health_check - plug :halt - - plug Plug.Parsers, - parsers: [:urlencoded, :multipart, :json], - pass: ["*/*"], - json_decoder: Phoenix.json_library() - - plug Plug.Session, @session_options - plug LiveVue.E2E.Router - - defp health_check(%{request_path: "/health"} = conn, _opts) do - conn - |> Plug.Conn.send_resp(200, "OK") - |> Plug.Conn.halt() - end - - defp health_check(conn, _opts), do: conn - - defp halt(%{request_path: "/halt"}, _opts) do - send(:e2e_helper, :halt) - Process.sleep(:infinity) - end - - defp halt(conn, _opts), do: conn -end - -# Start PubSub and Endpoint -# Note: LiveView modules are compiled from test/e2e/features/*/live.ex via elixirc_paths in mix.exs -{:ok, _} = - Supervisor.start_link( - [ - LiveVue.SSR.QuickBEAM, - LiveVue.E2E.Endpoint, - {Phoenix.PubSub, name: LiveVue.E2E.PubSub} - ], - strategy: :one_for_one - ) - IO.puts("Starting e2e server on port #{LiveVue.E2E.Endpoint.config(:http)[:port]}") if not IEx.started?() do From 42aab8822944a72b610c9b6ae5bb7179c58f5d8f Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 07:55:13 +0100 Subject: [PATCH 2/8] test: remove the JS e2e suite Delete the Playwright Test specs, config and helpers, and the @playwright/test dependency and npm scripts. mix e2e.test builds the assets and runs the ExUnit suite; docs updated. --- AGENTS.md | 20 +- README.md | 2 +- package-lock.json | 98 --- package.json | 7 +- test/e2e/README.md | 49 +- test/e2e/features/basic/basic.spec.js | 35 - test/e2e/features/dead-view/dead-view.spec.js | 24 - .../features/event-reply/event_reply.spec.js | 241 ------- test/e2e/features/event/event.spec.js | 113 --- test/e2e/features/form/form.spec.js | 644 ------------------ test/e2e/features/headless/headless.spec.js | 40 -- .../features/navigation/navigation.spec.js | 53 -- .../persistent-layout.spec.js | 78 --- test/e2e/features/prop-diff/prop-diff.spec.js | 226 ------ test/e2e/features/reconnect/reconnect.spec.js | 68 -- test/e2e/features/slot/slot.spec.js | 31 - test/e2e/features/stream/stream.spec.js | 433 ------------ test/e2e/features/upload/upload.spec.js | 394 ----------- test/e2e/playwright.config.js | 26 - test/e2e/utils.js | 51 -- 20 files changed, 40 insertions(+), 2593 deletions(-) delete mode 100644 test/e2e/features/basic/basic.spec.js delete mode 100644 test/e2e/features/dead-view/dead-view.spec.js delete mode 100644 test/e2e/features/event-reply/event_reply.spec.js delete mode 100644 test/e2e/features/event/event.spec.js delete mode 100644 test/e2e/features/form/form.spec.js delete mode 100644 test/e2e/features/headless/headless.spec.js delete mode 100644 test/e2e/features/navigation/navigation.spec.js delete mode 100644 test/e2e/features/persistent-layout/persistent-layout.spec.js delete mode 100644 test/e2e/features/prop-diff/prop-diff.spec.js delete mode 100644 test/e2e/features/reconnect/reconnect.spec.js delete mode 100644 test/e2e/features/slot/slot.spec.js delete mode 100644 test/e2e/features/stream/stream.spec.js delete mode 100644 test/e2e/features/upload/upload.spec.js delete mode 100644 test/e2e/playwright.config.js delete mode 100644 test/e2e/utils.js diff --git a/AGENTS.md b/AGENTS.md index b46843ef..dea7cdc2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,7 +8,7 @@ Vue.js + Phoenix LiveView integration library. Version 1.0.0. # Tests mix test # Elixir tests npm test # Vitest (assets/*.test.ts) -npm run e2e:test # Playwright E2E (test/e2e/) +mix e2e.test # Playwright E2E (e2e_pw/, server in test/e2e/) # Setup mix setup # First-time setup (deps + npm install) @@ -30,7 +30,8 @@ assets/ ├── useLiveForm.ts # Form handling with Ecto changesets ├── jsonPatch.ts # Efficient prop diffing └── vitePlugin.js # Vite plugin for component discovery -test/e2e/ # Playwright E2E tests with Phoenix server +test/e2e/ # Phoenix server and features for the E2E tests +e2e_pw/ # Playwright E2E tests (ExUnit, playwright_ex) ``` ## Key Patterns @@ -67,7 +68,7 @@ test/e2e/features/ ├── basic/ # Each feature is a directory │ ├── live.ex # LiveView module │ ├── counter.vue # Vue component(s) -│ └── basic.spec.js # Playwright test +│ └── ... ├── form/ ├── stream/ └── ... @@ -75,12 +76,13 @@ test/e2e/features/ To add a new E2E test: 1. Create `test/e2e/features/my-feature/` -2. Add `live.ex` (LiveView), `*.vue` (components), `*.spec.js` (test) -3. Add route to `test/e2e/test_helper.exs` router +2. Add `live.ex` (LiveView) and `*.vue` (components) +3. Add route to `test/e2e/server.exs` router +4. Add the test to `e2e_pw/` (`use LiveVue.E2E.Case`) -Key utilities in `test/e2e/utils.js`: -- `syncLV(page)` - Wait for LiveView connection -- `evalLV(page, code)` - Execute Elixir in LiveView process +Key utilities in `e2e_pw/support/utils.ex`: +- `sync_lv(page)` - Wait for LiveView connection +- `eval_lv(page, code)` - Execute Elixir in LiveView process ## Conventions @@ -94,5 +96,5 @@ For hex.pm releases, `mix release.{patch,minor,major}` runs easy_publish (bumps ## Notes -- This is a library - use E2E tests (`npm run e2e:test`) for testing +- This is a library - use E2E tests (`mix e2e.test`) for testing - CI: Elixir (.github/workflows/elixir.yml), Frontend (.github/workflows/frontend.yml) diff --git a/README.md b/README.md index 2c0d3aec..0be32daf 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ Ensure you have Node.js installed. Clone the repo and run `mix setup`. No build step is required for the library itself - Vite handles TypeScript transpilation when consumers bundle their app. -Use `npm run e2e:test` to run the Playwright E2E tests. +Use `mix e2e.test` to run the Playwright E2E tests (first `MIX_ENV=e2e mix playwright.install chromium`). ### Testing Local Changes in Another Project diff --git a/package-lock.json b/package-lock.json index 7770e817..a5ad0404 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "MIT", "devDependencies": { - "@playwright/test": "^1.53.0", "@types/node": "^22.9.1", "@vitejs/plugin-vue": "^6.0.0", "@vitest/ui": "^3.2.4", @@ -4520,22 +4519,6 @@ "url": "https://opencollective.com/pkgr" } }, - "node_modules/@playwright/test": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.54.1.tgz", - "integrity": "sha512-FS8hQ12acieG2dYSksmLOF7BNxnVf2afRJdCuM1eMSxj6QTSE6G4InGF7oApGgDb65MX7AwMVlIkpru0yZA4Xw==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "playwright": "1.54.1" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/@polka/url": { "version": "1.0.0-next.29", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz", @@ -11709,53 +11692,6 @@ "node": ">=8" } }, - "node_modules/playwright": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.54.1.tgz", - "integrity": "sha512-peWpSwIBmSLi6aW2auvrUtf2DqY16YYcCMO8rTVx486jKmDTJg7UAhyrraP98GB8BoPURZP8+nxO7TSd4cPr5g==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "playwright-core": "1.54.1" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "fsevents": "2.3.2" - } - }, - "node_modules/playwright-core": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.54.1.tgz", - "integrity": "sha512-Nbjs2zjj0htNhzgiy5wu+3w09YetDx5pkrpI/kZotDlDUaYk0HVA5xrBVPdow4SAUIlhgKcJeJg4GRKW6xHusA==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/playwright/node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/postcss": { "version": "8.5.6", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", @@ -16452,15 +16388,6 @@ "integrity": "sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA==", "dev": true }, - "@playwright/test": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.54.1.tgz", - "integrity": "sha512-FS8hQ12acieG2dYSksmLOF7BNxnVf2afRJdCuM1eMSxj6QTSE6G4InGF7oApGgDb65MX7AwMVlIkpru0yZA4Xw==", - "dev": true, - "requires": { - "playwright": "1.54.1" - } - }, "@polka/url": { "version": "1.0.0-next.29", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz", @@ -21800,31 +21727,6 @@ "find-up": "^4.0.0" } }, - "playwright": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.54.1.tgz", - "integrity": "sha512-peWpSwIBmSLi6aW2auvrUtf2DqY16YYcCMO8rTVx486jKmDTJg7UAhyrraP98GB8BoPURZP8+nxO7TSd4cPr5g==", - "dev": true, - "requires": { - "fsevents": "2.3.2", - "playwright-core": "1.54.1" - }, - "dependencies": { - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - } - } - }, - "playwright-core": { - "version": "1.54.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.54.1.tgz", - "integrity": "sha512-Nbjs2zjj0htNhzgiy5wu+3w09YetDx5pkrpI/kZotDlDUaYk0HVA5xrBVPdow4SAUIlhgKcJeJg4GRKW6xHusA==", - "dev": true - }, "postcss": { "version": "8.5.6", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", diff --git a/package.json b/package.json index 06e6c0a9..b282313d 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,8 @@ "test:watch": "vitest --watch", "test:ui": "vitest --ui", "bench": "vitest bench", - "e2e:install": "npx playwright install --with-deps chromium", "e2e:server": "MIX_ENV=e2e mix run test/e2e/test_helper.exs", - "e2e:build": "npx vite build --config test/e2e/vite.config.js && npx vite build --config test/e2e/vite.config.js --ssr test/e2e/js/server.js", - "e2e:test": "npm run e2e:build && npx playwright test --config test/e2e/playwright.config.js", - "e2e:test:headed": "npm run e2e:build && npx playwright test --config test/e2e/playwright.config.js --headed", - "e2e:test:debug": "npm run e2e:build && npx playwright test --config test/e2e/playwright.config.js --debug" + "e2e:build": "npx vite build --config test/e2e/vite.config.js && npx vite build --config test/e2e/vite.config.js --ssr test/e2e/js/server.js" }, "peerDependencies": { "vue": "^3.4.0" @@ -25,7 +21,6 @@ "phoenix": "file:deps/phoenix", "phoenix_html": "file:deps/phoenix_html", "phoenix_live_view": "file:deps/phoenix_live_view", - "@playwright/test": "^1.53.0", "@types/node": "^22.9.1", "@vitejs/plugin-vue": "^6.0.0", "@vitest/ui": "^3.2.4", diff --git a/test/e2e/README.md b/test/e2e/README.md index efff3cd7..d8347477 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -1,22 +1,26 @@ # LiveVue End-to-End Tests -This directory contains end-to-end tests for the LiveVue library using Playwright. +This directory contains the Phoenix server and the features for the end-to-end tests of the LiveVue +library. The tests themselves are ExUnit tests in `e2e_pw/`, run with +[playwright_ex](https://hex.pm/packages/playwright_ex) (needs Elixir 1.18+). ## Setup 1. Install Playwright browsers: ```bash - npm run e2e:install + MIX_ENV=e2e mix playwright.install chromium ``` ## Running Tests ```bash -npm run e2e:test # Run all tests -npm run e2e:test:headed # Run with browser UI -npm run e2e:test:debug # Debug interactively +mix e2e.test # Build the assets, run all tests +MIX_ENV=e2e mix test e2e_pw/form_test.exs # Run one file (after npm run e2e:build) ``` +To watch the browser, set `launch_options: [headless: false]` in the `:playwright, :test` config of +`config/config.exs`. To debug interactively, run with `PWDEBUG=1`. + ## Structure Tests are organized as colocated features - each feature has its LiveView, Vue components, and tests in one directory: @@ -27,7 +31,6 @@ test/e2e/ │ ├── basic/ # Basic counter test │ │ ├── live.ex # LiveView module (LiveVue.E2E.TestLive) │ │ ├── counter.vue # Vue component -│ │ └── basic.spec.js # Playwright test │ ├── form/ # Form validation tests │ ├── stream/ # LiveView streams tests │ ├── event/ # useLiveEvent tests @@ -38,12 +41,13 @@ test/e2e/ │ └── upload/ # File upload tests ├── js/ │ └── app.js # Vue/LiveSocket bootstrap -├── test_helper.exs # Phoenix endpoint, routes, layout -├── utils.js # Test utilities -├── playwright.config.js +├── server.exs # Phoenix endpoint, routes, layout +├── test_helper.exs # Runs the server standalone (npm run e2e:server) └── vite.config.js ``` +The tests are in `e2e_pw/`, one `*_test.exs` per feature. + ## Adding a New Test Feature 1. Create directory: `test/e2e/features/my-feature/` @@ -75,31 +79,32 @@ test/e2e/ ``` -4. Add route to `test_helper.exs`: +4. Add route to `server.exs`: ```elixir live "/my-feature", MyFeatureLive ``` -5. Add test (`my-feature.spec.js`): - ```javascript - import { test, expect } from "@playwright/test" - import { syncLV } from "../../utils.js" +5. Add test (`e2e_pw/my_feature_test.exs`): + ```elixir + defmodule LiveVue.E2E.MyFeatureTest do + use LiveVue.E2E.Case, async: true - test("my feature works", async ({ page }) => { - await page.goto("/my-feature") - await syncLV(page) - await expect(page.getByTestId("output")).toHaveText("hello") - }) + test "my feature works", %{page: page} do + Page.goto!(page, "/my-feature") + sync_lv(page) + Expect.to_have_text!(Page.get_by_test_id(page, "output"), "hello") + end + end ``` ## Test Utilities -- `syncLV(page)` - Wait for LiveView to connect and finish loading -- `evalLV(page, code)` - Execute Elixir code in LiveView process (returns result) +- `sync_lv(page)` - Wait for LiveView to connect and finish loading +- `eval_lv(page, code)` - Execute Elixir code in LiveView process (returns result) ## Test Server -Runs on http://localhost:4004. Routes are defined in `test_helper.exs`. +Runs on http://localhost:4004. Routes are defined in `server.exs`. ## Notes diff --git a/test/e2e/features/basic/basic.spec.js b/test/e2e/features/basic/basic.spec.js deleted file mode 100644 index a1dda3a9..00000000 --- a/test/e2e/features/basic/basic.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV } from "../../utils.js" - -test.describe("LiveVue Basic E2E Tests", () => { - test("renders Vue component inside LiveView and handles increment events", async ({ page }) => { - await page.goto("/test") - await syncLV(page) - - // Verify Vue component is mounted and displays initial count - await expect(page.locator('[phx-hook="VueHook"]')).toBeVisible() - await expect(page.locator("[data-pw-counter]")).toHaveText("0") - - // Verify the diff slider is present and has default value - const diffSlider = page.locator('input[type="range"]') - await expect(diffSlider).toBeVisible() - await expect(diffSlider).toHaveValue("1") - - // Test incrementing by default value (1) - await page.locator("button").click() - await syncLV(page) - await expect(page.locator('[phx-hook="VueHook"] [data-pw-counter]')).toHaveText("1") - - // Test incrementing by a different value (3) - await diffSlider.fill("3") - await page.locator("button").click() - await syncLV(page) - await expect(page.locator('[phx-hook="VueHook"] [data-pw-counter]')).toHaveText("4") - - // Test incrementing by maximum value (10) - await diffSlider.fill("10") - await page.locator("button").click() - await syncLV(page) - await expect(page.locator('[phx-hook="VueHook"] [data-pw-counter]')).toHaveText("14") - }) -}) diff --git a/test/e2e/features/dead-view/dead-view.spec.js b/test/e2e/features/dead-view/dead-view.spec.js deleted file mode 100644 index 033f08ea..00000000 --- a/test/e2e/features/dead-view/dead-view.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -import { test, expect } from "@playwright/test" - -test.describe("LiveVue Dead View Tests", () => { - test("renders Vue component inside regular Phoenix controller view (dead view)", async ({ - page, - }) => { - // Navigate to the dead view page - const response = await page.goto("/dead-view") - - // First check if the page loaded successfully (no 500 error) - expect(response.status()).toBe(200) - - // Verify the server-rendered content from the controller - await expect(page.locator("[data-pw-server-message]")).toHaveText("Hello from dead view!") - - // Wait for Vue to initialize and hydrate the component - // In dead views, Vue still mounts via the VueHook initialization - await page.waitForTimeout(500) - - // Verify the Vue component rendered correctly - await expect(page.locator("[data-pw-dead-view]")).toBeVisible() - await expect(page.locator("[data-pw-vue-message]")).toHaveText("Hello from dead view!") - }) -}) diff --git a/test/e2e/features/event-reply/event_reply.spec.js b/test/e2e/features/event-reply/event_reply.spec.js deleted file mode 100644 index 59dbe0dd..00000000 --- a/test/e2e/features/event-reply/event_reply.spec.js +++ /dev/null @@ -1,241 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV, evalLV } from "../../utils.js" - -test.describe("useEventReply E2E Tests", () => { - test.beforeEach(async ({ page }) => { - await page.goto("/event-reply-test") - await syncLV(page) - }) - - test("component initializes correctly", async ({ page }) => { - // Verify component is mounted - await expect(page.locator("[data-pw-event-reply-test]")).toBeVisible() - await expect(page.locator("[data-pw-server-counter]")).toHaveText("Server Counter: 0") - - // Initial state should be empty - await expect(page.locator("[data-pw-increment-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-increment-data]")).toHaveText("Data: null") - }) - - test("increment event with reply works correctly", async ({ page }) => { - // Click increment by 1 - await page.locator("[data-pw-increment-1]").click() - await syncLV(page) - - // Check server state updated - await expect(page.locator("[data-pw-server-counter]")).toHaveText("Server Counter: 1") - - // Check client state received reply - await expect(page.locator("[data-pw-increment-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-increment-data]")).toContainText('"counter":1') - - // Click increment by 5 - await page.locator("[data-pw-increment-5]").click() - await syncLV(page) - - // Check server counter is now 6 - await expect(page.locator("[data-pw-server-counter]")).toHaveText("Server Counter: 6") - await expect(page.locator("[data-pw-increment-data]")).toContainText('"counter":6') - }) - - test("user data fetching with different IDs", async ({ page }) => { - // Fetch user 1 - await page.locator("[data-pw-fetch-user-1]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-user-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-user-data]")).toContainText('"name":"John Doe"') - await expect(page.locator("[data-pw-user-data]")).toContainText('"email":"john@example.com"') - - // Fetch user 2 - await page.locator("[data-pw-fetch-user-2]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-user-data]")).toContainText('"name":"Jane Smith"') - await expect(page.locator("[data-pw-user-data]")).toContainText('"email":"jane@example.com"') - - // Fetch unknown user - await page.locator("[data-pw-fetch-user-999]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-user-data]")).toContainText('"name":"Unknown User"') - }) - - test("server error response handling works correctly", async ({ page }) => { - // Trigger server error response - await page.locator("[data-pw-trigger-error]").click() - await syncLV(page) - - // Should receive error in data (server returns error as valid response data) - await expect(page.locator("[data-pw-error-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-error-data]")).toContainText('"error":"Something went wrong on the server"') - }) - - test("no parameters event works", async ({ page }) => { - // Test ping without parameters - await page.locator("[data-pw-ping]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-ping-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-ping-data]")).toContainText('"response":"pong"') - }) - - test("different data types are handled correctly", async ({ page }) => { - // Test string - now wrapped in {data: "Hello World"} - await page.locator("[data-pw-test-string]").click() - await syncLV(page) - await expect(page.locator("[data-pw-datatype-data]")).toContainText('"data":"Hello World"') - - // Test number - now wrapped in {data: 42} - await page.locator("[data-pw-test-number]").click() - await syncLV(page) - await expect(page.locator("[data-pw-datatype-data]")).toContainText('"data":42') - - // Test boolean - now wrapped in {data: true} - await page.locator("[data-pw-test-boolean]").click() - await syncLV(page) - await expect(page.locator("[data-pw-datatype-data]")).toContainText('"data":true') - - // Test array - now wrapped in {data: [1,2,3,"four",true]} - await page.locator("[data-pw-test-array]").click() - await syncLV(page) - await expect(page.locator("[data-pw-datatype-data]")).toContainText('"data":[1,2,3,"four",true]') - - // Test object - now wrapped in {data: {nested: {value: "test"}, count: 5}} - await page.locator("[data-pw-test-object]").click() - await syncLV(page) - // Check for key components since JSON key order isn't guaranteed - const objectData = page.locator("[data-pw-datatype-data]") - await expect(objectData).toContainText('"data":') - await expect(objectData).toContainText('"nested":{"value":"test"}') - await expect(objectData).toContainText('"count":5') - - // Test null - now wrapped in {data: null} - await page.locator("[data-pw-test-null]").click() - await syncLV(page) - await expect(page.locator("[data-pw-datatype-data]")).toContainText('"data":null') - }) - - test("input validation with server-side logic", async ({ page }) => { - // Test short input (invalid) - await page.locator("[data-pw-validate-short]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-validate-data]")).toContainText('"valid":false') - await expect(page.locator("[data-pw-validate-data]")).toContainText('"error":"Input too short"') - - // Test valid input - await page.locator("[data-pw-validate-valid]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-validate-data]")).toContainText('"valid":true') - await expect(page.locator("[data-pw-validate-data]")).toContainText('"message":"Input is valid"') - - // Test long input (invalid) - await page.locator("[data-pw-validate-long]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-validate-data]")).toContainText('"valid":false') - await expect(page.locator("[data-pw-validate-data]")).toContainText('"error":"Input too long"') - }) - - test("cancellation functionality works", async ({ page }) => { - // Start slow event - await page.locator("[data-pw-start-slow]").click() - - // Should be loading immediately - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: true") - - // Cancel before it completes - await page.locator("[data-pw-cancel-slow]").click() - - // Should not be loading after cancel - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: false") - - // Data should remain null (cancelled) - await expect(page.locator("[data-pw-slow-data]")).toHaveText("Data: null") - - // Wait a bit to ensure the server response would have arrived - await page.waitForTimeout(500) - await syncLV(page) - - // Data should still be null (response ignored) - await expect(page.locator("[data-pw-slow-data]")).toHaveText("Data: null") - }) - - test("concurrent execution prevention works", async ({ page }) => { - // Start first slow event - await page.locator("[data-pw-concurrent-first]").click() - - // Should be loading - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: true") - - // Try to start second event - should be rejected - await page.locator("[data-pw-concurrent-second]").click() - - // Should still show loading from first event only - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: true") - - // Wait for first event to complete - await page.waitForTimeout(1200) - await syncLV(page) - - // Should now show completed first event - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-slow-data]")).toContainText('"message":"Slow response after 1000ms"') - }) - - test("multiple different composables work independently", async ({ page }) => { - // Execute multiple different events in quick succession - await page.locator("[data-pw-increment-1]").click() - await page.locator("[data-pw-fetch-user-1]").click() - await page.locator("[data-pw-ping]").click() - - await page.waitForTimeout(100) - - // All should complete successfully and independently - await expect(page.locator("[data-pw-increment-data]")).toContainText('"counter":1') - await expect(page.locator("[data-pw-user-data]")).toContainText('"name":"John Doe"') - await expect(page.locator("[data-pw-ping-data]")).toContainText('"response":"pong"') - - // All should be not loading - await expect(page.locator("[data-pw-increment-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-user-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-ping-loading]")).toHaveText("Loading: false") - }) - - test("component state persists across LiveView updates", async ({ page }) => { - // Execute an event to get some data - await page.locator("[data-pw-increment-5]").click() - await syncLV(page) - - await expect(page.locator("[data-pw-increment-data]")).toContainText('"counter":5') - - // Trigger another server update that doesn't affect this composable - await page.locator("[data-pw-fetch-user-1]").click() - await syncLV(page) - - // Original increment data should still be there - await expect(page.locator("[data-pw-increment-data]")).toContainText('"counter":5') - await expect(page.locator("[data-pw-user-data]")).toContainText('"name":"John Doe"') - }) - - test("loading states are accurate", async ({ page }) => { - // All should start as not loading - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: false") - - // Start slow event and verify loading state immediately - await page.locator("[data-pw-start-slow]").click() - - // Should be loading now - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: true") - - // Wait for completion - await page.waitForTimeout(2200) - await syncLV(page) - - // Should be done loading - await expect(page.locator("[data-pw-slow-loading]")).toHaveText("Loading: false") - await expect(page.locator("[data-pw-slow-data]")).toContainText("Slow response after 2000ms") - }) -}) diff --git a/test/e2e/features/event/event.spec.js b/test/e2e/features/event/event.spec.js deleted file mode 100644 index 421c56de..00000000 --- a/test/e2e/features/event/event.spec.js +++ /dev/null @@ -1,113 +0,0 @@ -import { test, expect } from '@playwright/test' -import { syncLV } from '../../utils.js' - -test.describe('useLiveEvent', () => { - test('should receive notification events from server', async ({ page }) => { - await page.goto('/events') - await syncLV(page) - - // Verify initial state - await expect(page.locator('#notification-count')).toContainText('Notification Count: 0') - await expect(page.locator('#custom-count')).toContainText('Custom Event Count: 0') - - // Send a notification event - await page.fill('#message-input', 'Hello from test!') - await page.click('#send-notification-btn') - await syncLV(page) - - // Verify notification event was received - await expect(page.locator('#notification-count')).toContainText('Notification Count: 1') - await expect(page.locator('.notification-event')).toContainText('Hello from test!') - - // Verify the message appears in both LiveView state and Vue component - await expect(page.locator('#message-display')).toContainText('Message: Hello from test!') - await expect(page.locator('#event-count')).toContainText('Event Count: 1') - - // Send another notification - await page.fill('#message-input', 'Second message') - await page.click('#send-notification-btn') - await syncLV(page) - - // Verify both notifications are received - await expect(page.locator('#notification-count')).toContainText('Notification Count: 2') - await expect(page.locator('.notification-event')).toHaveCount(2) - await expect(page.locator('.notification-event').nth(1)).toContainText('Second message') - }) - - test('should receive custom events from server', async ({ page }) => { - await page.goto('/events') - await syncLV(page) - - // Send a custom event - await page.fill('#custom-data-input', 'Custom data payload') - await page.click('#send-custom-btn') - await syncLV(page) - - // Verify custom event was received - await expect(page.locator('#custom-count')).toContainText('Custom Event Count: 1') - await expect(page.locator('.custom-event')).toContainText('Custom data payload (count: 1)') - await expect(page.locator('#event-count')).toContainText('Event Count: 1') - - // Send another custom event - await page.fill('#custom-data-input', 'Another payload') - await page.click('#send-custom-btn') - await syncLV(page) - - // Verify both custom events are received - await expect(page.locator('#custom-count')).toContainText('Custom Event Count: 2') - await expect(page.locator('.custom-event')).toHaveCount(2) - await expect(page.locator('.custom-event').nth(1)).toContainText('Another payload (count: 2)') - }) - - test('should handle mixed notification and custom events', async ({ page }) => { - await page.goto('/events') - await syncLV(page) - - // Send notification - await page.fill('#message-input', 'Mixed test notification') - await page.click('#send-notification-btn') - await syncLV(page) - - // Send custom event - await page.fill('#custom-data-input', 'Mixed test custom') - await page.click('#send-custom-btn') - await syncLV(page) - - // Send another notification - await page.fill('#message-input', 'Second notification') - await page.click('#send-notification-btn') - await syncLV(page) - - // Verify all events are received correctly - await expect(page.locator('#notification-count')).toContainText('Notification Count: 2') - await expect(page.locator('#custom-count')).toContainText('Custom Event Count: 1') - await expect(page.locator('#event-count')).toContainText('Event Count: 3') - - // Verify event contents - await expect(page.locator('.notification-event').nth(0)).toContainText('Mixed test notification') - await expect(page.locator('.custom-event').nth(0)).toContainText('Mixed test custom (count: 2)') - await expect(page.locator('.notification-event').nth(1)).toContainText('Second notification') - }) - - test('should handle rapid sequential events', async ({ page }) => { - await page.goto('/events') - await syncLV(page) - - // Send multiple events rapidly - for (let i = 1; i <= 5; i++) { - await page.fill('#message-input', `Rapid message ${i}`) - await page.click('#send-notification-btn') - } - - await syncLV(page) - - // Verify all events are received - await expect(page.locator('#notification-count')).toContainText('Notification Count: 5') - await expect(page.locator('.notification-event')).toHaveCount(5) - await expect(page.locator('#event-count')).toContainText('Event Count: 5') - - // Verify first and last messages - await expect(page.locator('.notification-event').nth(0)).toContainText('Rapid message 1') - await expect(page.locator('.notification-event').nth(4)).toContainText('Rapid message 5') - }) -}) \ No newline at end of file diff --git a/test/e2e/features/form/form.spec.js b/test/e2e/features/form/form.spec.js deleted file mode 100644 index abb4c08b..00000000 --- a/test/e2e/features/form/form.spec.js +++ /dev/null @@ -1,644 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV, evalLV } from "../../utils.js" - -test.describe("useLiveForm E2E Tests", () => { - test.beforeEach(async ({ page }) => { - await page.goto("/form-test") - await syncLV(page) - }) - - test("form initializes with empty state and is invalid", async ({ page }) => { - // Verify form component is mounted - await expect(page.locator("[data-pw-form]")).toBeVisible() - - // Check initial form state - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: false") - await expect(page.locator("[data-pw-is-touched]")).toHaveText("Touched: false") - - // Submit button should be disabled initially - await expect(page.locator("[data-pw-submit]")).toBeDisabled() - }) - - test("basic field validation and form state tracking", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - - // Fill name field (but not enough characters) - use type instead of fill - await nameInput.type("A") - await nameInput.blur() - await page.waitForTimeout(500) // Give time for debounced events - await syncLV(page) - - // Form should be touched and dirty but not valid - await expect(page.locator("[data-pw-is-touched]")).toHaveText("Touched: true") - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: true") - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Should show validation error after server validation - await expect(page.locator("[data-pw-name-error]")).toBeVisible() - - // Fill valid data - await nameInput.clear() - await nameInput.type("John Doe") - await emailInput.type("john@example.com") - await acceptTermsCheckbox.check() // Accept terms is now required - await page.waitForTimeout(500) // Give time for debounced events - await syncLV(page) - - // Form should now be valid - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - await expect(page.locator("[data-pw-submit]")).toBeEnabled() - }) - - test("nested field validation (profile bio)", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const bioInput = page.locator("[data-pw-bio-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - - // Fill required fields first - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await acceptTermsCheckbox.check() - - // Fill bio with insufficient content - await bioInput.fill("Short") - await bioInput.blur() - await syncLV(page) - - // Should show bio validation error - await expect(page.locator("[data-pw-bio-error]")).toBeVisible() - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Fill with valid bio - await bioInput.fill("This is a valid bio with enough characters to pass validation") - await bioInput.blur() - await syncLV(page) - - // Form should be valid now - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - }) - - test("array field operations - skills", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - - // Fill required fields - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - - // Initially no skills - await expect(page.locator("[data-pw-skill-item]")).toHaveCount(0) - - // Add a skill - await page.locator("[data-pw-add-skill]").click() - await expect(page.locator("[data-pw-skill-item]")).toHaveCount(1) - - // Fill the skill - await page.locator('[data-pw-skill-input="0"]').fill("JavaScript") - await syncLV(page) - - // Add another skill - await page.locator("[data-pw-add-skill]").click() - await expect(page.locator("[data-pw-skill-item]")).toHaveCount(2) - - // Fill second skill - await page.locator('[data-pw-skill-input="1"]').fill("TypeScript") - await syncLV(page) - - // Remove first skill - await page.locator('[data-pw-remove-skill="0"]').click() - await expect(page.locator("[data-pw-skill-item]")).toHaveCount(1) - - // Remaining skill should be TypeScript - await expect(page.locator('[data-pw-skill-input="0"]')).toHaveValue("TypeScript") - }) - - test("nested array field operations - items with tags", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - - // Fill required fields - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - - // Add an item - await page.locator("[data-pw-add-item]").click() - await expect(page.locator("[data-pw-item]")).toHaveCount(1) - - // Fill item title - await page.locator('[data-pw-item-title="0"]').fill("First Item") - - // Add tags to the item - await page.locator('[data-pw-add-tag="0"]').click() - await page.locator('[data-pw-add-tag="0"]').click() - await expect(page.locator("[data-pw-tag-item]")).toHaveCount(2) - - // Fill tags - await page.locator('[data-pw-tag-input="0-0"]').fill("important") - await page.locator('[data-pw-tag-input="0-1"]').fill("urgent") - - // Add second item - await page.locator("[data-pw-add-item]").click() - await expect(page.locator("[data-pw-item]")).toHaveCount(2) - - // Fill second item - await page.locator('[data-pw-item-title="1"]').fill("Second Item") - await page.locator('[data-pw-add-tag="1"]').click() - await page.locator('[data-pw-tag-input="1-0"]').fill("normal") - - // Remove first tag from first item - await page.locator('[data-pw-remove-tag="0-0"]').click() - - // Should have one tag left in first item - const firstItemTags = page.locator('[data-pw-item="0"] [data-pw-tag-item]') - await expect(firstItemTags).toHaveCount(1) - await expect(page.locator('[data-pw-tag-input="0-0"]')).toHaveValue("urgent") - - // Remove first item entirely - await page.locator('[data-pw-remove-item="0"]').click() - await expect(page.locator("[data-pw-item]")).toHaveCount(1) - - // Remaining item should be "Second Item" - await expect(page.locator('[data-pw-item-title="0"]')).toHaveValue("Second Item") - }) - - test("form validation lifecycle with server errors", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - - // Fill invalid data that will trigger server validation - await nameInput.fill("A") // Too short - await emailInput.fill("invalid-email") // Invalid format - await nameInput.blur() - await emailInput.blur() - await acceptTermsCheckbox.check() - await syncLV(page) - - // Should show validation errors - await expect(page.locator("[data-pw-name-error]")).toBeVisible() - await expect(page.locator("[data-pw-email-error]")).toBeVisible() - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Fix the name - await nameInput.fill("John Doe") - await nameInput.blur() - await syncLV(page) - - // Name error should be gone, email error should remain - await expect(page.locator("[data-pw-name-error]")).not.toBeVisible() - await expect(page.locator("[data-pw-email-error]")).toBeVisible() - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Fix the email - await emailInput.fill("john@example.com") - await emailInput.blur() - await syncLV(page) - - // All errors should be gone - await expect(page.locator("[data-pw-name-error]")).not.toBeVisible() - await expect(page.locator("[data-pw-email-error]")).not.toBeVisible() - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - }) - - test("form submission with valid data", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const ageInput = page.locator("[data-pw-age-input]") - const bioInput = page.locator("[data-pw-bio-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - - // Fill valid form data - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await ageInput.fill("30") - await bioInput.fill("This is a comprehensive bio with sufficient content for validation") - await acceptTermsCheckbox.check() - // let's wait for the debounce to finish - await page.waitForTimeout(150) - await syncLV(page) - - // Add some skills - await page.locator("[data-pw-add-skill]").click() - await page.locator('[data-pw-skill-input="0"]').fill("JavaScript") - await page.locator("[data-pw-add-skill]").click() - await page.locator('[data-pw-skill-input="1"]').fill("Vue.js") - - // Add an item with tags - await page.locator("[data-pw-add-item]").click() - await page.locator('[data-pw-item-title="0"]').fill("Build awesome apps") - await page.locator('[data-pw-add-tag="0"]').click() - await page.locator('[data-pw-tag-input="0-0"]').fill("development") - - await syncLV(page) - - // Form should be valid - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - await expect(page.locator("[data-pw-submit]")).toBeEnabled() - - // Submit the form - await page.locator("[data-pw-submit]").click() - await syncLV(page) - - // Form should be reset after successful submission - await expect(page.locator("[data-pw-name-input]")).toHaveValue("") - await expect(page.locator("[data-pw-email-input]")).toHaveValue("") - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: false") - await expect(page.locator("[data-pw-is-touched]")).toHaveText("Touched: false") - }) - - test("form reset functionality", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - - // Fill some data - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await page.locator("[data-pw-add-skill]").click() - await page.locator('[data-pw-skill-input="0"]').fill("JavaScript") - - await syncLV(page) - - // Form should be dirty - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: true") - - // Reset the form - await page.locator("[data-pw-reset]").click() - - // Form should be clean - await expect(page.locator("[data-pw-name-input]")).toHaveValue("") - await expect(page.locator("[data-pw-email-input]")).toHaveValue("") - await expect(page.locator("[data-pw-skill-item]")).toHaveCount(0) - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: false") - await expect(page.locator("[data-pw-is-touched]")).toHaveText("Touched: false") - }) - - test("debounced validation events", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - - // Type rapidly to test debouncing - await nameInput.focus() - await nameInput.pressSequentially("John", { delay: 50 }) - - // Should not trigger validation immediately - await page.waitForTimeout(100) - - // Continue typing - await nameInput.pressSequentially(" Doe", { delay: 50 }) - - // Wait for debounce period (300ms) plus some buffer - await page.waitForTimeout(400) - await syncLV(page) - - // Should have final value and validation should have occurred - await expect(nameInput).toHaveValue("John Doe") - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: true") - }) - - test("accessibility attributes are properly set", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - - // Fill invalid data to trigger errors - await nameInput.fill("A") - await emailInput.fill("invalid") - await nameInput.blur() - await emailInput.blur() - await syncLV(page) - - // Check aria-invalid attributes - await expect(nameInput).toHaveAttribute("aria-invalid", "true") - await expect(emailInput).toHaveAttribute("aria-invalid", "true") - - // Check aria-describedby attributes - await expect(nameInput).toHaveAttribute("aria-describedby") - await expect(emailInput).toHaveAttribute("aria-describedby") - - // Fix the errors - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await nameInput.blur() - await emailInput.blur() - await syncLV(page) - - // Aria-invalid should be false - await expect(nameInput).toHaveAttribute("aria-invalid", "false") - await expect(emailInput).toHaveAttribute("aria-invalid", "false") - }) - - test("form maintains state during LiveView updates", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - - // Start filling the form - await nameInput.focus() - await nameInput.fill("John") - - // Trigger a server action that might update the form - await emailInput.fill("john@example.com") - await emailInput.blur() - await syncLV(page) - - // Continue editing the name field while server processes - await nameInput.focus() - await nameInput.fill("John Doe") - - // The name field should retain the user's input - await expect(nameInput).toHaveValue("John Doe") - await expect(emailInput).toHaveValue("john@example.com") - }) - - test("complex nested validation with items and tags", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - - // Fill required fields - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await acceptTermsCheckbox.check() - - // Add item with invalid title (too short) - await page.locator("[data-pw-add-item]").click() - await page.locator('[data-pw-item-title="0"]').fill("Hi") // Too short - await page.locator('[data-pw-item-title="0"]').blur() - await syncLV(page) - - // Form should be invalid due to item validation - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Fix the item title - await page.locator('[data-pw-item-title="0"]').fill("Valid Item Title") - await page.locator('[data-pw-item-title="0"]').blur() - await syncLV(page) - - // Form should be valid now - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - - // Add a short tag (which should be invalid) - await page.locator('[data-pw-add-tag="0"]').click() - await page.locator('[data-pw-tag-input="0-0"]').fill("a") - await page.locator('[data-pw-tag-input="0-0"]').blur() - await syncLV(page) - - // Form should be invalid due to short tag - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Fill the tag - await page.locator('[data-pw-tag-input="0-0"]').fill("valid-tag") - await page.locator('[data-pw-tag-input="0-0"]').blur() - await syncLV(page) - - // Form should be valid again - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - }) - - test("single checkbox functionality", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - const newsletterCheckbox = page.locator("[data-pw-newsletter]") - - // Fill required fields first - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await syncLV(page) - - // Initially checkboxes should be unchecked - await expect(acceptTermsCheckbox).not.toBeChecked() - await expect(newsletterCheckbox).not.toBeChecked() - - // Form should be invalid because acceptTerms is required - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - - // Check accept terms - await acceptTermsCheckbox.check() - await syncLV(page) - - // Form should now be valid - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).not.toBeChecked() - - // Check newsletter (optional) - await newsletterCheckbox.check() - await syncLV(page) - - // Form should still be valid, both checkboxes checked - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - - // Uncheck accept terms - form should become invalid - await acceptTermsCheckbox.uncheck() - await syncLV(page) - - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: false") - await expect(acceptTermsCheckbox).not.toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - - // Should show error message for accept terms - await expect(page.locator("[data-pw-accept-terms-error]")).toBeVisible() - }) - - test("multi-checkbox array functionality", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - const emailPrefCheckbox = page.locator("[data-pw-preferences-email]") - const smsPrefCheckbox = page.locator("[data-pw-preferences-sms]") - const pushPrefCheckbox = page.locator("[data-pw-preferences-push]") - const syncDebouncedForm = async () => { - await page.waitForTimeout(350) - await syncLV(page) - } - - // Fill required fields - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await acceptTermsCheckbox.check() - await syncLV(page) - - // Initially all preference checkboxes should be unchecked - await expect(emailPrefCheckbox).not.toBeChecked() - await expect(smsPrefCheckbox).not.toBeChecked() - await expect(pushPrefCheckbox).not.toBeChecked() - - // Check email preference - await emailPrefCheckbox.check() - await syncDebouncedForm() - - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).not.toBeChecked() - await expect(pushPrefCheckbox).not.toBeChecked() - - // Check SMS preference as well - await smsPrefCheckbox.check() - await syncDebouncedForm() - - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).toBeChecked() - await expect(pushPrefCheckbox).not.toBeChecked() - - // Check all preferences - await pushPrefCheckbox.check() - await syncDebouncedForm() - - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).toBeChecked() - await expect(pushPrefCheckbox).toBeChecked() - - // Uncheck middle one (SMS) - await smsPrefCheckbox.uncheck() - await syncDebouncedForm() - - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).not.toBeChecked() - await expect(pushPrefCheckbox).toBeChecked() - - // Uncheck all - await emailPrefCheckbox.uncheck() - await pushPrefCheckbox.uncheck() - await syncDebouncedForm() - - await expect(emailPrefCheckbox).not.toBeChecked() - await expect(smsPrefCheckbox).not.toBeChecked() - await expect(pushPrefCheckbox).not.toBeChecked() - }) - - test("checkbox state persistence during form operations", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - const newsletterCheckbox = page.locator("[data-pw-newsletter]") - const emailPrefCheckbox = page.locator("[data-pw-preferences-email]") - const smsPrefCheckbox = page.locator("[data-pw-preferences-sms]") - - // Fill form with valid data and check some boxes - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await acceptTermsCheckbox.check() - await newsletterCheckbox.check() - await emailPrefCheckbox.check() - await smsPrefCheckbox.check() - await syncLV(page) - - // Verify all are checked - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).toBeChecked() - - // Add some dynamic content (array items) to trigger more server updates - await page.locator("[data-pw-add-skill]").click() - await page.locator('[data-pw-skill-input="0"]').fill("JavaScript") - await syncLV(page) - - // Checkbox states should be preserved - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).toBeChecked() - - // Make some changes to trigger validation - await nameInput.fill("J") // Too short, will cause validation error - await nameInput.blur() - await syncLV(page) - - // Checkbox states should still be preserved even with validation errors - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).toBeChecked() - - // Fix the name - await nameInput.fill("John Doe") - await nameInput.blur() - await syncLV(page) - - // Checkbox states should still be preserved - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - await expect(emailPrefCheckbox).toBeChecked() - await expect(smsPrefCheckbox).toBeChecked() - }) - - test("checkbox form reset functionality", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - const newsletterCheckbox = page.locator("[data-pw-newsletter]") - const emailPrefCheckbox = page.locator("[data-pw-preferences-email]") - const pushPrefCheckbox = page.locator("[data-pw-preferences-push]") - - // Fill form and check boxes - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await acceptTermsCheckbox.check() - await newsletterCheckbox.check() - await emailPrefCheckbox.check() - await pushPrefCheckbox.check() - await syncLV(page) - - // Verify everything is set - await expect(acceptTermsCheckbox).toBeChecked() - await expect(newsletterCheckbox).toBeChecked() - await expect(emailPrefCheckbox).toBeChecked() - await expect(pushPrefCheckbox).toBeChecked() - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: true") - - // Reset the form - await page.locator("[data-pw-reset]").click() - - // All checkboxes should be unchecked - await expect(acceptTermsCheckbox).not.toBeChecked() - await expect(newsletterCheckbox).not.toBeChecked() - await expect(emailPrefCheckbox).not.toBeChecked() - await expect(pushPrefCheckbox).not.toBeChecked() - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: false") - }) - - test("checkbox form submission with all checkbox states", async ({ page }) => { - const nameInput = page.locator("[data-pw-name-input]") - const emailInput = page.locator("[data-pw-email-input]") - const ageInput = page.locator("[data-pw-age-input]") - const acceptTermsCheckbox = page.locator("[data-pw-accept-terms]") - const newsletterCheckbox = page.locator("[data-pw-newsletter]") - const emailPrefCheckbox = page.locator("[data-pw-preferences-email]") - const smsPrefCheckbox = page.locator("[data-pw-preferences-sms]") - - // Fill form with valid data - await nameInput.fill("John Doe") - await emailInput.fill("john@example.com") - await ageInput.fill("30") - await acceptTermsCheckbox.check() - await newsletterCheckbox.check() - await emailPrefCheckbox.check() - await smsPrefCheckbox.check() - - // Add bio to make form valid - const bioInput = page.locator("[data-pw-bio-input]") - await bioInput.fill("This is a comprehensive bio with sufficient content for validation") - - await syncLV(page) - - // Form should be valid - await expect(page.locator("[data-pw-is-valid]")).toHaveText("Valid: true") - await expect(page.locator("[data-pw-submit]")).toBeEnabled() - - // Submit the form - await page.locator("[data-pw-submit]").click() - await syncLV(page) - - // Form should be reset after successful submission - await expect(acceptTermsCheckbox).not.toBeChecked() - await expect(newsletterCheckbox).not.toBeChecked() - await expect(emailPrefCheckbox).not.toBeChecked() - await expect(smsPrefCheckbox).not.toBeChecked() - await expect(page.locator("[data-pw-is-dirty]")).toHaveText("Dirty: false") - await expect(page.locator("[data-pw-is-touched]")).toHaveText("Touched: false") - }) -}) diff --git a/test/e2e/features/headless/headless.spec.js b/test/e2e/features/headless/headless.spec.js deleted file mode 100644 index 6895decb..00000000 --- a/test/e2e/features/headless/headless.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV } from "../../utils.js" - -test("headless component exposes reactive props via useLiveVue(elementId)", async ({ page }) => { - await page.goto("/headless") - await syncLV(page) - - await expect(page.locator("[data-pw-count]")).toHaveText("0") - await expect(page.locator("[data-pw-label]")).toHaveText("Hello") - - await page.locator("[data-pw-increment]").click() - await syncLV(page) - await expect(page.locator("[data-pw-count]")).toHaveText("1") - - await page.locator("[data-pw-increment]").click() - await syncLV(page) - await expect(page.locator("[data-pw-count]")).toHaveText("2") -}) - -test("headless component updates non-numeric props reactively", async ({ page }) => { - await page.goto("/headless") - await syncLV(page) - - await expect(page.locator("[data-pw-label]")).toHaveText("Hello") - - await page.locator("[data-pw-label-input]").fill("Updated") - await page.locator("[data-pw-update-label]").click() - await syncLV(page) - await expect(page.locator("[data-pw-label]")).toHaveText("Updated") -}) - -test("headless component renders no visible UI", async ({ page }) => { - await page.goto("/headless") - await syncLV(page) - - const headlessEl = page.locator("#data-source") - await expect(headlessEl).toBeAttached() - await expect(headlessEl).not.toHaveAttribute("data-name") - await expect(headlessEl).toHaveText("") -}) diff --git a/test/e2e/features/navigation/navigation.spec.js b/test/e2e/features/navigation/navigation.spec.js deleted file mode 100644 index 1fd27ba2..00000000 --- a/test/e2e/features/navigation/navigation.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -import { test, expect } from '@playwright/test' -import { syncLV } from '../../utils.js' - -test.describe('useLiveNavigation', () => { - test('should patch query params and navigate between routes', async ({ page }) => { - // Start at the first navigation route - await page.goto('/navigation/test1') - await syncLV(page) - - // Verify initial state - await expect(page.locator('#current-params')).toContainText('"page":"test1"') - await expect(page.locator('#current-query')).toContainText('{}') - - // Test patch functionality - should update query params - await page.click('#patch-btn') - await syncLV(page) - - // Verify query params were updated - await expect(page.locator('#current-query')).toContainText('"foo":"bar"') - await expect(page.locator('#current-query')).toContainText('"timestamp"') - // URL should still have the same page param but with query params - await expect(page).toHaveURL(/\/navigation\/test1\?.*foo=bar/) - - // Test navigate functionality - should change to alt route - await page.click('#navigate-btn') - await syncLV(page) - - // Verify navigation to alt route - await expect(page.locator('#current-params')).toContainText('"page":"test2"') - await expect(page.locator('#current-query')).toContainText('"baz":"qux"') - await expect(page).toHaveURL(/\/navigation\/alt\/test2\?.*baz=qux/) - - // Test navigate back - await page.click('#navigate-back-btn') - await syncLV(page) - - // Verify navigation back to original route - await expect(page.locator('#current-params')).toContainText('"page":"test1"') - await expect(page.locator('#current-query')).toContainText('{}') - await expect(page).toHaveURL('/navigation/test1') - }) - - test('should handle direct route access with params', async ({ page }) => { - // Test direct access to alt route with query params - await page.goto('/navigation/alt/direct?test=value&count=42') - await syncLV(page) - - // Verify params and query params are correctly parsed - await expect(page.locator('#current-params')).toContainText('"page":"direct"') - await expect(page.locator('#current-query')).toContainText('"test":"value"') - await expect(page.locator('#current-query')).toContainText('"count":"42"') - }) -}) \ No newline at end of file diff --git a/test/e2e/features/persistent-layout/persistent-layout.spec.js b/test/e2e/features/persistent-layout/persistent-layout.spec.js deleted file mode 100644 index 91cac3ce..00000000 --- a/test/e2e/features/persistent-layout/persistent-layout.spec.js +++ /dev/null @@ -1,78 +0,0 @@ -import { test, expect } from "@playwright/test" -import { evalLV, syncLV } from "../../utils.js" - -const waitForPage = async (page, text) => - expect(page.locator("[data-pw-page]")).toHaveText(text, { timeout: 5000 }) - -test("SSR renders the injected layout tree before hydration", async ({ browser }) => { - const context = await browser.newContext({ javaScriptEnabled: false }) - const page = await context.newPage() - - await page.goto("/persistent-layout/page1") - - await expect(page.locator("[data-pw-layout-counter]")).toHaveText("0") - await expect(page.locator("[data-pw-page]")).toHaveText("page1") - await expect(page.locator("[data-pw-nested]")).toHaveText("I'm nested!") - await expect(page.locator("[data-pw-sidebar-content]")).toContainText("Sidebar") - - await context.close() -}) - -test("layout state persists across push_patch navigation", async ({ page }) => { - await page.goto("/persistent-layout/page1") - await syncLV(page) - await waitForPage(page, "page1") - - // Increment layout counter a few times - await page.locator("[data-pw-layout-btn]").click() - await page.locator("[data-pw-layout-btn]").click() - await page.locator("[data-pw-layout-btn]").click() - await expect(page.locator("[data-pw-layout-counter]")).toHaveText("3") - - // Navigate to page2 via push_patch - await evalLV(page, `{:noreply, Phoenix.LiveView.push_patch(socket, to: "/persistent-layout/page2")}`) - await syncLV(page) - await waitForPage(page, "page2") - - // Layout counter should be preserved (Vue state survived navigation) - await expect(page.locator("[data-pw-layout-counter]")).toHaveText("3") - - // Page component should see layout counter via slot props - await expect(page.locator("[data-pw-page-layout-count]")).toHaveText("3") - - // Incrementing layout counter should update in both places - await page.locator("[data-pw-layout-btn]").click() - await expect(page.locator("[data-pw-layout-counter]")).toHaveText("4") - await expect(page.locator("[data-pw-page-layout-count]")).toHaveText("4") -}) - -test("nested injection: component injected into an injected component", async ({ page }) => { - await page.goto("/persistent-layout/page1") - await syncLV(page) - await waitForPage(page, "page1") - - // Nested component should render inside the page component's slot - await expect(page.locator("[data-pw-nested]")).toHaveText("I'm nested!") - - // Navigate — nested should survive (it's inside the persistent layout tree) - await evalLV(page, `{:noreply, Phoenix.LiveView.push_patch(socket, to: "/persistent-layout/page2")}`) - await syncLV(page) - await waitForPage(page, "page2") - - // Nested component should still be there - await expect(page.locator("[data-pw-nested]")).toHaveText("I'm nested!", { timeout: 5000 }) -}) - -test("named slot injection via v-inject:slotname", async ({ page }) => { - await page.goto("/persistent-layout/page1") - await syncLV(page) - await waitForPage(page, "page1") - - // Sidebar should render in the named slot with slot props - await expect(page.locator("[data-pw-sidebar-content]")).toContainText("Sidebar") - await expect(page.locator("[data-pw-sidebar-content]")).toContainText("layout: 0") - - // Incrementing layout counter should update sidebar's slot props too - await page.locator("[data-pw-layout-btn]").click() - await expect(page.locator("[data-pw-sidebar-content]")).toContainText("layout: 1") -}) diff --git a/test/e2e/features/prop-diff/prop-diff.spec.js b/test/e2e/features/prop-diff/prop-diff.spec.js deleted file mode 100644 index b9e702b6..00000000 --- a/test/e2e/features/prop-diff/prop-diff.spec.js +++ /dev/null @@ -1,226 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV } from "../../utils.js" - -// Read and parse props from the page -const getProps = async page => { - await syncLV(page) - - const propsJson = await page.locator('[data-testid="props-json"]').textContent() - return JSON.parse(propsJson) -} - -test.describe("LiveVue Prop Diff E2E Tests", () => { - test.beforeEach(async ({ page }) => { - await page.goto("/prop-diff-test") - await syncLV(page) - - // Verify Vue component is mounted - await expect(page.locator('[phx-hook="VueHook"]')).toBeVisible() - }) - - test("initial render displays all props correctly", async ({ page }) => { - // Check initial props are rendered - const props = await getProps(page) - - expect(props.simple_string).toBe("hello") - expect(props.simple_number).toBe(42) - expect(props.simple_boolean).toBe(true) - expect(props.simple_list).toEqual(["a", "b", "c"]) - expect(props.simple_map).toEqual({ key1: "value1", key2: "value2" }) - expect(props.nested_data.user).toEqual({ name: "John", age: 30 }) - expect(props.nested_data.settings).toEqual({ theme: "dark", notifications: true }) - expect(props.list_of_maps).toEqual([ - { id: 1, name: "Alice", role: "admin" }, - { id: 2, name: "Bob", role: "user" }, - ]) - }) - - test("simple string change is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-change-string"]').click() - - const props = await getProps(page) - - expect(props.simple_string).toBe("changed") - // Other props should remain unchanged - expect(props.simple_number).toBe(42) - expect(props.simple_boolean).toBe(true) - }) - - test("simple number change is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-change-number"]').click() - - const props = await getProps(page) - - expect(props.simple_number).toBe(99) - // Other props should remain unchanged - expect(props.simple_string).toBe("hello") - expect(props.simple_boolean).toBe(true) - }) - - test("boolean toggle is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-toggle-boolean"]').click() - - const props = await getProps(page) - - expect(props.simple_boolean).toBe(false) - - // Toggle back - await page.locator('[data-testid="btn-toggle-boolean"]').click() - - const props2 = await getProps(page) - expect(props2.simple_boolean).toBe(true) - }) - - test("array addition is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-add-to-list"]').click() - - const props = await getProps(page) - - expect(props.simple_list).toEqual(["a", "b", "c", "d"]) - }) - - test("array removal is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-remove-from-list"]').click() - - const props = await getProps(page) - - expect(props.simple_list).toEqual(["b", "c"]) - }) - - test("array replacement is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-replace-in-list"]').click() - - const props = await getProps(page) - - expect(props.simple_list).toEqual(["a", "REPLACED", "c"]) - }) - - test("map addition is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-add-to-map"]').click() - - const props = await getProps(page) - - expect(props.simple_map).toEqual({ - key1: "value1", - key2: "value2", - key3: "value3", - }) - }) - - test("map removal is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-remove-from-map"]').click() - - const props = await getProps(page) - - expect(props.simple_map).toEqual({ key2: "value2" }) - }) - - test("nested object property change is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-change-nested-name"]').click() - - const props = await getProps(page) - - expect(props.nested_data.user.name).toBe("Jane") - // Other nested properties should remain unchanged - expect(props.nested_data.user.age).toBe(30) - expect(props.nested_data.settings).toEqual({ theme: "dark", notifications: true }) - }) - - test("nested object number change is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-change-nested-age"]').click() - - const props = await getProps(page) - - expect(props.nested_data.user.age).toBe(25) - // Other properties should remain unchanged - expect(props.nested_data.user.name).toBe("John") - }) - - test("adding nested property is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-add-nested-setting"]').click() - - const props = await getProps(page) - - expect(props.nested_data.settings).toEqual({ - theme: "dark", - notifications: true, - language: "en", - }) - }) - - test("setting value to nil is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-set-nil"]').click() - - const props = await getProps(page) - - expect(props.simple_string).toBe(null) - // Other props should remain unchanged - expect(props.simple_number).toBe(42) - expect(props.simple_boolean).toBe(true) - }) - - test("adding item to list of maps is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-add-list-item"]').click() - - const props = await getProps(page) - - expect(props.list_of_maps).toEqual([ - { id: 1, name: "Alice", role: "admin" }, - { id: 2, name: "Bob", role: "user" }, - { id: 3, name: "Charlie", role: "guest" }, - ]) - }) - - test("updating item in list of maps is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-update-list-item"]').click() - - const props = await getProps(page) - - expect(props.list_of_maps).toEqual([ - { id: 1, name: "Alice Updated", role: "admin" }, - { id: 2, name: "Bob", role: "user" }, - ]) - }) - - test("removing item from list of maps is applied via diff", async ({ page }) => { - await page.locator('[data-testid="btn-remove-list-item"]').click() - - const props = await getProps(page) - - expect(props.list_of_maps).toEqual([{ id: 1, name: "Alice", role: "admin" }]) - }) - - test("multiple consecutive changes are applied correctly", async ({ page }) => { - // Make multiple changes in sequence - await page.locator('[data-testid="btn-change-string"]').click() - await page.locator('[data-testid="btn-change-number"]').click() - await page.locator('[data-testid="btn-add-to-list"]').click() - await page.locator('[data-testid="btn-change-nested-name"]').click() - - const props = await getProps(page) - - expect(props.simple_string).toBe("changed") - expect(props.simple_number).toBe(99) - expect(props.simple_list).toEqual(["a", "b", "c", "d"]) - expect(props.nested_data.user.name).toBe("Jane") - - // Unchanged properties should remain the same - expect(props.simple_boolean).toBe(true) - expect(props.nested_data.user.age).toBe(30) - }) - - test("Vue component can access all updated props reactively", async ({ page }) => { - // Verify that Vue component reactively updates when props change - const initial = await getProps(page) - - // Make a change - await page.locator('[data-testid="btn-change-string"]').click() - - // Wait for Vue to update (should be immediate) - const updated = await getProps(page) - - // Verify the change is reflected immediately in the Vue component - expect(updated.simple_string).toBe("changed") - expect(updated.simple_string).not.toBe(initial.simple_string) - }) -}) diff --git a/test/e2e/features/reconnect/reconnect.spec.js b/test/e2e/features/reconnect/reconnect.spec.js deleted file mode 100644 index 64d9a616..00000000 --- a/test/e2e/features/reconnect/reconnect.spec.js +++ /dev/null @@ -1,68 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV } from "../../utils.js" - -const reconnect = async page => { - await page.evaluate(() => { - return new Promise(resolve => { - window.liveSocket.disconnect(() => { - setTimeout(() => { - window.liveSocket.connect() - resolve() - }, 200) - }) - }) - }) - await syncLV(page) -} - -test.describe("LiveVue Reconnect", () => { - test("props are refreshed from server after socket reconnect", async ({ page }) => { - await page.goto("/reconnect") - await syncLV(page) - - // Verify initial state - await expect(page.locator("[data-pw-count]")).toHaveText("0") - await expect(page.locator("[data-pw-label]")).toHaveText("initial") - - // Update state — this sends a diff via data-props-diff - await page.locator("button").click() - await syncLV(page) - await expect(page.locator("[data-pw-count]")).toHaveText("1") - await expect(page.locator("[data-pw-label]")).toHaveText("updated") - - // Disconnect and reconnect. - // Without the fix, the stale data-props-diff from the last update - // would be re-applied, leaving Vue showing the old state. - await reconnect(page) - - // New process mounted with initial state — Vue must reflect that - await expect(page.locator("[data-pw-count]")).toHaveText("0") - await expect(page.locator("[data-pw-label]")).toHaveText("initial") - }) - - test("streams are restored after socket reconnect", async ({ page }) => { - await page.goto("/reconnect") - await syncLV(page) - - // Verify initial stream: 3 items - await expect(page.locator("[data-pw-item-count]")).toHaveText("3") - await expect(page.locator("[data-pw-item='1']")).toHaveText("Alpha") - await expect(page.locator("[data-pw-item='2']")).toHaveText("Beta") - await expect(page.locator("[data-pw-item='3']")).toHaveText("Gamma") - - // Update — adds a 4th stream item - await page.locator("button").click() - await syncLV(page) - await expect(page.locator("[data-pw-item-count]")).toHaveText("4") - await expect(page.locator("[data-pw-item='4']")).toHaveText("Delta") - - // Reconnect — new process re-mounts with only the original 3 items - await reconnect(page) - - await expect(page.locator("[data-pw-item-count]")).toHaveText("3") - await expect(page.locator("[data-pw-item='1']")).toHaveText("Alpha") - await expect(page.locator("[data-pw-item='2']")).toHaveText("Beta") - await expect(page.locator("[data-pw-item='3']")).toHaveText("Gamma") - await expect(page.locator("[data-pw-item='4']")).toHaveCount(0) - }) -}) diff --git a/test/e2e/features/slot/slot.spec.js b/test/e2e/features/slot/slot.spec.js deleted file mode 100644 index 3bafb900..00000000 --- a/test/e2e/features/slot/slot.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV } from "../../utils.js" - -test.describe("LiveVue Slot Non-ASCII Character Tests", () => { - test("renders non-ASCII characters in slots correctly", async ({ page }) => { - await page.goto("/slot-test") - await syncLV(page) - - // Test 1: Polish characters - const polishSlot = page.locator('[data-pw-label]:has-text("Polish")').locator('..').locator('[data-pw-slot]') - await expect(polishSlot).toContainText("Zażółć gęślą jaźń") - - // Test 2: Japanese characters - const japaneseSlot = page.locator('[data-pw-label]:has-text("Japanese")').locator('..').locator('[data-pw-slot]') - await expect(japaneseSlot).toContainText("こんにちは世界") - - // Test 3: Emoji - const emojiSlot = page.locator('[data-pw-label]:has-text("Emoji")').locator('..').locator('[data-pw-slot]') - await expect(emojiSlot).toContainText("Hello 🌍 World 🎉 Party 🚀") - - // Test 4: Mixed scripts (Russian, Chinese, Arabic) - const mixedSlot = page.locator('[data-pw-label]:has-text("Mixed")').locator('..').locator('[data-pw-slot]') - await expect(mixedSlot).toContainText("Привет мир!") - await expect(mixedSlot).toContainText("你好世界!") - await expect(mixedSlot).toContainText("مرحبا بالعالم") - - // Test 5: Special Latin characters - const specialSlot = page.locator('[data-pw-label]:has-text("Special")').locator('..').locator('[data-pw-slot]') - await expect(specialSlot).toContainText("Ñoño café résumé naïve") - }) -}) diff --git a/test/e2e/features/stream/stream.spec.js b/test/e2e/features/stream/stream.spec.js deleted file mode 100644 index 0e768424..00000000 --- a/test/e2e/features/stream/stream.spec.js +++ /dev/null @@ -1,433 +0,0 @@ -import { test, expect } from "@playwright/test" -import { syncLV } from "../../utils.js" - -test.describe("LiveVue Stream Integration", () => { - test.beforeEach(async ({ page }) => { - await page.goto("/streams") - await syncLV(page) - }) - - test("renders initial stream items", async ({ page }) => { - // Check that initial items are rendered - await expect(page.locator('[data-testid="item-1"]')).toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).toBeVisible() - - // Check item content - await expect(page.locator('[data-testid="item-1"] [data-testid="item-name"]')).toHaveText("Item 1") - await expect(page.locator('[data-testid="item-1"] [data-testid="item-description"]')).toHaveText("First item") - await expect(page.locator('[data-testid="item-1"] [data-testid="item-id"]')).toHaveText("ID: 1") - - // Check item count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (3)") - }) - - test("adds new items to stream", async ({ page }) => { - // Fill form and add new item - await page.fill('[data-testid="name-input"]', "New Item") - await page.fill('[data-testid="description-input"]', "This is a new item") - await page.click('[data-testid="add-button"]') - - await syncLV(page) - - // Check that new item appears - await expect(page.locator('[data-testid="item-4"]')).toBeVisible() - await expect(page.locator('[data-testid="item-4"] [data-testid="item-name"]')).toHaveText("New Item") - await expect(page.locator('[data-testid="item-4"] [data-testid="item-description"]')).toHaveText( - "This is a new item" - ) - await expect(page.locator('[data-testid="item-4"] [data-testid="item-id"]')).toHaveText("ID: 4") - - // Check updated count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (4)") - - // Check that form was cleared - await expect(page.locator('[data-testid="name-input"]')).toHaveValue("") - await expect(page.locator('[data-testid="description-input"]')).toHaveValue("") - }) - - test("adds multiple items in sequence", async ({ page }) => { - // Add first item - await page.fill('[data-testid="name-input"]', "Item A") - await page.fill('[data-testid="description-input"]', "Description A") - await page.click('[data-testid="add-button"]') - await syncLV(page) - - // Add second item - await page.fill('[data-testid="name-input"]', "Item B") - await page.fill('[data-testid="description-input"]', "Description B") - await page.click('[data-testid="add-button"]') - await syncLV(page) - - // Check both items exist - await expect(page.locator('[data-testid="item-4"]')).toBeVisible() - await expect(page.locator('[data-testid="item-5"]')).toBeVisible() - - // Check count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (5)") - }) - - test("removes individual items from stream", async ({ page }) => { - // Remove item 2 - await page.click('[data-testid="remove-2"]') - await syncLV(page) - - // Check that item 2 is gone but others remain - await expect(page.locator('[data-testid="item-1"]')).toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).toBeVisible() - - // Check updated count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (2)") - }) - - test("removes multiple items", async ({ page }) => { - // Remove items 1 and 3 - await page.click('[data-testid="remove-1"]') - await syncLV(page) - await page.click('[data-testid="remove-3"]') - await syncLV(page) - - // Check only item 2 remains - await expect(page.locator('[data-testid="item-1"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).not.toBeVisible() - - // Check count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (1)") - }) - - test("clears entire stream", async ({ page }) => { - // Clear all items - await page.click('[data-testid="clear-button"]') - await syncLV(page) - - // Check that all items are gone - await expect(page.locator('[data-testid="item-1"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).not.toBeVisible() - - // Check empty state - await expect(page.locator('[data-testid="empty-message"]')).toBeVisible() - await expect(page.locator('[data-testid="empty-message"]')).toHaveText("No items in the stream") - - // Check count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (0)") - }) - - test("resets stream to default state", async ({ page }) => { - // First clear the stream - await page.click('[data-testid="clear-button"]') - await syncLV(page) - await expect(page.locator('[data-testid="empty-message"]')).toBeVisible() - - // Then reset it - await page.click('[data-testid="reset-button"]') - await syncLV(page) - - // Check that original items are back - await expect(page.locator('[data-testid="item-1"]')).toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).toBeVisible() - await expect(page.locator('[data-testid="empty-message"]')).not.toBeVisible() - - // Check count - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (3)") - }) - - test("handles complex workflow: add, remove, clear, reset", async ({ page }) => { - // Add a new item - await page.fill('[data-testid="name-input"]', "Workflow Item") - await page.fill('[data-testid="description-input"]', "Testing workflow") - await page.click('[data-testid="add-button"]') - await syncLV(page) - - // Verify we have 4 items - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (4)") - - // Remove one original item - await page.click('[data-testid="remove-2"]') - await syncLV(page) - await expect(itemsHeading).toHaveText("Items (3)") - - // Clear all - await page.click('[data-testid="clear-button"]') - await syncLV(page) - await expect(itemsHeading).toHaveText("Items (0)") - await expect(page.locator('[data-testid="empty-message"]')).toBeVisible() - - // Reset to defaults - await page.click('[data-testid="reset-button"]') - await syncLV(page) - await expect(itemsHeading).toHaveText("Items (3)") - await expect(page.locator('[data-testid="empty-message"]')).not.toBeVisible() - - // Verify the original 3 items are back (not the added one) - await expect(page.locator('[data-testid="item-1"]')).toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).toBeVisible() - await expect(page.locator('[data-testid="item-4"]')).not.toBeVisible() - }) - - test("validates form input for adding items", async ({ page }) => { - // Try to add item with empty name - await page.fill('[data-testid="name-input"]', "") - await page.fill('[data-testid="description-input"]', "Description only") - - // This should trigger an alert (form validation) - page.on("dialog", async dialog => { - expect(dialog.message()).toBe("Please enter a name for the item") - await dialog.accept() - }) - - await page.click('[data-testid="add-button"]') - - // Item should not be added - await syncLV(page) - const itemsHeading = page.locator('h3:has-text("Items")') - await expect(itemsHeading).toHaveText("Items (3)") // Still 3 items - }) - - test("displays debug information correctly", async ({ page }) => { - // Check debug info shows correct type and length - await expect(page.locator('.debug-info p:has-text("Items type:")')).toBeVisible() - await expect(page.locator('.debug-info p:has-text("Items length:")')).toBeVisible() - - // Check raw items data is displayed - await expect(page.locator('[data-testid="raw-items"]')).toBeVisible() - - const rawItemsText = await page.locator('[data-testid="raw-items"]').textContent() - expect(rawItemsText).toContain('"id"') - expect(rawItemsText).toContain('"name"') - expect(rawItemsText).toContain('"description"') - }) - - test("maintains item order during operations", async ({ page }) => { - // Get initial order - const item1Name = await page.locator('[data-testid="item-1"] [data-testid="item-name"]').textContent() - const item2Name = await page.locator('[data-testid="item-2"] [data-testid="item-name"]').textContent() - const item3Name = await page.locator('[data-testid="item-3"] [data-testid="item-name"]').textContent() - - expect(item1Name).toBe("Item 1") - expect(item2Name).toBe("Item 2") - expect(item3Name).toBe("Item 3") - - // Add new item (should appear after existing ones) - await page.fill('[data-testid="name-input"]', "Item 4") - await page.fill('[data-testid="description-input"]', "Fourth item") - await page.click('[data-testid="add-button"]') - await syncLV(page) - - // Check that new item appears at the end - const item4Name = await page.locator('[data-testid="item-4"] [data-testid="item-name"]').textContent() - expect(item4Name).toBe("Item 4") - - // Remove middle item and check order is maintained - await page.click('[data-testid="remove-2"]') - await syncLV(page) - - // Items 1, 3, 4 should still be in correct order - await expect(page.locator('[data-testid="item-1"] [data-testid="item-name"]')).toHaveText("Item 1") - await expect(page.locator('[data-testid="item-3"] [data-testid="item-name"]')).toHaveText("Item 3") - await expect(page.locator('[data-testid="item-4"] [data-testid="item-name"]')).toHaveText("Item 4") - }) - - test("maintains correct item order after stream reset", async ({ page }) => { - // Add some items and clear to modify the stream - await page.fill('[data-testid="name-input"]', "Extra Item") - await page.fill('[data-testid="description-input"]', "Extra description") - await page.click('[data-testid="add-button"]') - await syncLV(page) - - // Reset the stream - await page.click('[data-testid="reset-button"]') - await syncLV(page) - - // Verify items appear in correct order: Item 1, Item 2, Item 3 - const allItems = await page.locator('[data-testid="item-name"]').allTextContents() - expect(allItems).toEqual(["Item 1", "Item 2", "Item 3"]) - - // Reset the stream - await page.click('[data-testid="reset-button-at-0"]') - await syncLV(page) - - // Verify items appear in correct order: Item 1, Item 2, Item 3 - const allReversedItems = await page.locator('[data-testid="item-name"]').allTextContents() - expect(allReversedItems).toEqual(["Item 3", "Item 2", "Item 1"]) - }) - - // Limit operation tests - test.describe("Limit Operations", () => { - test.beforeEach(async ({ page }) => { - await page.goto("/streams") - await syncLV(page) - }) - - test("adds multiple items at start with positive limit", async ({ page }) => { - // Verify initial state: 3 items - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (3)") - - // Add 3 items at start with limit 5 (should keep first 5 items) - await page.click('[data-testid="add-multiple-start-button"]') - await syncLV(page) - - // Should have 5 items total (3 new + 3 original, but limited to 5) - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (5)") - - // Check that new items are at the start and in correct order - // Expected order: Start Item C, Start Item B, Start Item A, Item 1, Item 2 - // (Note: items are added at position 0 in reverse order) - await expect(page.locator('[data-testid="item-6"] [data-testid="item-name"]')).toHaveText("Start Item C") - await expect(page.locator('[data-testid="item-5"] [data-testid="item-name"]')).toHaveText("Start Item B") - await expect(page.locator('[data-testid="item-4"] [data-testid="item-name"]')).toHaveText("Start Item A") - await expect(page.locator('[data-testid="item-1"] [data-testid="item-name"]')).toHaveText("Item 1") - await expect(page.locator('[data-testid="item-2"] [data-testid="item-name"]')).toHaveText("Item 2") - - // Item 3 should be removed due to limit 5 - await expect(page.locator('[data-testid="item-3"]')).not.toBeVisible() - }) - - test("adds multiple items at end with negative limit", async ({ page }) => { - // Verify initial state: 3 items - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (3)") - - // Add 3 items at end with negative limit -5 (should keep last 5 items) - await page.click('[data-testid="add-multiple-end-button"]') - await syncLV(page) - - // Should have 5 items total (3 original + 3 new, but limited to last 5) - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (5)") - - // Check that new items are at the end and original items remain - // Expected order: Item 2, Item 3, End Item X, End Item Y, End Item Z - // (Item 1 should be removed due to negative limit -5) - await expect(page.locator('[data-testid="item-1"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-2"] [data-testid="item-name"]')).toHaveText("Item 2") - await expect(page.locator('[data-testid="item-3"] [data-testid="item-name"]')).toHaveText("Item 3") - await expect(page.locator('[data-testid="item-4"] [data-testid="item-name"]')).toHaveText("End Item X") - await expect(page.locator('[data-testid="item-5"] [data-testid="item-name"]')).toHaveText("End Item Y") - await expect(page.locator('[data-testid="item-6"] [data-testid="item-name"]')).toHaveText("End Item Z") - }) - - test("adds single item with custom positive limit", async ({ page }) => { - // Set positive limit to 2 - await page.fill('[data-testid="positive-limit-input"]', "2") - - // Add item with positive limit 2 - await page.click('[data-testid="add-positive-limit-button"]') - await syncLV(page) - - // Should have only 2 items (limited to first 2) - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (2)") - - // Check which items remain (should be original Item 1 and new limited item) - await expect(page.locator('[data-testid="item-1"] [data-testid="item-name"]')).toHaveText("Item 1") - await expect(page.locator('[data-testid="item-4"] [data-testid="item-name"]')).toHaveText("Limited Item +2") - - // Items 2 and 3 should be removed - await expect(page.locator('[data-testid="item-2"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-3"]')).not.toBeVisible() - }) - - test("adds single item with custom negative limit", async ({ page }) => { - // Set negative limit to 2 - await page.fill('[data-testid="negative-limit-input"]', "2") - - // Add item with negative limit -2 - await page.click('[data-testid="add-negative-limit-button"]') - await syncLV(page) - - // Should have only 2 items (limited to last 2) - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (2)") - - // Check which items remain (should be Item 3 and new limited item) - await expect(page.locator('[data-testid="item-3"] [data-testid="item-name"]')).toHaveText("Item 3") - await expect(page.locator('[data-testid="item-4"] [data-testid="item-name"]')).toHaveText("Limited Item -2") - - // Items 1 and 2 should be removed - await expect(page.locator('[data-testid="item-1"]')).not.toBeVisible() - await expect(page.locator('[data-testid="item-2"]')).not.toBeVisible() - }) - - test("handles limit operations with existing items", async ({ page }) => { - // First add a regular item to have 4 items total - await page.fill('[data-testid="name-input"]', "Regular Item") - await page.fill('[data-testid="description-input"]', "Regular description") - await page.click('[data-testid="add-button"]') - await syncLV(page) - - // Should have 4 items - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (4)") - - // Now prepend with positive limit 3 - await page.fill('[data-testid="positive-limit-input"]', "3") - await page.click('[data-testid="add-positive-limit-button"]') - await syncLV(page) - - // Should have 3 items (first 3 kept) - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (3)") - - // Check that we have the first item, new regular item, and new limited item - await expect(page.locator('[data-testid="item-5"] [data-testid="item-name"]')).toHaveText("Limited Item +3") - await expect(page.locator('[data-testid="item-1"] [data-testid="item-name"]')).toHaveText("Item 1") - await expect(page.locator('[data-testid="item-2"] [data-testid="item-name"]')).toHaveText("Item 2") - }) - - test("validates limit input constraints", async ({ page }) => { - // Test that buttons are disabled for invalid inputs - await expect(page.locator('[data-testid="add-positive-limit-button"]')).not.toBeDisabled() - await expect(page.locator('[data-testid="add-negative-limit-button"]')).not.toBeDisabled() - - // Clear inputs should disable buttons - await page.fill('[data-testid="positive-limit-input"]', "") - await page.fill('[data-testid="negative-limit-input"]', "") - - await expect(page.locator('[data-testid="add-positive-limit-button"]')).toBeDisabled() - await expect(page.locator('[data-testid="add-negative-limit-button"]')).toBeDisabled() - - // Zero should disable buttons - await page.fill('[data-testid="positive-limit-input"]', "0") - await page.fill('[data-testid="negative-limit-input"]', "0") - - await expect(page.locator('[data-testid="add-positive-limit-button"]')).toBeDisabled() - await expect(page.locator('[data-testid="add-negative-limit-button"]')).toBeDisabled() - - // Valid values should enable buttons - await page.fill('[data-testid="positive-limit-input"]', "3") - await page.fill('[data-testid="negative-limit-input"]', "3") - - await expect(page.locator('[data-testid="add-positive-limit-button"]')).not.toBeDisabled() - await expect(page.locator('[data-testid="add-negative-limit-button"]')).not.toBeDisabled() - }) - - test("handles limit operations in sequence", async ({ page }) => { - // Start with positive limit - await page.fill('[data-testid="positive-limit-input"]', "4") - await page.click('[data-testid="add-positive-limit-button"]') - await syncLV(page) - - // Should have 4 items - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (4)") - - // Then apply negative limit - await page.fill('[data-testid="negative-limit-input"]', "2") - await page.click('[data-testid="add-negative-limit-button"]') - await syncLV(page) - - // Should have 2 items (last 2) - await expect(page.locator('h3:has-text("Items")')).toHaveText("Items (2)") - - // Verify it's the limited item and one original item - await expect(page.locator('[data-testid="item-3"] [data-testid="item-name"]')).toHaveText("Item 3") - await expect(page.locator('[data-testid="item-5"] [data-testid="item-name"]')).toHaveText("Limited Item -2") - }) - }) -}) diff --git a/test/e2e/features/upload/upload.spec.js b/test/e2e/features/upload/upload.spec.js deleted file mode 100644 index 59402575..00000000 --- a/test/e2e/features/upload/upload.spec.js +++ /dev/null @@ -1,394 +0,0 @@ -import { test, expect } from "@playwright/test" -import { evalLV, syncLV } from "../../utils.js" -import { readFileSync } from "fs" -import { join } from "path" - -test.describe("useLiveUpload", () => { - // Helper function to create test files - const createTestFile = (name, content = "test content") => { - return new File([content], name, { type: "text/plain" }) - } - - test("should handle manual upload (auto_upload: false)", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Verify initial state - await expect(page.locator("#upload-mode")).toContainText("manual") - await expect(page.locator("#auto-upload")).toContainText("false") - await expect(page.locator("#selected-count")).toContainText("0") - await expect(page.locator("#uploaded-count")).toContainText("0") - - // Upload button should not be visible initially - await expect(page.locator("#upload-btn")).not.toBeVisible() - - // Create a test file and simulate file selection - const testContent = "This is test file content for manual upload" - await page.setInputFiles('input[type="file"]', { - name: "test-manual.txt", - mimeType: "text/plain", - buffer: Buffer.from(testContent), - }) - - await syncLV(page) - - // Verify file is selected but not uploaded yet - await expect(page.locator("#selected-count")).toContainText("1") - await expect(page.locator("#uploaded-count")).toContainText("0") - - // Upload button should now be visible - await expect(page.locator("#upload-btn")).toBeVisible() - - // Verify file appears in file list - await expect(page.locator(".file-entry")).toHaveCount(1) - await expect(page.locator(".file-name")).toContainText("test-manual.txt") - await expect(page.locator(".file-done")).toContainText("pending") - - // Click upload button to manually trigger upload - await page.click("#upload-btn") - await syncLV(page) - - // Wait for upload to complete and verify - await expect(page.locator("#uploaded-count")).toContainText("1") - await expect(page.locator(".uploaded-file")).toHaveCount(1) - await expect(page.locator(".uploaded-name")).toContainText("test-manual.txt") - }) - - test("should handle automatic upload (auto_upload: true)", async ({ page }) => { - await page.goto("/upload/auto") - await syncLV(page) - - // Verify initial state - await expect(page.locator("#upload-mode")).toContainText("auto") - await expect(page.locator("#auto-upload")).toContainText("true") - await expect(page.locator("#selected-count")).toContainText("0") - await expect(page.locator("#uploaded-count")).toContainText("0") - - // Upload button should not be visible for auto upload - await expect(page.locator("#upload-btn")).not.toBeVisible() - - // Create a test file and simulate file selection - const testContent = "This is test file content for auto upload" - await page.setInputFiles('input[type="file"]', { - name: "test-auto.txt", - mimeType: "text/plain", - buffer: Buffer.from(testContent), - }) - - await syncLV(page) - - // For auto upload, file should be uploaded automatically - // Wait a bit longer for the auto upload to process - await page.waitForTimeout(2000) - await syncLV(page) - - // Verify file was selected and processed - await expect(page.locator("#selected-count")).toContainText("1") - await expect(page.locator(".file-entry")).toHaveCount(1) - - // Check if the file was processed (either uploaded or marked as done) - const fileStatus = await page.locator(".file-done").textContent() - const uploadedCount = await page.locator("#uploaded-count").textContent() - - // For auto upload, the file should either be uploaded or marked as done - expect(fileStatus?.includes("done") || uploadedCount?.includes("1")).toBeTruthy() - }) - - test("should handle multiple file selection and upload", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Select multiple files - await page.setInputFiles('input[type="file"]', [ - { - name: "file1.txt", - mimeType: "text/plain", - buffer: Buffer.from("Content of file 1"), - }, - { - name: "file2.txt", - mimeType: "text/plain", - buffer: Buffer.from("Content of file 2"), - }, - ]) - - await syncLV(page) - - // Verify multiple files are selected - await expect(page.locator("#selected-count")).toContainText("2") - await expect(page.locator(".file-entry")).toHaveCount(2) - - // Upload all files - await page.click("#upload-btn") - await syncLV(page) - - // Verify all files were uploaded - await expect(page.locator("#uploaded-count")).toContainText("2") - await expect(page.locator(".uploaded-file")).toHaveCount(2) - }) - - test("should handle file cancellation", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Select a file - await page.setInputFiles('input[type="file"]', { - name: "cancel-test.txt", - mimeType: "text/plain", - buffer: Buffer.from("This file will be cancelled"), - }) - - await syncLV(page) - - // Verify file is selected - await expect(page.locator("#selected-count")).toContainText("1") - await expect(page.locator(".file-entry")).toHaveCount(1) - - // Cancel the file - await page.click("#cancel-all-btn") - await syncLV(page) - - // Verify file was cancelled - await expect(page.locator("#selected-count")).toContainText("0") - await expect(page.locator(".file-entry")).toHaveCount(0) - await expect(page.locator("#uploaded-count")).toContainText("0") - }) - - test("should respect max_entries limit", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Verify max entries is displayed - await expect(page.locator("#max-entries")).toContainText("3") - - // Select exactly max_entries files (3) - await page.setInputFiles('input[type="file"]', [ - { name: "file1.txt", mimeType: "text/plain", buffer: Buffer.from("1") }, - { name: "file2.txt", mimeType: "text/plain", buffer: Buffer.from("2") }, - { name: "file3.txt", mimeType: "text/plain", buffer: Buffer.from("3") }, - ]) - - await syncLV(page) - - // Should accept exactly max_entries (3 files) - await expect(page.locator("#selected-count")).toContainText("3") - await expect(page.locator(".file-entry")).toHaveCount(3) - }) - - test("should handle file size errors", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Try to upload a file larger than max_file_size (1MB) - const largeContent = "x".repeat(2000000) // 2MB file - await page.setInputFiles('input[type="file"]', { - name: "large-file.txt", - mimeType: "text/plain", - buffer: Buffer.from(largeContent), - }) - - await syncLV(page) - - // File should be selected but may have errors - await expect(page.locator("#selected-count")).toContainText("1") - await expect(page.locator(".file-entry")).toHaveCount(1) - - // Check if error handling is working (specific error messages may vary) - // The file might be rejected or show error state - const hasErrors = await page - .locator("#global-errors") - .isVisible() - .catch(() => false) - const hasEntryErrors = await page - .locator(".entry-errors") - .isVisible() - .catch(() => false) - - // At least one error display should be present for oversized files - expect(hasErrors || hasEntryErrors).toBeTruthy() - }) - - test("should handle unsupported file type errors", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Try to upload a file type not in accept list (.exe not in .txt .pdf .jpg .png) - await page.setInputFiles('input[type="file"]', { - name: "program.exe", - mimeType: "application/octet-stream", - buffer: Buffer.from("fake exe content"), - }) - - await syncLV(page) - - // File should be selected but may have errors - await expect(page.locator("#selected-count")).toContainText("1") - - // Check if error handling is working for unsupported file types - const hasErrors = await page - .locator("#global-errors") - .isVisible() - .catch(() => false) - const hasEntryErrors = await page - .locator(".entry-errors") - .isVisible() - .catch(() => false) - - // At least one error display should be present for unsupported file types - expect(hasErrors || hasEntryErrors).toBeTruthy() - }) - - test("should handle too many files error", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Try to select more files than max_entries allows (4 files when max is 3) - await page.setInputFiles('input[type="file"]', [ - { name: "file1.txt", mimeType: "text/plain", buffer: Buffer.from("1") }, - { name: "file2.txt", mimeType: "text/plain", buffer: Buffer.from("2") }, - { name: "file3.txt", mimeType: "text/plain", buffer: Buffer.from("3") }, - { name: "file4.txt", mimeType: "text/plain", buffer: Buffer.from("4") }, - ]) - - await syncLV(page) - - // Either only 3 files are accepted, or there's an error about too many files - const selectedCount = await page.locator("#selected-count").textContent() - expect(await page.locator(".file-entry").count()).toEqual(4) - - // Should either limit to max_entries or show error - // If more than 3 files are shown, there should be an error - const hasErrors = await page - .locator("#global-errors") - .isVisible() - .catch(() => false) - expect(hasErrors).toBeTruthy() - }) - - test("should handle drag and drop file upload", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - // Verify initial state - await expect(page.locator("#selected-count")).toContainText("0") - - // Create a DataTransfer object with files for drag and drop simulation - const testContent = "This is test file content for drag and drop" - - // Simulate drag and drop by dispatching a drop event with files - await page.evaluate(async content => { - const dropArea = document.querySelector("#drop-zone") - if (!dropArea) throw new Error("Drop area not found") - - // Create a File object - const file = new File([content], "drag-drop-test.txt", { type: "text/plain" }) - - // Create DataTransfer object and add the file - const dataTransfer = new DataTransfer() - dataTransfer.items.add(file) - - // Create and dispatch drop event - const dropEvent = new DragEvent("drop", { - bubbles: true, - cancelable: true, - dataTransfer: dataTransfer, - }) - - dropArea.dispatchEvent(dropEvent) - }, testContent) - - await syncLV(page) - - // Verify file was added via drag and drop - await expect(page.locator("#selected-count")).toContainText("1") - await expect(page.locator(".file-entry")).toHaveCount(1) - await expect(page.locator(".file-name")).toContainText("drag-drop-test.txt") - await expect(page.locator(".file-done")).toContainText("pending") - - // Upload button should now be visible for manual upload - await expect(page.locator("#upload-btn")).toBeVisible() - - // Test that the upload works after drag and drop - await page.click("#upload-btn") - await syncLV(page) - - // Verify upload completed - await expect(page.locator("#uploaded-count")).toContainText("1") - await expect(page.locator(".uploaded-file")).toHaveCount(1) - await expect(page.locator(".uploaded-name")).toContainText("drag-drop-test.txt") - }) - - test("should keep the original upload input usable across a simulated reconnect ref rotation", async ({ page }) => { - await page.goto("/upload/manual") - await syncLV(page) - - const originalRef = await page.evaluate(() => { - const input = document.querySelector('input[type="file"]') - if (!input) throw new Error("Upload input not found") - window.__originalUploadInput = input - return input.getAttribute("data-phx-upload-ref") - }) - - await evalLV( - page, - ` - socket - |> Phoenix.LiveView.disallow_upload(:test_files) - |> Phoenix.LiveView.allow_upload(:test_files, - accept: ~w(.txt .pdf .jpg .png), - max_entries: 3, - max_file_size: 1_000_000, - auto_upload: false - ) - ` - ) - - await page.waitForFunction(previousRef => { - const input = document.querySelector('input[type="file"]') - return !!input && input.getAttribute("data-phx-upload-ref") !== previousRef - }, originalRef) - - await syncLV(page) - - const reconnectState = await page.evaluate(() => { - const currentInput = document.querySelector('input[type="file"]') - const originalInput = window.__originalUploadInput - - return { - originalStillAttached: !!originalInput?.isConnected, - sameNode: originalInput === currentInput, - currentRef: currentInput?.getAttribute("data-phx-upload-ref"), - } - }) - - expect(reconnectState.originalStillAttached).toBe(true) - expect(reconnectState.sameNode).toBe(true) - expect(reconnectState.currentRef).not.toBe(originalRef) - - const testContent = "Upload after reconnect through original input handle" - - await page.evaluate(content => { - const input = window.__originalUploadInput - if (!input) throw new Error("Saved upload input not found") - - const file = new File([content], "reconnect-race.txt", { type: "text/plain" }) - const dataTransfer = new DataTransfer() - dataTransfer.items.add(file) - input.files = dataTransfer.files - input.dispatchEvent(new Event("change", { bubbles: true, cancelable: true })) - }, testContent) - - await syncLV(page) - - await expect(page.locator("#selected-count")).toContainText("1") - await expect(page.locator(".file-entry")).toHaveCount(1) - await expect(page.locator(".file-name")).toContainText("reconnect-race.txt") - - await page.click("#upload-btn") - await syncLV(page) - - await expect(page.locator("#uploaded-count")).toContainText("1") - await expect(page.locator(".uploaded-file")).toHaveCount(1) - await expect(page.locator(".uploaded-name")).toContainText("reconnect-race.txt") - }) -}) diff --git a/test/e2e/playwright.config.js b/test/e2e/playwright.config.js deleted file mode 100644 index 9c3c5856..00000000 --- a/test/e2e/playwright.config.js +++ /dev/null @@ -1,26 +0,0 @@ -import { defineConfig, devices } from "@playwright/test" - -export default defineConfig({ - testDir: "./features", - forbidOnly: !!process.env.CI, - retries: process.env.CI ? 2 : 0, - expect: { - timeout: 1000, - }, - use: { - trace: "retain-on-failure", - screenshot: "only-on-failure", - baseURL: "http://localhost:4004/", - }, - webServer: { - command: "cd ../.. && MIX_ENV=e2e mix run test/e2e/test_helper.exs", - url: "http://127.0.0.1:4004/health", - reuseExistingServer: !process.env.CI, - timeout: 60_000, - }, - projects: [ - { name: "chromium", use: { ...devices["Desktop Chrome"] } }, - // { name: "firefox", use: { ...devices["Desktop Firefox"] } }, - // { name: "webkit", use: { ...devices["Desktop Safari"] } }, - ], -}) diff --git a/test/e2e/utils.js b/test/e2e/utils.js deleted file mode 100644 index bffe55b6..00000000 --- a/test/e2e/utils.js +++ /dev/null @@ -1,51 +0,0 @@ -import { expect } from "@playwright/test" - -// Wait for LiveView to be ready and Vue components to be mounted -export const syncLV = async page => { - // Use longer timeout for connection - websocket setup can take time under load - const connectionTimeout = { timeout: 5000 } - const promises = [ - expect(page.locator(".phx-connected").first()).toBeVisible(connectionTimeout), - expect(page.locator(".phx-change-loading")).toHaveCount(0), - expect(page.locator(".phx-click-loading")).toHaveCount(0), - expect(page.locator(".phx-submit-loading")).toHaveCount(0), - new Promise(resolve => setTimeout(resolve, 50)), - ] - return Promise.all(promises) -} - -// Execute code inside LiveView process -export const evalLV = async (page, code, selector = "[data-phx-main]") => - await page.evaluate( - ([code, selector]) => { - return new Promise(resolve => { - window.liveSocket.main.withinTargets(selector, (targetView, targetCtx) => { - targetView.pushEvent( - "event", - document.body, - targetCtx, - "sandbox:eval", - { value: code }, - {}, - ({ result, error }) => { - if (error) { - throw new Error(error) - } - resolve(result) - } - ) - }) - }) - }, - [code, selector] - ) - -// Generate random string for test isolation -export const randomString = length => { - const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" - let result = "" - for (let i = 0; i < length; i++) { - result += chars.charAt(Math.floor(Math.random() * chars.length)) - } - return result -} From e52033add1f57462da5b87d735ca2f32f44c8a25 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 08:31:29 +0100 Subject: [PATCH 3/8] Run e2e.test through env, as mix cmd has no shell --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index c3884d0c..5d0293c0 100644 --- a/mix.exs +++ b/mix.exs @@ -184,7 +184,7 @@ defmodule LiveVue.MixProject do setup: ["deps.get", "cmd npm install"], precommit: ["test", "format", "e2e.test", "assets.test"], "assets.test": ["cmd npm test"], - "e2e.test": ["cmd npm run e2e:build", "cmd MIX_ENV=e2e mix test"], + "e2e.test": ["cmd npm run e2e:build", "cmd env MIX_ENV=e2e mix test"], "release.patch": ["easy_publish.release patch --branch=main"], "release.minor": ["easy_publish.release minor --branch=main"], "release.major": ["easy_publish.release major --branch=main"] From 066fad0b31a7fcb3630b2c147f9ca8ccd2b74a9f Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 08:59:34 +0100 Subject: [PATCH 4/8] Fail the CI retry when it runs no tests --- .github/workflows/e2e.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 89dce277..2bd21c88 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -57,11 +57,13 @@ jobs: - name: Install E2E dependencies and browsers run: mix playwright.install chromium --with-deps - # Up to two retries of the failed tests, as the `retries: 2` of Playwright Test + # Up to two retries of the failed tests, as the `retries: 2` of Playwright Test. An empty + # rerun (nothing failed but a module) must not pass. - name: Run E2E tests run: | npm run e2e:build - mix test || { [ $? -eq 2 ] && mix test --failed; } || { [ $? -eq 2 ] && mix test --failed; } + set -o pipefail + mix test || { [ $? -eq 2 ] && mix test --failed | tee "$RUNNER_TEMP/retry.log" && ! grep -q "There are no tests to run" "$RUNNER_TEMP/retry.log"; } || { [ $? -eq 2 ] && mix test --failed | tee "$RUNNER_TEMP/retry.log" && ! grep -q "There are no tests to run" "$RUNNER_TEMP/retry.log"; } - uses: actions/upload-artifact@v7 if: failure() From 41ef5299ddd99b496509c5df21029bb026f3264d Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 10:04:48 +0100 Subject: [PATCH 5/8] Retry failed e2e tests plainly, with mix test --failed --- .github/workflows/e2e.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 2bd21c88..89dce277 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -57,13 +57,11 @@ jobs: - name: Install E2E dependencies and browsers run: mix playwright.install chromium --with-deps - # Up to two retries of the failed tests, as the `retries: 2` of Playwright Test. An empty - # rerun (nothing failed but a module) must not pass. + # Up to two retries of the failed tests, as the `retries: 2` of Playwright Test - name: Run E2E tests run: | npm run e2e:build - set -o pipefail - mix test || { [ $? -eq 2 ] && mix test --failed | tee "$RUNNER_TEMP/retry.log" && ! grep -q "There are no tests to run" "$RUNNER_TEMP/retry.log"; } || { [ $? -eq 2 ] && mix test --failed | tee "$RUNNER_TEMP/retry.log" && ! grep -q "There are no tests to run" "$RUNNER_TEMP/retry.log"; } + mix test || { [ $? -eq 2 ] && mix test --failed; } || { [ $? -eq 2 ] && mix test --failed; } - uses: actions/upload-artifact@v7 if: failure() From 8090c3b87706cbcd80c28eaf49810a7ecfa0ac65 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 10:18:47 +0100 Subject: [PATCH 6/8] Fix stale comments in the e2e server files --- test/e2e/server.exs | 4 ++-- test/e2e/test_helper.exs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/server.exs b/test/e2e/server.exs index 1dcd29d1..fa4d81ac 100644 --- a/test/e2e/server.exs +++ b/test/e2e/server.exs @@ -1,5 +1,5 @@ -# The e2e app: endpoint, router, layout. Started by test/e2e/test_helper.exs (Playwright JS) -# and test/e2e_pw/test_helper.exs (ExUnit). +# The e2e app: endpoint, router, layout. Started by e2e_pw/test_helper.exs (`mix e2e.test`) +# and test/e2e/test_helper.exs (`npm run e2e:server`). # Configure Phoenix JSON encoder Application.put_env(:phoenix, :json_library, Jason) diff --git a/test/e2e/test_helper.exs b/test/e2e/test_helper.exs index 14cbc29b..c0cf8def 100644 --- a/test/e2e/test_helper.exs +++ b/test/e2e/test_helper.exs @@ -1,4 +1,4 @@ -# The server is shared with the ExUnit port in test/e2e_pw. +# Runs the server standalone (npm run e2e:server). The tests in e2e_pw/ start it themselves. Code.require_file("server.exs", __DIR__) Process.register(self(), :e2e_helper) From 6d447fe4be43f663f373c415b422064d45dd0fa0 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 19 Nov 2026 11:26:16 +0100 Subject: [PATCH 7/8] Install the e2e browsers with mix in conductor-setup.sh --- conductor-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conductor-setup.sh b/conductor-setup.sh index c7734b24..7902ecac 100755 --- a/conductor-setup.sh +++ b/conductor-setup.sh @@ -28,6 +28,6 @@ npm ci # Install Playwright browsers for E2E tests echo "🎭 Installing Playwright browsers..." -npm run e2e:install +MIX_ENV=e2e mix deps.get && MIX_ENV=e2e mix playwright.install chromium echo "✅ Setup complete! Run 'cd example_project && mix phx.server' to start development." From b4a6957d1f2a854f3a6df83d5228dc0c74857fdb Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Sat, 21 Nov 2026 12:57:48 +0100 Subject: [PATCH 8/8] Use playwright_ex 1.65.0-rc.3 --- .github/workflows/e2e.yml | 2 +- mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 89dce277..d1ed69fa 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -64,7 +64,7 @@ jobs: mix test || { [ $? -eq 2 ] && mix test --failed; } || { [ $? -eq 2 ] && mix test --failed; } - uses: actions/upload-artifact@v7 - if: failure() + if: ${{ !cancelled() }} with: name: test-results path: test-results diff --git a/mix.exs b/mix.exs index 5d0293c0..1e0cdc3c 100644 --- a/mix.exs +++ b/mix.exs @@ -174,7 +174,7 @@ defmodule LiveVue.MixProject do # e2e dependencies {:bandit, "~> 1.5", only: :e2e}, {:phoenix_live_reload, "~> 1.2", only: :e2e}, - {:playwright, "~> 1.65.0-rc.2", hex: :playwright_ex, only: :e2e} + {:playwright, "~> 1.65.0-rc.3", hex: :playwright_ex, only: :e2e} ] end diff --git a/mix.lock b/mix.lock index b50dfab5..f59ccd37 100644 --- a/mix.lock +++ b/mix.lock @@ -47,7 +47,7 @@ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "phoenix_vite": {:hex, :phoenix_vite, "0.5.1", "f79b71dace8c94c434fef7e21db617a2e25e1e4e03be62f2cf4eeb79c739368d", [:mix], [{:bun, "~> 1.5 or ~> 2.0", [hex: :bun, repo: "hexpm", optional: true]}, {:igniter, "~> 0.6", [hex: :igniter, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "8f7c47f95f6a3384b4e10c9b1690b2a4e51aca938cf88f885a9514bce4339d4d"}, - "playwright": {:hex, :playwright_ex, "1.65.0-rc.2", "bdc53b1858b122d23e736f28b6ce4aa9d1fd2913abfad629de954f46abaee35b", [:mix], [], "hexpm", "916c76ab916de05ce06a2a2eb072ce80581e3685597d8dd8377200be860f6000"}, + "playwright": {:hex, :playwright_ex, "1.65.0-rc.3", "5000b41737562681abe1f1120dacae10a3e5cfef6554c61779b6411e391c2901", [:mix], [], "hexpm", "2871c0a65d1de19e2ebbe47fe3ee4309aa45a9d3d3a113eb10d9d09bdd291ece"}, "plug": {:hex, :plug, "1.20.3", "56c480c633ec2ce10140e236e15233bf576e1d323887d7c96711bd02ab5160db", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "be266aee1b8536ef6409d58cf39a3121319f0ec47cfa1b24024485aa0e76ad76"}, "plug_crypto": {:hex, :plug_crypto, "2.2.0", "144014737daaf485407f5ed77daeaad74d651b216a28c87543f8cc7043f8efc8", [:mix], [], "hexpm", "83a95744ab1c75876542b6fab135fcc176280e0f301a111c1f757fddcec95d2c"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"},