From 85b556346c4f334af56269abe8fdb2c61aacd419 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Mon, 23 Nov 2026 20:02:26 +0100 Subject: [PATCH 01/14] test(browser): move browser scenarios to Fluffy --- .github/workflows/elixir.yml | 10 +- assets/package-lock.json | 41 ------- assets/package.json | 3 - config/test.exs | 11 ++ mix.exs | 2 +- mix.lock | 4 +- test/browser/README.md | 11 +- test/browser/steps/appearance_menu_steps.exs | 22 ++-- .../steps/calendar_day_sheet_steps.exs | 2 +- .../browser/steps/calendar_timezone_steps.exs | 2 +- test/browser/steps/copy_huddl_steps.exs | 10 +- test/browser/steps/cover_crop_steps.exs | 55 +++++----- .../steps/cover_upload_progress_steps.exs | 15 ++- .../steps/discover_navigation_steps.exs | 5 +- .../steps/email_confirmation_steps.exs | 2 +- test/browser/steps/group_cover_steps.exs | 34 +++--- test/browser/steps/huddl_photos_steps.exs | 100 ++++++++++-------- test/browser/steps/keyboard_focus_steps.exs | 25 +++-- .../browser/steps/location_keyboard_steps.exs | 45 +++++--- test/browser/steps/member_menu_steps.exs | 17 ++- .../browser/steps/mobile_navigation_steps.exs | 19 ++-- test/browser/steps/mobile_rsvp_steps.exs | 2 +- .../steps/notification_preferences_steps.exs | 13 ++- .../steps/organizer_keyboard_steps.exs | 15 ++- test/browser/steps/overview_cards_steps.exs | 2 +- test/browser/steps/profile_picture_steps.exs | 32 +++--- test/browser/steps/report_review_steps.exs | 14 ++- test/browser/steps/share_links_steps.exs | 40 +++---- test/browser/steps/sidebar_scroll_steps.exs | 45 ++++---- test/browser/steps/sign_in_return_steps.exs | 2 +- test/browser/steps/social_schedule_steps.exs | 21 ++-- test/browser/support/hooks.exs | 45 ++++---- test/browser/test_helper.exs | 13 --- test/support/browser_helpers.ex | 31 +++--- 34 files changed, 338 insertions(+), 372 deletions(-) delete mode 100644 assets/package-lock.json diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 97a2f262d..e323ba95b 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -213,11 +213,6 @@ jobs: with: otp-version: '29.1.2' elixir-version: '1.20.5' - - uses: actions/setup-node@v7.1.0 - with: - node-version: '26' - cache: npm - cache-dependency-path: assets/package-lock.json # The compiled build restores only on an exact mix.lock match; see the # test job's build cache. - name: Cache browser job dependencies @@ -238,7 +233,6 @@ jobs: run: | mix deps.get mix assets.setup - npm ci --prefix assets - name: Install Chromium and system dependencies env: PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/_build/browser/browsers @@ -247,7 +241,7 @@ jobs: # wanted; when that mirror's index is inconsistent the whole step fails. run: | sudo grep -rl "dl.google.com" /etc/apt/sources.list.d | xargs -r sudo rm -f - assets/node_modules/.bin/playwright install --with-deps chromium --only-shell + mix playwright.install --with-deps chromium --only-shell - name: Run browser scenarios timeout-minutes: 2 run: mix test.browser @@ -258,7 +252,7 @@ jobs: name: browser-failure-diagnostics path: | _build/browser/screenshots - _build/browser/traces + _build/browser/test-results if-no-files-found: ignore retention-days: 7 diff --git a/assets/package-lock.json b/assets/package-lock.json deleted file mode 100644 index d7dd44530..000000000 --- a/assets/package-lock.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "assets", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "devDependencies": { - "playwright": "1.65.1" - } - }, - "node_modules/playwright": { - "version": "1.65.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.65.1.tgz", - "integrity": "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "playwright-core": "1.65.1" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=20" - } - }, - "node_modules/playwright-core": { - "version": "1.65.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz", - "integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=20" - } - } - } -} diff --git a/assets/package.json b/assets/package.json index cfeb097fc..3c859823d 100644 --- a/assets/package.json +++ b/assets/package.json @@ -2,8 +2,5 @@ "private": true, "scripts": { "test": "node --test js/*_test.mjs" - }, - "devDependencies": { - "playwright": "1.65.1" } } diff --git a/config/test.exs b/config/test.exs index e68db925a..814124c15 100644 --- a/config/test.exs +++ b/config/test.exs @@ -33,6 +33,17 @@ config :huddlz, :auth_rate_limits, # Configure PhoenixTest config :phoenix_test, :endpoint, HuddlzWeb.Endpoint +# Browser scenarios (mix test.browser). The endpoint's sandbox plug and +# AllowEctoSandbox read the sandbox metadata from the user agent. +config :fluffy, endpoint: HuddlzWeb.Endpoint, ecto_repos: [Huddlz.Repo] +config :fluffy, Fluffy.Sandbox, header: "user-agent" + +config :playwright, :test, + timezone_id: "America/New_York", + screenshot: :on, + trace: :on, + output_dir: "_build/browser/test-results" + # Disable swoosh api client in test config :swoosh, :api_client, false diff --git a/mix.exs b/mix.exs index 433bfdfb4..dc198ff9d 100644 --- a/mix.exs +++ b/mix.exs @@ -144,7 +144,7 @@ defmodule Huddlz.MixProject do {:mox, "~> 1.0", only: :test}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, {:phoenix_test, "~> 0.12", only: :test}, - {:phoenix_test_playwright, "~> 0.19.0", only: :test, runtime: false}, + {:fluffy, "~> 0.9.0-rc.5", only: :test}, {:slugify, "~> 1.3"}, {:remote_ip, "~> 1.1"}, {:envious, "~> 1.0"} diff --git a/mix.lock b/mix.lock index ebeec7830..056d3aa04 100644 --- a/mix.lock +++ b/mix.lock @@ -47,6 +47,7 @@ "finch": {:hex, :finch, "0.25.0", "ce6203ff9464baf7d82e71b9568cf061ed640317e7e3449dac7601d220689d53", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.2.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9fd9a2c47a9033f4d70fad6e7d656948c08bc6652699de20e609a5917c0bb0a5"}, "fine": {:hex, :fine, "0.2.0", "71d9ff9fa69a4167cff1f6e9fd3350ab8e45d26b52f484c6d6514194b594df02", [:mix], [], "hexpm", "6f69a9e8dadbfd017b27f611b000362870683ae65f28aec904f36ec4c5058db5"}, "floki": {:hex, :floki, "0.38.5", "5786298f62ea266f9a8e88642753a8bc99925cd1ed7a7c8e420f6965ddbc7d1f", [:mix], [], "hexpm", "c8c5b04455f01b076cd489fee7dc26b49edf9851ef61146e743f4676114bf6b0"}, + "fluffy": {:hex, :fluffy, "0.9.0-rc.5", "d3d4846b5d8ffa8cb838c74c364abc25f059f6e2ff4d9c31595d97a1d7bb0af1", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:lazy_html, ">= 0.1.0 and < 1.0.0", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.24 and < 2.0.0-0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, "~> 4.7", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 1.2.10 and < 2.0.0-0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:playwright, "~> 1.65.0-rc.3", [hex: :playwright_ex, repo: "hexpm", optional: false]}], "hexpm", "658fb1e5c337680e303c0f8560f9a39898666720fe7b096cb118a984eaf14666"}, "gettext": {:hex, :gettext, "1.0.2", "5457e1fd3f4abe47b0e13ff85086aabae760497a3497909b8473e0acee57673b", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "eab805501886802071ad290714515c8c4a17196ea76e5afc9d06ca85fb1bfeb3"}, "glob_ex": {:hex, :glob_ex, "0.1.12", "7b2d9369c20e2697efcfd185d13d6e84c94cd3bfd2730fbde613141c2e015c00", [:mix], [], "hexpm", "2e2fac83f113514434c7eaf267b4c38af2f91766f1cab2c5db7053b7fc1ee0bb"}, "hammer": {:hex, :hammer, "7.6.0", "6eb6239dc874d66cb289ee1816872f8c9366b8e21c6a1bac9120010a50c6db57", [:mix], [{:igniter, "~> 0.8", [hex: :igniter, repo: "hexpm", optional: true]}], "hexpm", "5777d22a2f96e53e489aa5a31aee73fe082da78464be52a688521772f96a934a"}, @@ -85,10 +86,9 @@ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.4.1", "2ff3e7ba8b432120989870997b9adaefb76e1f63805554ab0b9e948987981f4b", [:mix], [], "hexpm", "352fba7a87bf61395b6e97da66944ad9b1bfe5459e5981039f60d68270bd9700"}, "phoenix_template": {:hex, :phoenix_template, "1.1.0", "b329582281b1e00e4dc664afd60ef5b489cbb356923caa3b1e00abe8651b9a18", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "eba70070de79b2c3501ef205a74a69f98ab352f3785aa15da9ed161f9fe0fd5d"}, "phoenix_test": {:hex, :phoenix_test, "0.14.0", "3fef4f78a3438cc398a0884cc7370f9c9a0afdbd9d70b8bd362837cd61943ffe", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:lazy_html, "~> 0.1.7", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:mime, ">= 1.0.0", [hex: :mime, repo: "hexpm", optional: true]}, {:phoenix, ">= 1.7.10", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "0d090b0b6deb4193797f7bee8f19ecabdc4bb4000db51ccd140dded0b2d57be3"}, - "phoenix_test_playwright": {:hex, :phoenix_test_playwright, "0.19.0", "7f974843858132db85e9aa91bb3b11a76b1535070aae13afb351b7dacb9e4046", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, "~> 4.5", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_test, ">= 0.12.0 and < 1.0.0", [hex: :phoenix_test, repo: "hexpm", optional: false]}, {:playwright_ex, "~> 0.15", [hex: :playwright_ex, repo: "hexpm", optional: false]}, {:websockex, ">= 0.4.0 and < 1.0.0", [hex: :websockex, repo: "hexpm", optional: true]}], "hexpm", "0979bba45e54e8042bc0c13be9ae55d0b958c16603567adfea34f050e563b163"}, "phoenix_view": {:hex, :phoenix_view, "2.0.4", "b45c9d9cf15b3a1af5fb555c674b525391b6a1fe975f040fb4d913397b31abf4", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "4e992022ce14f31fe57335db27a28154afcc94e9983266835bb3040243eb620b"}, "picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"}, - "playwright_ex": {:hex, :playwright_ex, "0.16.0", "21d26ac29e18140a23e8f8bf78648fee233ae3bf03ce799306647bcdfd3b42e9", [:mix], [{:mime, "~> 2.0", [hex: :mime, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:websockex, ">= 0.4.0 and < 1.0.0", [hex: :websockex, repo: "hexpm", optional: true]}], "hexpm", "8ef7f618e0c282dd68b5aba1bcbb73be48aef3b835e82828a21586050318a95f"}, + "playwright": {:hex, :playwright_ex, "1.65.0-rc.4", "be9390181664ad361880c5da24771b0ea524add332c10cad1c9b0da9ed2e33ae", [:mix], [], "hexpm", "7505d4ba8260bc88c096f4a8c538d21639d7d71a7166f8d6e0afade506b569cc"}, "plug": {:hex, :plug, "1.20.4", "8fca521b31eb586dbb91968dd9fa95be6b60fb40f9ca77b005361e06836aed75", [: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", "96ee42c0b8b35bcb14e3e65afb85abe9bb7745a8576e8c602802bbb01e5acf72"}, "plug_crypto": {:hex, :plug_crypto, "2.2.1", "bd1d0358a2e2f5ffb818217e64c394f9d24ed191d862b7fa1bcce264ace2b8ea", [:mix], [], "hexpm", "4417ccbd8f85e627321cd07d2ab9c4b621f1fd883b9905af241f9b4b780b94b6"}, "postgrex": {:hex, :postgrex, "0.23.0", "f106e1429559f0db8799c250279ee5fa16e364a39380cd9523e725df3625b235", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "f001ab3fd56f5ef2b8b3cd4a512005614fcaeccca068ddb29e57d338a7f104ec"}, diff --git a/test/browser/README.md b/test/browser/README.md index ec7e6f5bd..607fe1ec1 100644 --- a/test/browser/README.md +++ b/test/browser/README.md @@ -11,8 +11,7 @@ One-time setup from the repository root: ```sh MIX_ENV=test mix deps.get MIX_ENV=test mix assets.setup -npm ci --prefix assets -PLAYWRIGHT_BROWSERS_PATH="$PWD/_build/browser/browsers" assets/node_modules/.bin/playwright install chromium --only-shell +MIX_ENV=test PLAYWRIGHT_BROWSERS_PATH="$PWD/_build/browser/browsers" mix playwright.install chromium --only-shell ``` On Linux, add `--with-deps` to the Playwright install command to install the required system libraries. @@ -47,16 +46,16 @@ Browser scenarios live in `features/`, their steps in `steps/`, and Cucumber hoo Keep this suite serial: its SQL sandbox ownership and global Mox stubs are shared with HTTP/LiveView processes. Do not add `@async` or extra workers without changing that fixture strategy. Each scenario gets a fresh browser context. Authentication uses a signed session cookie; apart from password recovery, these are not sign-in UI tests. Places/geocoding are deterministic stubs, with no external service credentials needed. The test endpoint serves the app over HTTP. Each browser context answers HTTPS requests locally so third-party services cannot delay page loads. Google Fonts requests receive the Inter fixture from `test/fixtures/fonts` to preserve layout measurements. Other HTTPS requests, including Maps embeds, receive an empty response. Browser contexts use `America/New_York`; `@mobile` selects a 320×720 viewport. -Browser setup uses the adapter's public `Case.do_setup_all/1` and `Case.do_setup/1` functions because Cucumber creates the ExUnit modules. The hook supplies a compatible module name for diagnostic filenames, preserving the scenario name. SQL sandbox HTTP metadata and the LiveView allowance hook are enabled only in test builds, before authentication queries. +Browser setup calls `Playwright.Test`'s per-test setup from the hook because Cucumber creates the ExUnit modules, so none of them can `use Playwright.Test`. SQL sandbox HTTP metadata and the LiveView allowance hook are enabled only in test builds, before authentication queries. ## CI and diagnostics -The **Browser scenarios (Chromium)** job runs separately on every PR, including stacked PRs, and every push to `main`, alongside the fast tests. It installs the pinned Playwright version from `assets/package-lock.json`, Chromium headless shell, and Linux libraries. It uses one worker, a two-minute test-step timeout, and no automatic retries. Dependency compilation is cached; browser binaries and diagnostics are not part of that cache. +The **Browser scenarios (Chromium)** job runs separately on every PR, including stacked PRs, and every push to `main`, alongside the fast tests. It installs the Playwright driver that Fluffy pins, Chromium headless shell, and Linux libraries. It uses one worker, a two-minute test-step timeout, and no automatic retries. Dependency compilation is cached; browser binaries and diagnostics are not part of that cache. -Screenshots and traces are captured for every attempt under `_build/browser/screenshots` and `_build/browser/traces`. Failed CI runs upload these directories as `browser-failure-diagnostics` for seven days. Inspect the original failure before rerunning: +Screenshots and traces are captured for every attempt under `_build/browser/test-results`, one directory per scenario; explicit screenshots go to `_build/browser/screenshots`. Failed CI runs upload these directories as `browser-failure-diagnostics` for seven days. Inspect the original failure before rerunning: ```sh -assets/node_modules/.bin/playwright show-trace _build/browser/traces/ +MIX_ENV=test mix playwright.cli show-trace _build/browser/test-results//trace.zip ``` Assertions wait for observable browser state instead of sleeping. When an interaction needs LiveView to have connected after navigation, use `assert_has("body .phx-connected")` before sending input. JavaScript used in steps observes layout, image loading, or native form submissions; it does not implement the application behavior. The failed-cover scenario intentionally requests a missing image, so its expected 404 is not a suite-wide console failure. diff --git a/test/browser/steps/appearance_menu_steps.exs b/test/browser/steps/appearance_menu_steps.exs index 8e965f8f9..cbc9436ca 100644 --- a/test/browser/steps/appearance_menu_steps.exs +++ b/test/browser/steps/appearance_menu_steps.exs @@ -3,15 +3,14 @@ defmodule BrowserAppearanceMenuSteps do import ExUnit.Assertions import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest @menu_open "document.querySelector('#theme-menu').matches(':popover-open')" step "I open the appearance menu with the keyboard", context do conn = context.conn - |> press("#theme-menu-trigger", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#theme-menu-trigger", "Enter")) |> assert_browser(@menu_open) Map.put(context, :conn, conn) @@ -19,7 +18,7 @@ defmodule BrowserAppearanceMenuSteps do step "I pick {string} with the keyboard", %{args: [label]} = context do conn = tab_to_option(context.conn, label) - Map.put(context, :conn, press(conn, ":focus", "Enter")) + Map.put(context, :conn, unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Enter"))) end step "the page uses the dark appearance and the menu is closed", context do @@ -33,7 +32,7 @@ defmodule BrowserAppearanceMenuSteps do end step "I press Escape", context do - Map.put(context, :conn, press(context.conn, ":focus", "Escape")) + Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Escape"))) end step "the menu is closed and focus is back on its trigger", context do @@ -52,12 +51,15 @@ defmodule BrowserAppearanceMenuSteps do defp tab_to_option(_conn, label, 0), do: flunk("no appearance option labelled #{label}") defp tab_to_option(conn, label, tries) do - conn = press(conn, ":focus", "Tab") + conn = unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Tab")) - {:ok, focused} = - PlaywrightEx.Frame.evaluate(conn.frame_id, - expression: "document.activeElement.querySelector('.theme-option-label')?.textContent", - timeout: 5_000 + focused = + unwrap_and_return( + conn, + &Playwright.Page.evaluate!( + &1, + "document.activeElement.querySelector('.theme-option-label')?.textContent" + ) ) if focused == label, do: conn, else: tab_to_option(conn, label, tries - 1) diff --git a/test/browser/steps/calendar_day_sheet_steps.exs b/test/browser/steps/calendar_day_sheet_steps.exs index cb6656e4d..e73ba6122 100644 --- a/test/browser/steps/calendar_day_sheet_steps.exs +++ b/test/browser/steps/calendar_day_sheet_steps.exs @@ -3,7 +3,7 @@ defmodule BrowserCalendarDaySheetSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest step "I am going to {string} on the 17th of next month", %{args: [title]} = context do attendee = generate(user(role: :user)) diff --git a/test/browser/steps/calendar_timezone_steps.exs b/test/browser/steps/calendar_timezone_steps.exs index db398f913..aed3db66b 100644 --- a/test/browser/steps/calendar_timezone_steps.exs +++ b/test/browser/steps/calendar_timezone_steps.exs @@ -3,7 +3,7 @@ defmodule BrowserCalendarSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest step "I attend a Denver huddl late on July 15", context do attendee = generate(user(role: :user)) diff --git a/test/browser/steps/copy_huddl_steps.exs b/test/browser/steps/copy_huddl_steps.exs index 63d263ec0..0b94782a7 100644 --- a/test/browser/steps/copy_huddl_steps.exs +++ b/test/browser/steps/copy_huddl_steps.exs @@ -3,7 +3,7 @@ defmodule BrowserCopyHuddlSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest step "I opened a copied huddl on my phone", context do owner = generate(user(role: :user)) @@ -21,10 +21,12 @@ defmodule BrowserCopyHuddlSteps do end step "I review the copied description", context do - PhoenixTest.Playwright.evaluate( + unwrap( context.conn, - "document.querySelector('#form_description').scrollIntoView({block: 'center'})", - fn _ -> :ok end + &Playwright.Page.evaluate!( + &1, + "document.querySelector('#form_description').scrollIntoView({block: 'center'})" + ) ) context diff --git a/test/browser/steps/cover_crop_steps.exs b/test/browser/steps/cover_crop_steps.exs index c334a2efa..82a1f6017 100644 --- a/test/browser/steps/cover_crop_steps.exs +++ b/test/browser/steps/cover_crop_steps.exs @@ -4,12 +4,12 @@ defmodule BrowserCoverCropSteps do import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest require Ash.Query - alias PlaywrightEx.Frame - alias PlaywrightEx.Page + alias Playwright.Mouse + alias Playwright.Page step "I am creating a group in a browser", context do owner = generate(user(role: :user)) @@ -29,12 +29,12 @@ defmodule BrowserCoverCropSteps do end step "I choose a tall picture for the cover", context do - assert {:ok, _} = - Frame.set_input_files(context.conn.frame_id, - selector: "#group-cover-upload input[type=file]", - timeout: 5_000, - local_paths: [Path.expand("test/fixtures/tall_red_blue.png")] - ) + unwrap( + context.conn, + &Page.set_input_files!(&1, "#group-cover-upload input[type=file]", [ + Path.expand("test/fixtures/tall_red_blue.png") + ]) + ) context end @@ -79,28 +79,31 @@ defmodule BrowserCoverCropSteps do step "I drag the picture up to keep its bottom and use the photo", context do conn = context.conn - {:ok, %{"x" => x, "top" => top, "bottom" => bottom}} = - Frame.evaluate(conn.frame_id, - timeout: 5_000, - expression: """ + %{"x" => x, "top" => top, "bottom" => bottom} = + unwrap_and_return( + conn, + &Page.evaluate!(&1, """ (() => { const win = document.querySelector('#group-cover-upload-crop .crop-window').getBoundingClientRect(); return {x: win.left + win.width / 2, top: win.top + 4, bottom: win.bottom - 4}; })() - """ + """) ) # Three drags from the bottom of the window to its top; the picture # stops at its own bottom edge, whatever it was dragged past. - for _ <- 1..3 do - assert {:ok, _} = Page.mouse_move(conn.page_id, x: x, y: bottom, timeout: 5_000) - assert {:ok, _} = Page.mouse_down(conn.page_id, timeout: 5_000) - assert {:ok, _} = Page.mouse_move(conn.page_id, x: x, y: top, steps: 6, timeout: 5_000) - assert {:ok, _} = Page.mouse_up(conn.page_id, timeout: 5_000) - end - conn = conn + |> unwrap(fn page -> + mouse = Page.mouse(page) + + for _ <- 1..3 do + Mouse.move!(mouse, x, bottom) + Mouse.down!(mouse) + Mouse.move!(mouse, x, top, steps: 6) + Mouse.up!(mouse) + end + end) |> assert_browser(""" (() => { const sheet = document.querySelector('#group-cover-upload-crop'); @@ -122,11 +125,13 @@ defmodule BrowserCoverCropSteps do "#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']" ) - {:ok, thumbnail_path} = - Frame.evaluate(conn.frame_id, - timeout: 5_000, - expression: + thumbnail_path = + unwrap_and_return( + conn, + &Page.evaluate!( + &1, "document.querySelector('#group-cover-upload .cover-slot img').getAttribute('src')" + ) ) image = diff --git a/test/browser/steps/cover_upload_progress_steps.exs b/test/browser/steps/cover_upload_progress_steps.exs index 19dfea5c3..5b21d27cf 100644 --- a/test/browser/steps/cover_upload_progress_steps.exs +++ b/test/browser/steps/cover_upload_progress_steps.exs @@ -1,10 +1,9 @@ defmodule BrowserCoverUploadSteps do use Cucumber.StepDefinition - import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest alias Huddlz.Storage.GroupImages @@ -43,12 +42,12 @@ defmodule BrowserCoverUploadSteps do end step "I choose a picture for the cover", context do - assert {:ok, _} = - PlaywrightEx.Frame.set_input_files(context.conn.frame_id, - selector: "#group-cover-upload input[type=file]", - timeout: 5_000, - local_paths: [Path.expand("test/fixtures/test_image.jpg")] - ) + unwrap( + context.conn, + &Playwright.Page.set_input_files!(&1, "#group-cover-upload input[type=file]", [ + Path.expand("test/fixtures/test_image.jpg") + ]) + ) # The crop sheet opens first; the picture already fits, so use it as is. conn = diff --git a/test/browser/steps/discover_navigation_steps.exs b/test/browser/steps/discover_navigation_steps.exs index 946c77a05..12651334e 100644 --- a/test/browser/steps/discover_navigation_steps.exs +++ b/test/browser/steps/discover_navigation_steps.exs @@ -3,8 +3,7 @@ defmodule BrowserDiscoverNavigationSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [evaluate: 3] + import Fluffy.PhoenixTest step "a public huddl titled {string} is upcoming", %{args: [title]} = context do host = generate(user(role: :user)) @@ -38,7 +37,7 @@ defmodule BrowserDiscoverNavigationSteps do end step "I follow Discover in the sidebar", context do - evaluate(context.conn, "window.__huddlzPage = 'kept'", fn _ -> :ok end) + unwrap(context.conn, &Playwright.Page.evaluate!(&1, "window.__huddlzPage = 'kept'")) conn = click_link(context.conn, ".sb-nav a", "Discover") diff --git a/test/browser/steps/email_confirmation_steps.exs b/test/browser/steps/email_confirmation_steps.exs index a24430e72..ea7ad885c 100644 --- a/test/browser/steps/email_confirmation_steps.exs +++ b/test/browser/steps/email_confirmation_steps.exs @@ -4,7 +4,7 @@ defmodule BrowserEmailConfirmationSteps do import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest import Swoosh.TestAssertions step "I have hidden the reminder for my unconfirmed address in a browser", context do diff --git a/test/browser/steps/group_cover_steps.exs b/test/browser/steps/group_cover_steps.exs index c5069171d..b08d2e0f7 100644 --- a/test/browser/steps/group_cover_steps.exs +++ b/test/browser/steps/group_cover_steps.exs @@ -4,8 +4,7 @@ defmodule BrowserCoverSteps do import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [evaluate: 3] + import Fluffy.PhoenixTest alias Huddlz.Storage.Local @@ -55,7 +54,7 @@ defmodule BrowserCoverSteps do context.conn |> visit("/groups/#{context.group.slug}") |> assert_has(".phx-connected") - |> assert_has("h1", text: context.group.name) + |> assert_has("h1", text: to_string(context.group.name)) Map.put(context, :conn, conn) end @@ -117,20 +116,21 @@ defmodule BrowserCoverSteps do defp assert_cover(conn, state) do conn = assert_has(conn, "#group-detail-hero .cover-image") - evaluate( - conn, - """ - (async () => { - const element = document.querySelector('#group-detail-hero .cover-image'); - const url = getComputedStyle(element).backgroundImage.slice(5, -2); - const image = new Image(); - image.src = url; - try { await image.decode(); return image.naturalWidth > 0; } - catch { return false; } - })() - """, - fn decoded -> assert decoded == (state == "valid") end - ) + unwrap(conn, fn page -> + decoded = + Playwright.Page.evaluate!(page, """ + (async () => { + const element = document.querySelector('#group-detail-hero .cover-image'); + const url = getComputedStyle(element).backgroundImage.slice(5, -2); + const image = new Image(); + image.src = url; + try { await image.decode(); return image.naturalWidth > 0; } + catch { return false; } + })() + """) + + assert decoded == (state == "valid") + end) outcome = if state == "valid", do: "loaded", else: "failed" conn = assert_has(conn, "#group-detail-hero .cover-image[data-cover-state='#{outcome}']") diff --git a/test/browser/steps/huddl_photos_steps.exs b/test/browser/steps/huddl_photos_steps.exs index d8d8eb4d2..c33f7df54 100644 --- a/test/browser/steps/huddl_photos_steps.exs +++ b/test/browser/steps/huddl_photos_steps.exs @@ -1,10 +1,8 @@ defmodule BrowserPhotoSteps do use Cucumber.StepDefinition - import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest step "I am viewing my completed huddl in the browser", context do owner = generate(user(display_name: "Sam Rivera")) @@ -29,12 +27,13 @@ defmodule BrowserPhotoSteps do File.write!(path, :binary.copy(<<0>>, 6_000_000)) ExUnit.Callbacks.on_exit(fn -> File.rm(path) end) - assert {:ok, _} = - PlaywrightEx.Frame.set_input_files(context.conn.frame_id, - selector: "#huddl-photo-upload-form input[type=file]", - timeout: 5_000, - local_paths: [Path.expand("test/fixtures/test_image.jpg"), path] - ) + unwrap( + context.conn, + &Playwright.Page.set_input_files!(&1, "#huddl-photo-upload-form input[type=file]", [ + Path.expand("test/fixtures/test_image.jpg"), + path + ]) + ) context end @@ -56,12 +55,12 @@ defmodule BrowserPhotoSteps do end step "I select a corrupt image and submit it", context do - assert {:ok, _} = - PlaywrightEx.Frame.set_input_files(context.conn.frame_id, - selector: "#huddl-photo-upload-form input[type=file]", - timeout: 5_000, - local_paths: [Path.expand("test/fixtures/corrupt_image.jpg")] - ) + unwrap( + context.conn, + &Playwright.Page.set_input_files!(&1, "#huddl-photo-upload-form input[type=file]", [ + Path.expand("test/fixtures/corrupt_image.jpg") + ]) + ) Map.put(context, :conn, click_button(context.conn, "Upload photos")) end @@ -78,19 +77,17 @@ defmodule BrowserPhotoSteps do step "I choose two photos using the keyboard upload control", context do conn = context.conn - |> press("#huddl-hero-group", "Tab") + |> unwrap(&Playwright.Page.press!(&1, "#huddl-hero-group", "Tab")) |> assert_has("#browse-photos:focus") - |> press(":focus", "Enter") - - assert {:ok, _} = - PlaywrightEx.Frame.set_input_files(conn.frame_id, - selector: "#huddl-photo-upload-form input[type=file]", - timeout: 5_000, - local_paths: [ - Path.expand("test/fixtures/test_image.jpg"), - Path.expand("priv/static/icon-512.png") - ] - ) + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Enter")) + + unwrap( + conn, + &Playwright.Page.set_input_files!(&1, "#huddl-photo-upload-form input[type=file]", [ + Path.expand("test/fixtures/test_image.jpg"), + Path.expand("priv/static/icon-512.png") + ]) + ) Map.put(context, :conn, conn) end @@ -111,7 +108,9 @@ defmodule BrowserPhotoSteps do |> assert_has(".photo-tile", count: 2) |> refute_has(".photo-upload-entry") - conn = press(conn, ".photo-tile:first-child .photo-open", "Enter") + conn = + unwrap(conn, &Playwright.Page.press!(&1, ".photo-tile:first-child .photo-open", "Enter")) + Map.put(context, :conn, conn) end @@ -119,15 +118,15 @@ defmodule BrowserPhotoSteps do conn = context.conn |> assert_has("#photo-lightbox button[aria-label='Previous photo']:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#photo-lightbox button[aria-label='Next photo']:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#photo-lightbox .lightbox-actions button:focus", text: "Close") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#photo-lightbox button[aria-label='close']:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#photo-lightbox button[aria-label='Previous photo']:focus") - |> press(":focus", "Shift+Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) |> assert_has("#photo-lightbox button[aria-label='close']:focus") Map.put(context, :conn, conn) @@ -136,13 +135,13 @@ defmodule BrowserPhotoSteps do step "I can navigate with arrow keys and see the contributor and photo position", context do conn = context.conn - |> assert_has("#photo-lightbox", text: "Sam Rivera") + |> assert_has("#photo-lightbox [role='dialog']", text: "Sam Rivera") |> assert_has("#photo-position", text: "1 of 2") - |> press(":focus", "ArrowRight") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowRight")) |> assert_has("#photo-position", text: "2 of 2") - |> press(":focus", "ArrowRight") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowRight")) |> assert_has("#photo-position", text: "1 of 2") - |> press(":focus", "ArrowLeft") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowLeft")) |> assert_has("#photo-position", text: "2 of 2") Map.put(context, :conn, conn) @@ -151,7 +150,7 @@ defmodule BrowserPhotoSteps do step "Escape returns focus to the photo I opened", context do conn = context.conn - |> press(":focus", "Escape") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Escape")) |> assert_browser("!document.querySelector('#photo-lightbox')") |> assert_has(".photo-tile:first-child .photo-open:focus") @@ -171,22 +170,29 @@ defmodule BrowserPhotoSteps do end step "I consider deleting the first photo", context do - Map.put(context, :conn, press(context.conn, ".photo-tile:first-child .photo-delete", "Enter")) + Map.put( + context, + :conn, + unwrap( + context.conn, + &Playwright.Page.press!(&1, ".photo-tile:first-child .photo-delete", "Enter") + ) + ) end step "Tab and Shift+Tab stay inside the photo deletion dialog", context do conn = context.conn |> assert_has("#cancel-delete-photo:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#confirm-delete-photo:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#delete-photo-modal button[aria-label='close']:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#cancel-delete-photo:focus") - |> press(":focus", "Shift+Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) |> assert_has("#delete-photo-modal button[aria-label='close']:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#cancel-delete-photo:focus") Map.put(context, :conn, conn) @@ -196,9 +202,9 @@ defmodule BrowserPhotoSteps do conn = context.conn |> assert_has("#delete-photo-modal img") - |> assert_has("#delete-photo-modal", text: "Sam Rivera") - |> press(":focus", "Enter") - |> refute_has("#delete-photo-modal") + |> assert_has("#delete-photo-modal [role='dialog']", text: "Sam Rivera") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Enter")) + |> refute_has("#delete-photo-modal [role='dialog']") |> assert_has(".photo-tile", count: 2) assert_has(conn, ".photo-tile:first-child .photo-delete:focus") diff --git a/test/browser/steps/keyboard_focus_steps.exs b/test/browser/steps/keyboard_focus_steps.exs index 2c0fc96d0..990951c12 100644 --- a/test/browser/steps/keyboard_focus_steps.exs +++ b/test/browser/steps/keyboard_focus_steps.exs @@ -4,8 +4,7 @@ defmodule BrowserKeyboardFocusSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers import Huddlz.Test.MoxHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest step "I am signed in and looking at my groups in a browser", context do member = generate(user(role: :user)) @@ -18,15 +17,15 @@ defmodule BrowserKeyboardFocusSteps do end step "I press Tab from the top of the page", context do - Map.put(context, :conn, press(context.conn, "body", "Tab")) + Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, "body", "Tab"))) end step "I press Tab", context do - Map.put(context, :conn, press(context.conn, ":focus", "Tab")) + Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Tab"))) end step "I follow the skip link with Enter", context do - Map.put(context, :conn, press(context.conn, ":focus", "Enter")) + Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Enter"))) end step "{string} has keyboard focus", %{args: [name]} = context do @@ -79,7 +78,7 @@ defmodule BrowserKeyboardFocusSteps do |> fill_in("Display Name", with: "Keyboard Person") |> fill_in("Password", with: "ValidPassword123!") |> fill_in("Confirm Password", with: "ValidPassword123!") - |> press("#registration-form button[type=submit]", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#registration-form button[type=submit]", "Enter")) Map.put(context, :conn, conn) end @@ -97,7 +96,7 @@ defmodule BrowserKeyboardFocusSteps do context.conn |> fill_in("Group name", with: "Keyboard Review Group") |> fill_in("Description", with: "A group for reviewing keyboard access") - |> press("#group-form button[type=submit]", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#group-form button[type=submit]", "Enter")) Map.put(context, :conn, conn) end @@ -107,7 +106,7 @@ defmodule BrowserKeyboardFocusSteps do context.conn |> within("#group-location", &click_button(&1, "Clear")) |> assert_has("#group-location-input") - |> press("#edit-group-form button[type=submit]", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#edit-group-form button[type=submit]", "Enter")) Map.put(context, :conn, conn) end @@ -116,7 +115,7 @@ defmodule BrowserKeyboardFocusSteps do conn = context.conn |> fill_in("Opening line", with: String.duplicate("a", 141)) - |> press("#schedule-form button[type=submit]", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#schedule-form button[type=submit]", "Enter")) Map.put(context, :conn, conn) end @@ -125,7 +124,7 @@ defmodule BrowserKeyboardFocusSteps do conn = context.conn |> click_button("#turnout-nudge button", "Add turnout") - |> press("#turnout-form-nudge button[type=submit]", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#turnout-form-nudge button[type=submit]", "Enter")) Map.put(context, :conn, conn) end @@ -238,9 +237,9 @@ defmodule BrowserKeyboardFocusSteps do context.conn |> fill_in("Search for an address", with: "saint") |> assert_has("[role='option']") - |> press("#modal-address-autocomplete-input", "ArrowDown") + |> unwrap(&Playwright.Page.press!(&1, "#modal-address-autocomplete-input", "ArrowDown")) |> assert_has("#modal-address-autocomplete[data-has-highlight='true']") - |> press("#modal-address-autocomplete-input", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#modal-address-autocomplete-input", "Enter")) |> assert_has("#new-location-form button[type=submit]:not([disabled])") Map.put(context, :conn, conn) @@ -280,7 +279,7 @@ defmodule BrowserKeyboardFocusSteps do conn = context.conn |> within(context.focus_form, &fill_in(&1, label, with: value)) - |> press(submit, "Enter") + |> unwrap(&Playwright.Page.press!(&1, submit, "Enter")) Map.put(context, :conn, conn) end diff --git a/test/browser/steps/location_keyboard_steps.exs b/test/browser/steps/location_keyboard_steps.exs index ff8dfad63..8ce9ba281 100644 --- a/test/browser/steps/location_keyboard_steps.exs +++ b/test/browser/steps/location_keyboard_steps.exs @@ -5,8 +5,7 @@ defmodule BrowserLocationKeyboardSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers import Huddlz.Test.MoxHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [type: 3, press: 3, evaluate: 3] + import Fluffy.PhoenixTest step "I have opened my profile in a browser", context do member = generate(user(role: :user, display_name: "Browser Member")) @@ -20,16 +19,15 @@ defmodule BrowserLocationKeyboardSteps do |> visit("/profile") |> assert_has(".phx-connected") |> assert_has("h1", text: "Profile") - |> evaluate( - """ - (() => { - window.observedSubmissions = 0; - document.addEventListener('submit', () => window.observedSubmissions++, true); - return true; - })() - """, - fn installed -> assert installed end - ) + |> unwrap(fn page -> + assert Playwright.Page.evaluate!(page, """ + (() => { + window.observedSubmissions = 0; + document.addEventListener('submit', () => window.observedSubmissions++, true); + return true; + })() + """) + end) ExUnit.Callbacks.on_exit(fn -> File.rm_rf!("priv/static/uploads/profile_pictures/#{member.id}") @@ -39,21 +37,33 @@ defmodule BrowserLocationKeyboardSteps do end step "I type {string} into my home location", %{args: [query]} = context do - conn = context.conn |> type("#profile-location-input", query) |> assert_has("[role='option']") + conn = + context.conn + |> unwrap( + &(&1 + |> Playwright.Page.locator("#profile-location-input") + |> Playwright.Locator.press_sequentially!(query)) + ) + |> assert_has("[role='option']") + Map.put(context, :conn, conn) end step "I highlight the first home location suggestion", context do conn = context.conn - |> press("#profile-location-input", "ArrowDown") + |> unwrap(&Playwright.Page.press!(&1, "#profile-location-input", "ArrowDown")) |> assert_has("#profile-location[data-has-highlight='true']") Map.put(context, :conn, conn) end step "I select the highlighted home location with Enter", context do - Map.put(context, :conn, press(context.conn, "#profile-location-input", "Enter")) + Map.put( + context, + :conn, + unwrap(context.conn, &Playwright.Page.press!(&1, "#profile-location-input", "Enter")) + ) end step "my home location is {string}", %{args: [location]} = context do @@ -65,7 +75,10 @@ defmodule BrowserLocationKeyboardSteps do end step "Enter did not submit a form", context do - evaluate(context.conn, "window.observedSubmissions", fn count -> assert count == 0 end) + unwrap(context.conn, fn page -> + assert Playwright.Page.evaluate!(page, "window.observedSubmissions") == 0 + end) + context end end diff --git a/test/browser/steps/member_menu_steps.exs b/test/browser/steps/member_menu_steps.exs index 81d8e4603..a3e3e6fcc 100644 --- a/test/browser/steps/member_menu_steps.exs +++ b/test/browser/steps/member_menu_steps.exs @@ -4,8 +4,7 @@ defmodule BrowserMemberMenuSteps do import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest step "I have opened a group's roster in a browser", context do owner = generate(user(role: :user, display_name: "Owner Olive")) @@ -31,7 +30,7 @@ defmodule BrowserMemberMenuSteps do step "I open the menu for {string} with the keyboard", %{args: [name]} = context do conn = context.conn - |> press(trigger_for(name), "Enter") + |> unwrap(&Playwright.Page.press!(&1, trigger_for(name), "Enter")) |> assert_browser(menu_open(name)) Map.merge(context, %{conn: conn, menu_name: name}) @@ -39,7 +38,7 @@ defmodule BrowserMemberMenuSteps do step "I choose {string} with the keyboard", %{args: [label]} = context do conn = tab_to_item(context.conn, label) - Map.put(context, :conn, press(conn, ":focus", "Enter")) + Map.put(context, :conn, unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Enter"))) end step "the member menu is closed and focus is back on its button", context do @@ -75,12 +74,12 @@ defmodule BrowserMemberMenuSteps do defp tab_to_item(_conn, label, 0), do: flunk("no menu item labelled #{label}") defp tab_to_item(conn, label, tries) do - conn = press(conn, ":focus", "Tab") + conn = unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Tab")) - {:ok, focused} = - PlaywrightEx.Frame.evaluate(conn.frame_id, - expression: "document.activeElement.textContent.trim()", - timeout: 5_000 + focused = + unwrap_and_return( + conn, + &Playwright.Page.evaluate!(&1, "document.activeElement.textContent.trim()") ) if focused == label, do: conn, else: tab_to_item(conn, label, tries - 1) diff --git a/test/browser/steps/mobile_navigation_steps.exs b/test/browser/steps/mobile_navigation_steps.exs index 2487d7d2e..cf32675a2 100644 --- a/test/browser/steps/mobile_navigation_steps.exs +++ b/test/browser/steps/mobile_navigation_steps.exs @@ -2,14 +2,13 @@ defmodule BrowserNavigationSteps do use Cucumber.StepDefinition import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest step "I open mobile navigation with the keyboard", context do conn = context.conn |> assert_browser("document.querySelector('#mobile-navigation-drawer').inert") - |> press("#mobile-nav-trigger", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#mobile-nav-trigger", "Enter")) |> assert_has("#mobile-nav-close:focus") Map.put(context, :conn, conn) @@ -19,11 +18,11 @@ defmodule BrowserNavigationSteps do conn = context.conn |> assert_has("[data-mobile-nav-background][inert]") - |> press(":focus", "Shift+Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) |> assert_has("#mobile-navigation-drawer a[aria-label='huddlz home']:focus") - |> press(":focus", "Shift+Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) |> assert_has("#sidebar-user:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#mobile-navigation-drawer a[aria-label='huddlz home']:focus") |> assert_browser(""" (() => { @@ -36,7 +35,7 @@ defmodule BrowserNavigationSteps do end step "I close mobile navigation with Escape", context do - Map.put(context, :conn, press(context.conn, ":focus", "Escape")) + Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Escape"))) end step "focus returns to the navigation trigger and the page is usable", context do @@ -45,7 +44,7 @@ defmodule BrowserNavigationSteps do |> assert_has("#mobile-nav-trigger:focus[aria-expanded='false']") |> assert_browser("document.querySelector('#mobile-navigation-drawer').inert") |> refute_has("[data-mobile-nav-background][inert]") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_browser( "document.querySelector('[data-mobile-nav-background]').contains(document.activeElement)" ) @@ -56,7 +55,7 @@ defmodule BrowserNavigationSteps do step "I reopen mobile navigation and visit Groups", context do conn = context.conn - |> press("#mobile-nav-trigger", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#mobile-nav-trigger", "Enter")) |> click_link("#mobile-navigation-drawer a", "Groups") Map.put(context, :conn, conn) @@ -69,7 +68,7 @@ defmodule BrowserNavigationSteps do |> assert_has(".phx-connected") |> assert_browser("document.querySelector('#mobile-navigation-drawer').inert") |> refute_has("[data-mobile-nav-background][inert]") - |> press("#mobile-nav-trigger", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#mobile-nav-trigger", "Enter")) |> assert_has("#mobile-nav-close:focus") |> assert_has("[data-mobile-nav-background][inert]") diff --git a/test/browser/steps/mobile_rsvp_steps.exs b/test/browser/steps/mobile_rsvp_steps.exs index e6f8c01a2..8769dd2ce 100644 --- a/test/browser/steps/mobile_rsvp_steps.exs +++ b/test/browser/steps/mobile_rsvp_steps.exs @@ -3,7 +3,7 @@ defmodule BrowserMobileRsvpSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest step "I am viewing an upcoming huddl in a narrow browser", context do owner = generate(user(display_name: "Sam Rivera")) diff --git a/test/browser/steps/notification_preferences_steps.exs b/test/browser/steps/notification_preferences_steps.exs index b9aea2e80..c3f3b2def 100644 --- a/test/browser/steps/notification_preferences_steps.exs +++ b/test/browser/steps/notification_preferences_steps.exs @@ -3,8 +3,7 @@ defmodule BrowserNotificationPreferencesSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [click: 3] + import Fluffy.PhoenixTest step "I have opened my notification preferences in a browser", context do member = generate(user(role: :user)) @@ -27,7 +26,15 @@ defmodule BrowserNotificationPreferencesSteps do # A person flips a switch by clicking its row label; the checkbox itself # is visually hidden behind the track. step "I flip {string} off", %{args: [label]} = context do - Map.put(context, :conn, click(context.conn, "label", label)) + Map.put( + context, + :conn, + unwrap(context.conn, fn page -> + page + |> Playwright.Page.locator("label", has: Playwright.Page.get_by_text(page, label)) + |> Playwright.Locator.click!() + end) + ) end step "the row says the change could not be saved", context do diff --git a/test/browser/steps/organizer_keyboard_steps.exs b/test/browser/steps/organizer_keyboard_steps.exs index 2c37074c1..0527f3d11 100644 --- a/test/browser/steps/organizer_keyboard_steps.exs +++ b/test/browser/steps/organizer_keyboard_steps.exs @@ -3,8 +3,7 @@ defmodule BrowserOrganizerSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest step "I have opened a new huddl as its group organizer", context do owner = generate(user(role: :user)) @@ -22,9 +21,9 @@ defmodule BrowserOrganizerSteps do step "I tab into the format choices and choose virtual with an arrow key", context do conn = context.conn - |> press("textarea[name='form[description]']", "Tab") + |> unwrap(&Playwright.Page.press!(&1, "textarea[name='form[description]']", "Tab")) |> assert_has("#event-type-in_person:focus") - |> press(":focus", "ArrowRight") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowRight")) Map.put(context, :conn, conn) end @@ -43,14 +42,14 @@ defmodule BrowserOrganizerSteps do step "I enable recurrence and members only using Space", context do conn = context.conn - |> press("select[name='form[duration_minutes]']", "Tab") + |> unwrap(&Playwright.Page.press!(&1, "select[name='form[duration_minutes]']", "Tab")) |> assert_has("input[name='form[is_recurring]']:focus") - |> press(":focus", "Space") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Space")) |> assert_has("input[name='form[is_recurring]']:checked:focus-visible[aria-checked='true']") |> assert_has("select[name='form[frequency]']") - |> press("input[name='form[max_attendees]']", "Tab") + |> unwrap(&Playwright.Page.press!(&1, "input[name='form[max_attendees]']", "Tab")) |> assert_has("input[name='form[is_private]']:focus") - |> press(":focus", "Space") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Space")) Map.put(context, :conn, conn) end diff --git a/test/browser/steps/overview_cards_steps.exs b/test/browser/steps/overview_cards_steps.exs index 3a3421f07..8bdb09476 100644 --- a/test/browser/steps/overview_cards_steps.exs +++ b/test/browser/steps/overview_cards_steps.exs @@ -3,7 +3,7 @@ defmodule BrowserOverviewCardsSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest alias Huddlz.Communities.HuddlAttendee diff --git a/test/browser/steps/profile_picture_steps.exs b/test/browser/steps/profile_picture_steps.exs index d661c2719..6dfd25175 100644 --- a/test/browser/steps/profile_picture_steps.exs +++ b/test/browser/steps/profile_picture_steps.exs @@ -1,19 +1,17 @@ defmodule BrowserPictureSteps do use Cucumber.StepDefinition - import ExUnit.Assertions import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest step "I upload a profile picture through the file input", context do # The app intentionally hides its file input behind a visible upload label. - assert {:ok, _} = - PlaywrightEx.Frame.set_input_files(context.conn.frame_id, - selector: "#avatar-form input[type=file]", - timeout: 5_000, - local_paths: [Path.expand("test/fixtures/test_image.jpg")] - ) + unwrap( + context.conn, + &Playwright.Page.set_input_files!(&1, "#avatar-form input[type=file]", [ + Path.expand("test/fixtures/test_image.jpg") + ]) + ) # The crop sheet opens first; the picture is used as it is. conn = @@ -39,7 +37,7 @@ defmodule BrowserPictureSteps do step "I open the remove picture confirmation with the keyboard", context do conn = context.conn - |> press("#open-remove-avatar-dialog", "Enter") + |> unwrap(&Playwright.Page.press!(&1, "#open-remove-avatar-dialog", "Enter")) |> assert_has("#cancel-remove-avatar:focus") Map.put(context, :conn, conn) @@ -77,7 +75,7 @@ defmodule BrowserPictureSteps do step "my profile picture is replaced by initials", context do conn = context.conn - |> refute_has("#remove-avatar-dialog") + |> refute_has("#remove-avatar-dialog [role='dialog']") |> assert_has("[role='alert']", text: "Profile picture removed") |> refute_has("img.big-avatar") |> assert_has("main .big-avatar", text: "BM") @@ -88,25 +86,25 @@ defmodule BrowserPictureSteps do step "Tab stays inside the confirmation dialog", context do conn = context.conn - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#confirm-remove-avatar:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#remove-avatar-dialog button[aria-label='close']:focus") - |> press(":focus", "Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) |> assert_has("#cancel-remove-avatar:focus") - |> press(":focus", "Shift+Tab") + |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) |> assert_has("#remove-avatar-dialog button[aria-label='close']:focus") Map.put(context, :conn, conn) end step "I dismiss the confirmation with Escape", context do - Map.put(context, :conn, press(context.conn, ":focus", "Escape")) + Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Escape"))) end step "focus returns to Remove and my picture remains", context do context.conn - |> refute_has("#remove-avatar-dialog") + |> refute_has("#remove-avatar-dialog [role='dialog']") |> assert_has("#open-remove-avatar-dialog:focus") |> assert_has("img.big-avatar") diff --git a/test/browser/steps/report_review_steps.exs b/test/browser/steps/report_review_steps.exs index b52c6754a..745e98496 100644 --- a/test/browser/steps/report_review_steps.exs +++ b/test/browser/steps/report_review_steps.exs @@ -3,10 +3,9 @@ defmodule BrowserReportReviewSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest + import Fluffy.PhoenixTest alias Huddlz.Accounts - alias PhoenixTest.Playwright step "I am reviewing a reported account in a browser", context do owner = generate(user(display_name: "Sam Rivera")) @@ -29,7 +28,7 @@ defmodule BrowserReportReviewSteps do step "the report review controls stay together", context do check_controls(context.conn) - Playwright.screenshot(context.conn, "reports-#{size(context)}.png") + unwrap(context.conn, &screenshot(&1, "reports-#{size(context)}.png")) context end @@ -69,10 +68,17 @@ defmodule BrowserReportReviewSteps do step "the account review controls stay together", context do check_controls(context.conn) - Playwright.screenshot(context.conn, "users-review-#{size(context)}.png") + unwrap(context.conn, &screenshot(&1, "users-review-#{size(context)}.png")) context end + defp screenshot(page, name), + do: + Playwright.Page.screenshot!(page, + path: "_build/browser/screenshots/#{name}", + full_page: true + ) + defp size(context), do: if(Map.get(context, :mobile), do: "mobile", else: "desktop") defp check_controls(conn) do diff --git a/test/browser/steps/share_links_steps.exs b/test/browser/steps/share_links_steps.exs index 17e747a29..142a4ce2e 100644 --- a/test/browser/steps/share_links_steps.exs +++ b/test/browser/steps/share_links_steps.exs @@ -3,7 +3,7 @@ defmodule BrowserShareLinksSteps do import ExUnit.Assertions import Huddlz.Generator - import PhoenixTest + import Fluffy.PhoenixTest step "I am viewing a public {string} to share", %{args: [page]} = context do owner = generate(user()) @@ -12,39 +12,31 @@ defmodule BrowserShareLinksSteps do conn = context.conn |> visit(path) |> assert_has(".phx-connected") # Retain real clipboard access for observation even when the app's API is unavailable. - assert {:ok, _} = - PlaywrightEx.Frame.evaluate(conn.frame_id, - expression: """ - window.readClipboard = navigator.clipboard.readText.bind(navigator.clipboard); - navigator.clipboard.writeText('previous clipboard contents'); - """, - timeout: 5_000 - ) + unwrap( + conn, + &Playwright.Page.evaluate!(&1, """ + window.readClipboard = navigator.clipboard.readText.bind(navigator.clipboard); + navigator.clipboard.writeText('previous clipboard contents'); + """) + ) Map.merge(context, %{conn: conn, share_url: HuddlzWeb.Endpoint.url() <> path}) end step "direct clipboard access is {string}", %{args: [availability]} = context do - assert {:ok, _} = - PlaywrightEx.Frame.evaluate(context.conn.frame_id, - expression: clipboard_availability(availability), - timeout: 5_000 - ) + unwrap(context.conn, &Playwright.Page.evaluate!(&1, clipboard_availability(availability))) context end step "I copy the address from the Share section", context do refute_has(context.conn, "[role='dialog']") - Map.put(context, :conn, click_button(context.conn, "#share-actions", "Copy link")) + Map.put(context, :conn, click_button(context.conn, "#share-actions button", "Copy link")) end step "my clipboard contains the page's address", context do - assert {:ok, copied} = - PlaywrightEx.Frame.evaluate(context.conn.frame_id, - expression: "window.readClipboard()", - timeout: 5_000 - ) + copied = + unwrap_and_return(context.conn, &Playwright.Page.evaluate!(&1, "window.readClipboard()")) assert copied == context.share_url @@ -63,8 +55,8 @@ defmodule BrowserShareLinksSteps do step "I copy the address from the QR code dialog", context do conn = context.conn - |> click_button("#share-actions", "QR code") - |> click_button("[role='dialog']", "Copy link") + |> click_button("#share-actions button", "QR code") + |> click_button("[role='dialog'] button", "Copy link") Map.put(context, :conn, conn) end @@ -92,7 +84,9 @@ defmodule BrowserShareLinksSteps do defp clipboard_availability("rejected"), do: """ - navigator.clipboard.writeText = () => Promise.reject(new DOMException('Denied', 'NotAllowedError')); + () => { + navigator.clipboard.writeText = () => Promise.reject(new DOMException('Denied', 'NotAllowedError')); + } """ defp clipboard_availability("available"), do: "true" diff --git a/test/browser/steps/sidebar_scroll_steps.exs b/test/browser/steps/sidebar_scroll_steps.exs index e54fca742..ae347aa91 100644 --- a/test/browser/steps/sidebar_scroll_steps.exs +++ b/test/browser/steps/sidebar_scroll_steps.exs @@ -1,11 +1,9 @@ defmodule BrowserSidebarScrollSteps do use Cucumber.StepDefinition - import ExUnit.Assertions import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [press: 3] + import Fluffy.PhoenixTest @sidebar "document.querySelector('#mobile-navigation-drawer')" @@ -59,13 +57,17 @@ defmodule BrowserSidebarScrollSteps do step "I tab through to Sign out", context do # Nothing is focused on a fresh page, so the first Tab starts from the body. conn = - Enum.reduce_while(1..60, press(context.conn, "body", "Tab"), fn _n, conn -> - conn = press(conn, ":focus", "Tab") - - if evaluate(conn, "document.activeElement.id === 'sign-out-link'"), - do: {:halt, conn}, - else: {:cont, conn} - end) + Enum.reduce_while( + 1..60, + unwrap(context.conn, &Playwright.Page.press!(&1, "body", "Tab")), + fn _n, conn -> + conn = unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Tab")) + + if evaluate(conn, "document.activeElement.id === 'sign-out-link'"), + do: {:halt, conn}, + else: {:cont, conn} + end + ) Map.put(context, :conn, assert_has(conn, "#sign-out-link:focus")) end @@ -135,22 +137,13 @@ defmodule BrowserSidebarScrollSteps do })() """) - {:ok, _} = PlaywrightEx.Page.mouse_move(conn.page_id, x: x, y: y, timeout: 5_000) - - # The wheel call answers with an empty result; the next step observes the effect. - %{id: _} = - PlaywrightEx.send( - %{guid: conn.page_id, method: :mouse_wheel, params: %{delta_x: 0, delta_y: delta_y}}, - timeout: 5_000 - ) - - conn + unwrap(conn, fn page -> + mouse = Playwright.Page.mouse(page) + Playwright.Mouse.move!(mouse, x, y) + Playwright.Mouse.wheel!(mouse, 0, delta_y) + end) end - defp evaluate(conn, expression) do - {:ok, value} = - PlaywrightEx.Frame.evaluate(conn.frame_id, expression: expression, timeout: 5_000) - - value - end + defp evaluate(conn, expression), + do: unwrap_and_return(conn, &Playwright.Page.evaluate!(&1, expression)) end diff --git a/test/browser/steps/sign_in_return_steps.exs b/test/browser/steps/sign_in_return_steps.exs index ff2bfd65a..93bc2d7d3 100644 --- a/test/browser/steps/sign_in_return_steps.exs +++ b/test/browser/steps/sign_in_return_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserSignInReturnSteps do use Cucumber.StepDefinition import Huddlz.Generator - import PhoenixTest + import Fluffy.PhoenixTest import ExUnit.Assertions import Swoosh.TestAssertions, only: [set_swoosh_global: 0] diff --git a/test/browser/steps/social_schedule_steps.exs b/test/browser/steps/social_schedule_steps.exs index f97860392..5684f6832 100644 --- a/test/browser/steps/social_schedule_steps.exs +++ b/test/browser/steps/social_schedule_steps.exs @@ -3,8 +3,7 @@ defmodule BrowserSocialScheduleSteps do import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import PhoenixTest - import PhoenixTest.Playwright, only: [evaluate: 2, press: 3] + import Fluffy.PhoenixTest step "I am editing a social connection as its owner", context do {conn, group, _place} = connected_place(context.conn) @@ -54,7 +53,7 @@ defmodule BrowserSocialScheduleSteps do end step "I choose morning-of posting with Space", context do - conn = press(context.conn, "#moments_morning_of", "Space") + conn = unwrap(context.conn, &Playwright.Page.press!(&1, "#moments_morning_of", "Space")) Map.put(context, :conn, conn) end @@ -68,7 +67,7 @@ defmodule BrowserSocialScheduleSteps do context.conn |> fill_in("Opening line", with: "See you tonight!") |> click_button("Done") - |> refute_has("#schedule-sheet") + |> refute_has("#schedule-sheet [role='dialog']") Map.put(context, :conn, conn) end @@ -82,7 +81,7 @@ defmodule BrowserSocialScheduleSteps do |> assert_browser( "getComputedStyle(document.querySelector('#schedule-sheet-container')).opacity === '1'" ) - |> press("#opening-line", "Tab") + |> unwrap(&Playwright.Page.press!(&1, "#opening-line", "Tab")) |> assert_has("#remove-connection:focus") |> assert_browser(""" Array.from(document.querySelectorAll('#schedule-form button, #schedule-form a')).every(control => { @@ -113,7 +112,7 @@ defmodule BrowserSocialScheduleSteps do context.conn |> click_button("Start posting") |> assert_browser("location.search === ''") - |> refute_has("#schedule-sheet") + |> refute_has("#schedule-sheet [role='dialog']") |> click_link("Members") |> assert_has("h1", text: "Members") @@ -123,10 +122,10 @@ defmodule BrowserSocialScheduleSteps do step "Back returns to Social and back again reopens the connected place's schedule", context do conn = context.conn - |> evaluate("requestAnimationFrame(() => history.back())") + |> unwrap(&Playwright.Page.evaluate!(&1, "requestAnimationFrame(() => history.back())")) |> assert_has("a[aria-current='page']", text: "Social") - |> refute_has("#schedule-sheet") - |> evaluate("requestAnimationFrame(() => history.back())") + |> refute_has("#schedule-sheet [role='dialog']") + |> unwrap(&Playwright.Page.evaluate!(&1, "requestAnimationFrame(() => history.back())")) |> assert_has("#schedule-sheet", text: context.place.channel_name) Map.put(context, :conn, conn) @@ -134,8 +133,8 @@ defmodule BrowserSocialScheduleSteps do step "Forward returns to Social with the schedule closed", context do context.conn - |> evaluate("requestAnimationFrame(() => history.forward())") - |> refute_has("#schedule-sheet") + |> unwrap(&Playwright.Page.evaluate!(&1, "requestAnimationFrame(() => history.forward())")) + |> refute_has("#schedule-sheet [role='dialog']") |> assert_has("h1", text: "Social") context diff --git a/test/browser/support/hooks.exs b/test/browser/support/hooks.exs index 03c7e34db..2427a8b4a 100644 --- a/test/browser/support/hooks.exs +++ b/test/browser/support/hooks.exs @@ -1,8 +1,6 @@ defmodule BrowserHooks do use Cucumber.Hooks - alias PhoenixTest.Playwright.Case, as: BrowserCase - before_scenario context do # Serial suite: HTTP and LiveView processes share these Mox stubs. Mox.set_mox_global() @@ -14,34 +12,32 @@ defmodule BrowserHooks do cond do Map.get(context, :clipboard_browser) -> Map.put(context, :browser_context_opts, - timezone_id: "America/New_York", permissions: ["clipboard-read", "clipboard-write"] ) Map.get(context, :mobile) -> - Map.put(context, :browser_context_opts, - timezone_id: "America/New_York", - viewport: %{width: 320, height: 720} - ) + Map.put(context, :browser_context_opts, viewport: %{width: 320, height: 720}) # A short desktop window: wide enough for the sidebar, too short for it. Map.get(context, :short) -> - Map.put(context, :browser_context_opts, - timezone_id: "America/New_York", - viewport: %{width: 1280, height: 520} - ) + Map.put(context, :browser_context_opts, viewport: %{width: 1280, height: 520}) true -> context end - context = Map.merge(context, Map.new(BrowserCase.do_setup_all(context))) - # Cucumber's generated module atoms lack the Elixir prefix expected by - # the adapter's artifact filenames. Keep the original scenario name. - driver_context = Map.put(context, :module, __MODULE__) - context = Map.merge(context, Map.new(BrowserCase.do_setup(driver_context))) - answer_external_requests_locally(context.conn) - context + # Cucumber creates the ExUnit modules, so no `use Playwright.Test` can + # register the scenario: run its per-test setup here. + Playwright.Test.__setup__(context) + Huddlz.DataCase.setup_sandbox(context) + + conn = + Fluffy.PhoenixTest.start_session(:playwright, + browser_context: Map.get(context, :browser_context_opts, []) + ) + + answer_external_requests_locally(conn) + Map.put(context, :conn, conn) end @inter_url "https://fonts.gstatic.com/s/inter/v20/inter-latin.woff2" @@ -64,17 +60,18 @@ defmodule BrowserHooks do # answered locally: Inter from a fixture, so layouts measure as they do in # production, and anything else with an empty response. defp answer_external_requests_locally(conn) do - {:ok, _} = - PlaywrightEx.BrowserContext.route( - conn.context_id, + Fluffy.PhoenixTest.unwrap(conn, fn page -> + page + |> Playwright.Page.context() + |> Playwright.BrowserContext.route!( # Playwright resolves a bare "https://**" to "https://**/", which only # matches URLs ending in a slash. "https://*/**", fn route, request -> - {:ok, _} = PlaywrightEx.Route.fulfill(route, response(request.url)) - end, - timeout: 5_000 + Playwright.Route.fulfill!(route, response(Playwright.Request.url(request))) + end ) + end) end defp response("https://fonts.googleapis.com/" <> _), diff --git a/test/browser/test_helper.exs b/test/browser/test_helper.exs index 0d4389ec0..94292fd93 100644 --- a/test/browser/test_helper.exs +++ b/test/browser/test_helper.exs @@ -3,16 +3,3 @@ ExUnit.start(capture_log: true, max_cases: 1) Ecto.Adapters.SQL.Sandbox.mode(Huddlz.Repo, :manual) System.put_env("PLAYWRIGHT_BROWSERS_PATH", Path.expand("_build/browser/browsers")) -Application.put_env(:phoenix_test, :otp_app, :huddlz) -Application.put_env(:phoenix_test, :base_url, HuddlzWeb.Endpoint.url()) - -Application.put_env(:phoenix_test, :playwright, - browser_context_opts: [timezone_id: "America/New_York"], - browser_pools: [[id: :default_pool, size: 1]], - screenshot: true, - screenshot_dir: "_build/browser/screenshots", - trace: true, - trace_dir: "_build/browser/traces" -) - -{:ok, _} = PhoenixTest.Playwright.Supervisor.start_link() diff --git a/test/support/browser_helpers.ex b/test/support/browser_helpers.ex index 48e32ab30..250f46e28 100644 --- a/test/support/browser_helpers.ex +++ b/test/support/browser_helpers.ex @@ -1,28 +1,31 @@ defmodule Huddlz.Test.BrowserHelpers do @moduledoc false - import ExUnit.Assertions - import PhoenixTest.Playwright, only: [add_session_cookie: 3] + import Fluffy.PhoenixTest, only: [unwrap: 2] + import Phoenix.ConnTest, only: [build_conn: 0, dispatch: 4] def sign_in(conn, member) do {:ok, token, _claims} = AshAuthentication.Jwt.token_for_user(member, %{}, domain: Huddlz.Accounts) - add_session_cookie( - conn, - [value: %{user_token: token, live_socket_id: "users_sessions:#{Base.url_encode64(token)}"}], - HuddlzWeb.Endpoint.session_options() - ) + # One request through the endpoint signs the session cookie. + signed = + build_conn() + |> Plug.Test.init_test_session(%{ + user_token: token, + live_socket_id: "users_sessions:#{Base.url_encode64(token)}" + }) + |> dispatch(HuddlzWeb.Endpoint, :get, "/") + + cookies = + for {name, %{value: value}} <- signed.resp_cookies, + do: %{name: name, value: value, url: Fluffy.base_url(conn.session)} + + %{conn | session: Fluffy.add_cookies(conn.session, cookies)} end # Observe actual browser state with a bounded wait; never simulate app behavior. def assert_browser(conn, expression) do - assert {:ok, _} = - PlaywrightEx.Frame.wait_for_function(conn.frame_id, - expression: expression, - timeout: 5_000 - ) - - conn + unwrap(conn, &Playwright.Page.wait_for_function!(&1, expression, nil, timeout: 5_000)) end end From cdc756ef36f813e64380ad3900b61f66b8d5a1dd Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Mon, 23 Nov 2026 20:02:35 +0100 Subject: [PATCH 02/14] test(browser): drop connected waits after visit, route with Fluffy --- test/browser/README.md | 2 +- test/browser/steps/calendar_day_sheet_steps.exs | 1 - test/browser/steps/calendar_timezone_steps.exs | 1 - test/browser/steps/copy_huddl_steps.exs | 1 - test/browser/steps/cover_crop_steps.exs | 1 - .../browser/steps/cover_upload_progress_steps.exs | 1 - test/browser/steps/discover_navigation_steps.exs | 1 - test/browser/steps/group_cover_steps.exs | 1 - test/browser/steps/huddl_photos_steps.exs | 1 - test/browser/steps/keyboard_focus_steps.exs | 6 +++--- test/browser/steps/location_keyboard_steps.exs | 1 - test/browser/steps/member_menu_steps.exs | 1 - test/browser/steps/mobile_rsvp_steps.exs | 1 - .../steps/notification_preferences_steps.exs | 1 - test/browser/steps/organizer_keyboard_steps.exs | 1 - test/browser/steps/overview_cards_steps.exs | 1 - test/browser/steps/report_review_steps.exs | 3 +-- test/browser/steps/share_links_steps.exs | 2 +- test/browser/steps/sidebar_scroll_steps.exs | 1 - test/browser/steps/sign_in_return_steps.exs | 3 +-- test/browser/steps/social_schedule_steps.exs | 1 - test/browser/support/hooks.exs | 15 ++++----------- 22 files changed, 11 insertions(+), 36 deletions(-) diff --git a/test/browser/README.md b/test/browser/README.md index 607fe1ec1..5febbc916 100644 --- a/test/browser/README.md +++ b/test/browser/README.md @@ -58,4 +58,4 @@ Screenshots and traces are captured for every attempt under `_build/browser/test MIX_ENV=test mix playwright.cli show-trace _build/browser/test-results//trace.zip ``` -Assertions wait for observable browser state instead of sleeping. When an interaction needs LiveView to have connected after navigation, use `assert_has("body .phx-connected")` before sending input. JavaScript used in steps observes layout, image loading, or native form submissions; it does not implement the application behavior. The failed-cover scenario intentionally requests a missing image, so its expected 404 is not a suite-wide console failure. +Assertions wait for observable browser state instead of sleeping. `visit` waits for the LiveView to connect, so steps don't assert `.phx-connected` after it. JavaScript used in steps observes layout, image loading, or native form submissions; it does not implement the application behavior. The failed-cover scenario intentionally requests a missing image, so its expected 404 is not a suite-wide console failure. diff --git a/test/browser/steps/calendar_day_sheet_steps.exs b/test/browser/steps/calendar_day_sheet_steps.exs index e73ba6122..3e64acc84 100644 --- a/test/browser/steps/calendar_day_sheet_steps.exs +++ b/test/browser/steps/calendar_day_sheet_steps.exs @@ -36,7 +36,6 @@ defmodule BrowserCalendarDaySheetSteps do conn = context.conn |> visit("/calendar/month?month=#{month}") - |> assert_has(".phx-connected") |> assert_browser("innerWidth === 320 && !document.querySelector('#calendar-day-panel')") Map.put(context, :conn, conn) diff --git a/test/browser/steps/calendar_timezone_steps.exs b/test/browser/steps/calendar_timezone_steps.exs index aed3db66b..427a9f8e8 100644 --- a/test/browser/steps/calendar_timezone_steps.exs +++ b/test/browser/steps/calendar_timezone_steps.exs @@ -45,7 +45,6 @@ defmodule BrowserCalendarSteps do conn = context.conn |> visit("/calendar/month?month=2030-07") - |> assert_has(".phx-connected") |> assert_browser("Intl.DateTimeFormat().resolvedOptions().timeZone === 'America/New_York'") Map.put(context, :conn, conn) diff --git a/test/browser/steps/copy_huddl_steps.exs b/test/browser/steps/copy_huddl_steps.exs index 0b94782a7..ba1112979 100644 --- a/test/browser/steps/copy_huddl_steps.exs +++ b/test/browser/steps/copy_huddl_steps.exs @@ -14,7 +14,6 @@ defmodule BrowserCopyHuddlSteps do context.conn |> sign_in(owner) |> visit("/groups/#{group.slug}/huddlz/new?copy=#{huddl.id}") - |> assert_has(".phx-connected") |> assert_has("h2", text: "Copied from") Map.put(context, :conn, conn) diff --git a/test/browser/steps/cover_crop_steps.exs b/test/browser/steps/cover_crop_steps.exs index 82a1f6017..b538a84e5 100644 --- a/test/browser/steps/cover_crop_steps.exs +++ b/test/browser/steps/cover_crop_steps.exs @@ -22,7 +22,6 @@ defmodule BrowserCoverCropSteps do context.conn |> sign_in(owner) |> visit("/groups/new") - |> assert_has(".phx-connected") |> assert_has("#group-cover-upload[data-state=idle]") Map.put(context, :conn, conn) diff --git a/test/browser/steps/cover_upload_progress_steps.exs b/test/browser/steps/cover_upload_progress_steps.exs index 5b21d27cf..c32d0f548 100644 --- a/test/browser/steps/cover_upload_progress_steps.exs +++ b/test/browser/steps/cover_upload_progress_steps.exs @@ -25,7 +25,6 @@ defmodule BrowserCoverUploadSteps do context.conn |> sign_in(owner) |> visit("/groups/new") - |> assert_has(".phx-connected") |> assert_has("#group-cover-upload[data-state=idle]") # Remember where the slot and the name field sit before anything happens. diff --git a/test/browser/steps/discover_navigation_steps.exs b/test/browser/steps/discover_navigation_steps.exs index 12651334e..05496c970 100644 --- a/test/browser/steps/discover_navigation_steps.exs +++ b/test/browser/steps/discover_navigation_steps.exs @@ -30,7 +30,6 @@ defmodule BrowserDiscoverNavigationSteps do context.conn |> sign_in(member) |> visit("/agenda") - |> assert_has(".phx-connected") |> assert_has("h1", text: "Agenda") Map.merge(context, %{conn: conn, member: member}) diff --git a/test/browser/steps/group_cover_steps.exs b/test/browser/steps/group_cover_steps.exs index b08d2e0f7..fd479b8de 100644 --- a/test/browser/steps/group_cover_steps.exs +++ b/test/browser/steps/group_cover_steps.exs @@ -53,7 +53,6 @@ defmodule BrowserCoverSteps do conn = context.conn |> visit("/groups/#{context.group.slug}") - |> assert_has(".phx-connected") |> assert_has("h1", text: to_string(context.group.name)) Map.put(context, :conn, conn) diff --git a/test/browser/steps/huddl_photos_steps.exs b/test/browser/steps/huddl_photos_steps.exs index c33f7df54..268bd88d6 100644 --- a/test/browser/steps/huddl_photos_steps.exs +++ b/test/browser/steps/huddl_photos_steps.exs @@ -17,7 +17,6 @@ defmodule BrowserPhotoSteps do context.conn |> sign_in(owner) |> visit("/groups/#{group.slug}/huddlz/#{huddl.id}") - |> assert_has(".phx-connected") Map.merge(context, %{conn: conn, huddl: huddl}) end diff --git a/test/browser/steps/keyboard_focus_steps.exs b/test/browser/steps/keyboard_focus_steps.exs index 990951c12..88dc402a8 100644 --- a/test/browser/steps/keyboard_focus_steps.exs +++ b/test/browser/steps/keyboard_focus_steps.exs @@ -8,7 +8,7 @@ defmodule BrowserKeyboardFocusSteps do step "I am signed in and looking at my groups in a browser", context do member = generate(user(role: :user)) - conn = context.conn |> sign_in(member) |> visit("/groups") |> assert_has(".phx-connected") + conn = context.conn |> sign_in(member) |> visit("/groups") Map.put(context, :conn, conn) end @@ -165,7 +165,7 @@ defmodule BrowserKeyboardFocusSteps do defp open_page(context, "discover"), do: visit_signed_out(context, "/discover") defp visit_signed_out(context, path) do - Map.put(context, :conn, context.conn |> visit(path) |> assert_has(".phx-connected")) + Map.put(context, :conn, context.conn |> visit(path)) end defp open_form(context, "sign in"), @@ -267,7 +267,7 @@ defmodule BrowserKeyboardFocusSteps do end defp signed_in_form(context, member, path, form, submit \\ nil) do - conn = context.conn |> sign_in(member) |> visit(path) |> assert_has(".phx-connected") + conn = context.conn |> sign_in(member) |> visit(path) Map.merge(context, %{conn: conn, focus_form: form, focus_submit: submit}) end diff --git a/test/browser/steps/location_keyboard_steps.exs b/test/browser/steps/location_keyboard_steps.exs index 8ce9ba281..c7028090f 100644 --- a/test/browser/steps/location_keyboard_steps.exs +++ b/test/browser/steps/location_keyboard_steps.exs @@ -17,7 +17,6 @@ defmodule BrowserLocationKeyboardSteps do context.conn |> sign_in(member) |> visit("/profile") - |> assert_has(".phx-connected") |> assert_has("h1", text: "Profile") |> unwrap(fn page -> assert Playwright.Page.evaluate!(page, """ diff --git a/test/browser/steps/member_menu_steps.exs b/test/browser/steps/member_menu_steps.exs index a3e3e6fcc..8843a73a9 100644 --- a/test/browser/steps/member_menu_steps.exs +++ b/test/browser/steps/member_menu_steps.exs @@ -21,7 +21,6 @@ defmodule BrowserMemberMenuSteps do context.conn |> sign_in(owner) |> visit("/organize/#{group.slug}/members") - |> assert_has("body .phx-connected") |> assert_has("h1", text: "Members") Map.merge(context, %{conn: conn, owner: owner, member: member, group: group}) diff --git a/test/browser/steps/mobile_rsvp_steps.exs b/test/browser/steps/mobile_rsvp_steps.exs index 8769dd2ce..e6de8e207 100644 --- a/test/browser/steps/mobile_rsvp_steps.exs +++ b/test/browser/steps/mobile_rsvp_steps.exs @@ -26,7 +26,6 @@ defmodule BrowserMobileRsvpSteps do context.conn |> sign_in(member) |> visit("/groups/#{group.slug}/huddlz/#{huddl.id}") - |> assert_has(".phx-connected") Map.merge(context, %{conn: conn, huddl: huddl}) end diff --git a/test/browser/steps/notification_preferences_steps.exs b/test/browser/steps/notification_preferences_steps.exs index c3f3b2def..8dd9a2731 100644 --- a/test/browser/steps/notification_preferences_steps.exs +++ b/test/browser/steps/notification_preferences_steps.exs @@ -12,7 +12,6 @@ defmodule BrowserNotificationPreferencesSteps do context.conn |> sign_in(member) |> visit("/profile/notifications") - |> assert_has(".phx-connected") |> assert_has("h1", text: "Notifications") Map.merge(context, %{conn: conn, member: member}) diff --git a/test/browser/steps/organizer_keyboard_steps.exs b/test/browser/steps/organizer_keyboard_steps.exs index 0527f3d11..816ed7c59 100644 --- a/test/browser/steps/organizer_keyboard_steps.exs +++ b/test/browser/steps/organizer_keyboard_steps.exs @@ -13,7 +13,6 @@ defmodule BrowserOrganizerSteps do context.conn |> sign_in(owner) |> visit("/groups/#{group.slug}/huddlz/new") - |> assert_has(".phx-connected") Map.put(context, :conn, conn) end diff --git a/test/browser/steps/overview_cards_steps.exs b/test/browser/steps/overview_cards_steps.exs index 8bdb09476..09ee59ae9 100644 --- a/test/browser/steps/overview_cards_steps.exs +++ b/test/browser/steps/overview_cards_steps.exs @@ -36,7 +36,6 @@ defmodule BrowserOverviewCardsSteps do context.conn |> sign_in(owner) |> visit("/organize/#{group.slug}") - |> assert_has(".phx-connected") |> assert_has("#turnout-nudge", text: "Elixir office hours") Map.merge(context, %{conn: conn, group: group}) diff --git a/test/browser/steps/report_review_steps.exs b/test/browser/steps/report_review_steps.exs index 745e98496..6a7c2da00 100644 --- a/test/browser/steps/report_review_steps.exs +++ b/test/browser/steps/report_review_steps.exs @@ -21,7 +21,7 @@ defmodule BrowserReportReviewSteps do Accounts.suspend_user!(owner, "Repeated advertisements", actor: admin) conn = - context.conn |> sign_in(admin) |> visit("/admin/reports") |> assert_has(".phx-connected") + context.conn |> sign_in(admin) |> visit("/admin/reports") Map.merge(context, %{conn: conn, reported: owner}) end @@ -59,7 +59,6 @@ defmodule BrowserReportReviewSteps do conn = context.conn |> visit("/admin/users?scope=suspended") - |> assert_has(".phx-connected") |> click_button("Review") |> assert_has(".review-card a", text: "1 open report") diff --git a/test/browser/steps/share_links_steps.exs b/test/browser/steps/share_links_steps.exs index 142a4ce2e..6872edbc0 100644 --- a/test/browser/steps/share_links_steps.exs +++ b/test/browser/steps/share_links_steps.exs @@ -9,7 +9,7 @@ defmodule BrowserShareLinksSteps do owner = generate(user()) group = generate(group(is_public: true, owner_id: owner.id, actor: owner)) path = page_path(page, group, owner) - conn = context.conn |> visit(path) |> assert_has(".phx-connected") + conn = context.conn |> visit(path) # Retain real clipboard access for observation even when the app's API is unavailable. unwrap( diff --git a/test/browser/steps/sidebar_scroll_steps.exs b/test/browser/steps/sidebar_scroll_steps.exs index ae347aa91..8f3b26b53 100644 --- a/test/browser/steps/sidebar_scroll_steps.exs +++ b/test/browser/steps/sidebar_scroll_steps.exs @@ -21,7 +21,6 @@ defmodule BrowserSidebarScrollSteps do context.conn |> sign_in(member) |> visit("/agenda") - |> assert_has(".phx-connected") |> assert_has(".sb-org-row", text: "Overflow group 14") Map.merge(context, %{conn: conn, member: member}) diff --git a/test/browser/steps/sign_in_return_steps.exs b/test/browser/steps/sign_in_return_steps.exs index 93bc2d7d3..1996951f0 100644 --- a/test/browser/steps/sign_in_return_steps.exs +++ b/test/browser/steps/sign_in_return_steps.exs @@ -19,7 +19,7 @@ defmodule BrowserSignInReturnSteps do generate(huddl(group_id: group.id, creator_id: owner.id, actor: owner, is_private: false)) path = "/groups/#{group.slug}/huddlz/#{huddl.id}" - conn = context.conn |> visit(path) |> assert_has(".phx-connected") + conn = context.conn |> visit(path) Map.merge(context, %{ conn: conn, @@ -58,7 +58,6 @@ defmodule BrowserSignInReturnSteps do conn = conn |> visit("/reset/#{token}") - |> assert_has(".phx-connected") |> fill_in("New password", with: "ChangedPassword123!") |> fill_in("Confirm new password", with: "ChangedPassword123!") |> click_button("Reset password") diff --git a/test/browser/steps/social_schedule_steps.exs b/test/browser/steps/social_schedule_steps.exs index 5684f6832..bb529c695 100644 --- a/test/browser/steps/social_schedule_steps.exs +++ b/test/browser/steps/social_schedule_steps.exs @@ -11,7 +11,6 @@ defmodule BrowserSocialScheduleSteps do conn = conn |> visit("/organize/#{group.slug}/social") - |> assert_has("body .phx-connected") |> click_button("Edit") |> assert_has("#social-post-preview", text: "Morning-of post preview") # The sheet moves focus to its first control again two animation diff --git a/test/browser/support/hooks.exs b/test/browser/support/hooks.exs index 2427a8b4a..76e16ba16 100644 --- a/test/browser/support/hooks.exs +++ b/test/browser/support/hooks.exs @@ -60,17 +60,10 @@ defmodule BrowserHooks do # answered locally: Inter from a fixture, so layouts measure as they do in # production, and anything else with an empty response. defp answer_external_requests_locally(conn) do - Fluffy.PhoenixTest.unwrap(conn, fn page -> - page - |> Playwright.Page.context() - |> Playwright.BrowserContext.route!( - # Playwright resolves a bare "https://**" to "https://**/", which only - # matches URLs ending in a slash. - "https://*/**", - fn route, request -> - Playwright.Route.fulfill!(route, response(Playwright.Request.url(request))) - end - ) + # Playwright resolves a bare "https://**" to "https://**/", which only + # matches URLs ending in a slash. + Fluffy.Playwright.route(conn.session, "https://*/**", fn route, request -> + Playwright.Route.fulfill!(route, response(Playwright.Request.url(request))) end) end From 437d75a7ed53f464698802149fb0194e27f27d5b Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 09:17:29 +0100 Subject: [PATCH 03/14] test(browser): update Fluffy to 0.9.0-rc.6 and playwright_ex to 1.65.0-rc.5 --- mix.exs | 2 +- mix.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mix.exs b/mix.exs index dc198ff9d..cd94676c3 100644 --- a/mix.exs +++ b/mix.exs @@ -144,7 +144,7 @@ defmodule Huddlz.MixProject do {:mox, "~> 1.0", only: :test}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, {:phoenix_test, "~> 0.12", only: :test}, - {:fluffy, "~> 0.9.0-rc.5", only: :test}, + {:fluffy, "~> 0.9.0-rc.6", only: :test}, {:slugify, "~> 1.3"}, {:remote_ip, "~> 1.1"}, {:envious, "~> 1.0"} diff --git a/mix.lock b/mix.lock index 056d3aa04..b307b264c 100644 --- a/mix.lock +++ b/mix.lock @@ -47,7 +47,7 @@ "finch": {:hex, :finch, "0.25.0", "ce6203ff9464baf7d82e71b9568cf061ed640317e7e3449dac7601d220689d53", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.2.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9fd9a2c47a9033f4d70fad6e7d656948c08bc6652699de20e609a5917c0bb0a5"}, "fine": {:hex, :fine, "0.2.0", "71d9ff9fa69a4167cff1f6e9fd3350ab8e45d26b52f484c6d6514194b594df02", [:mix], [], "hexpm", "6f69a9e8dadbfd017b27f611b000362870683ae65f28aec904f36ec4c5058db5"}, "floki": {:hex, :floki, "0.38.5", "5786298f62ea266f9a8e88642753a8bc99925cd1ed7a7c8e420f6965ddbc7d1f", [:mix], [], "hexpm", "c8c5b04455f01b076cd489fee7dc26b49edf9851ef61146e743f4676114bf6b0"}, - "fluffy": {:hex, :fluffy, "0.9.0-rc.5", "d3d4846b5d8ffa8cb838c74c364abc25f059f6e2ff4d9c31595d97a1d7bb0af1", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:lazy_html, ">= 0.1.0 and < 1.0.0", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.24 and < 2.0.0-0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, "~> 4.7", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 1.2.10 and < 2.0.0-0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:playwright, "~> 1.65.0-rc.3", [hex: :playwright_ex, repo: "hexpm", optional: false]}], "hexpm", "658fb1e5c337680e303c0f8560f9a39898666720fe7b096cb118a984eaf14666"}, + "fluffy": {:hex, :fluffy, "0.9.0-rc.6", "13888b7971d50d5cb45a60aebd7d098a21b955d3591b230281bde00e0f9a1133", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:lazy_html, ">= 0.1.13 and < 1.0.0", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.10 and < 2.0.0-0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, ">= 4.6.6 and < 5.0.0-0", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 1.1.32 and < 2.0.0-0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:playwright, "~> 1.65.0-rc.5", [hex: :playwright_ex, repo: "hexpm", optional: false]}], "hexpm", "becf30d63bb18b319ee6ff32475634879aab6b7df9ec9e9c578733e8cebb6a49"}, "gettext": {:hex, :gettext, "1.0.2", "5457e1fd3f4abe47b0e13ff85086aabae760497a3497909b8473e0acee57673b", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "eab805501886802071ad290714515c8c4a17196ea76e5afc9d06ca85fb1bfeb3"}, "glob_ex": {:hex, :glob_ex, "0.1.12", "7b2d9369c20e2697efcfd185d13d6e84c94cd3bfd2730fbde613141c2e015c00", [:mix], [], "hexpm", "2e2fac83f113514434c7eaf267b4c38af2f91766f1cab2c5db7053b7fc1ee0bb"}, "hammer": {:hex, :hammer, "7.6.0", "6eb6239dc874d66cb289ee1816872f8c9366b8e21c6a1bac9120010a50c6db57", [:mix], [{:igniter, "~> 0.8", [hex: :igniter, repo: "hexpm", optional: true]}], "hexpm", "5777d22a2f96e53e489aa5a31aee73fe082da78464be52a688521772f96a934a"}, @@ -55,14 +55,14 @@ "hpax": {:hex, :hpax, "1.1.0", "782931867cc23217c68fb5f68fe1a11f5e7544c7fda82c8a7019a5df5a4a1cdf", [:mix], [], "hexpm", "0b8d0f05832f55571d65ac720f79bf8994138ffbb133209dc4685eae0ad456a8"}, "ical": {:hex, :ical, "3.2.2", "382bd28e9089443d578c62102c26d4da54b8a414efffcfa22ac8061fa1fcd5b5", [:mix], [{:mint, "~> 1.7", [hex: :mint, repo: "hexpm", optional: true]}, {:time_zone_info, "~> 0.7", [hex: :time_zone_info, repo: "hexpm", optional: true]}], "hexpm", "3ede50a859b2e5c12ce38166f8fe9639c164dc9a9f58e2b6ce33fa7f95343705"}, "idna": {:hex, :idna, "8.0.0", "bb8795a18aadce07dce6a3928c4fcae74ac66eaf95186b46ea11598bccc719f9", [:rebar3], [], "hexpm", "e0c5ce7846f14515af66142a55b8097d5f46d10df9235e781f168bef5622bcf9"}, - "igniter": {:hex, :igniter, "0.8.5", "f2561b74903e714074089f100d67ca7c65b7b8897335e42e1daefb4bee6f9997", [:mix], [{:ex_ast, "~> 0.16", [hex: :ex_ast, repo: "hexpm", optional: false]}, {:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4.5", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:phx_new, "~> 1.7", [hex: :phx_new, repo: "hexpm", optional: true]}, {:req, "~> 0.7", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "3593e74a12fb82dcdc86207c12890505cfd3f0f0e9e0db11446fbcd7cf7a089e"}, + "igniter": {:hex, :igniter, "0.8.6", "a8312174487977ba037a776ea0388f496b3f3f9f107229c563e34c5567b5857b", [:mix], [{:ex_ast, "~> 0.16", [hex: :ex_ast, repo: "hexpm", optional: false]}, {:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4.5", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:phx_new, "~> 1.7", [hex: :phx_new, repo: "hexpm", optional: true]}, {:req, "~> 0.7", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "70062876b02b22c94e4678e4aa8cd95d282f71731645d06f2de5de64584528f1"}, "image": {:hex, :image, "0.73.0", "dbad0cca91be8b1e86ce48281a4ac8bd2b740ee1869edba9ede249c5de72b406", [:mix], [{:color, "~> 0.13", [hex: :color, repo: "hexpm", optional: false]}, {:evision, "~> 0.1.33 or ~> 0.2", [hex: :evision, repo: "hexpm", optional: true]}, {:exla, "~> 0.12", [hex: :exla, repo: "hexpm", optional: true]}, {:kino, "~> 0.13", [hex: :kino, repo: "hexpm", optional: true]}, {:nx, "~> 0.12", [hex: :nx, repo: "hexpm", optional: true]}, {:nx_image, "~> 0.1", [hex: :nx_image, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.1 or ~> 3.2 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: true]}, {:req, "~> 0.4", [hex: :req, repo: "hexpm", optional: true]}, {:rustler, "> 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:scholar, "~> 0.3", [hex: :scholar, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: false]}, {:vix, "~> 0.33", [hex: :vix, repo: "hexpm", optional: false]}, {:xav, "~> 0.10", [hex: :xav, repo: "hexpm", optional: true]}], "hexpm", "8592f1109ad07d61dbaead5fff09fa7d7aee24ca4cd1dcd852f7509e51ae624a"}, "iterex": {:hex, :iterex, "0.1.2", "58f9b9b9a22a55cbfc7b5234a9c9c63eaac26d276b3db80936c0e1c60355a5a6", [:mix], [], "hexpm", "2e103b8bcc81757a9af121f6dc0df312c9a17220f302b1193ef720460d03029d"}, "jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"}, "joken": {:hex, :joken, "2.8.0", "7eb3529e6d0ab62c6f76068608a65b4b17392ffd1d0cdd610de177f51f6ed159", [:mix], [{:jose, "~> 1.11.12", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "a76cc8ae7cca4c8144c1ed335c3d9a229c84e69a20a750a4eba24a1d549a89f6"}, "jose": {:hex, :jose, "1.11.13", "94abcd8bf98eb9f007272918bd3f5ffb613e8d250567de233e6c2b2456319005", [:mix, :rebar3], [], "hexpm", "15d8bd0f01ab29d1771e8da1f60f9c98725b23a17f7312cdd40e8e2757bd98c7"}, "json_xema": {:hex, :json_xema, "0.6.5", "060459c9c9152650edb4427b1acbc61fa43a23bcea0301d200cafa76e0880f37", [:mix], [{:conv_case, "~> 0.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:xema, "~> 0.16", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "b8ffdbc2f67aa8b91b44e1ba0ab77eb5c0b0142116f8fbb804977fb939d470ef"}, - "lazy_html": {:hex, :lazy_html, "0.1.14", "d733120403d0e6cce25eae8cf03800b5be47f28c40d1fe44a2a0850d33f9f0a2", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.9", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.2.0", [hex: :fine, repo: "hexpm", optional: false]}], "hexpm", "99210889b0cc591398d006def761f2faef438d1ac77d045a527791733571dc0c"}, + "lazy_html": {:hex, :lazy_html, "0.1.15", "010ab90c554e637404ae7b00d8594465fbc52053077474c8ed45fbb0deb5a66d", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.9", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.2.0", [hex: :fine, repo: "hexpm", optional: false]}], "hexpm", "139b5a6ebb6a9181b2da660f7aeb47c12b1af48c79524a57ebf207552301df4a"}, "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"}, "mint": {:hex, :mint, "1.11.0", "a713551624815c0435237b93d90ea8b9b14254690c66f732d0ef8930f76ff1d9", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "c6279ba2d6aa3a383a1d4cfbe7b59f42e6efd400f58d8e2acfeac48a438693ab"}, "mix_test_watch": {:hex, :mix_test_watch, "1.4.0", "d88bcc4fbe3198871266e9d2f00cd8ae350938efbb11d3fa1da091586345adbb", [:mix], [{:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "2b4693e17c8ead2ef56d4f48a0329891e8c2d0d73752c0f09272a2b17dc38d1b"}, @@ -88,7 +88,7 @@ "phoenix_test": {:hex, :phoenix_test, "0.14.0", "3fef4f78a3438cc398a0884cc7370f9c9a0afdbd9d70b8bd362837cd61943ffe", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:lazy_html, "~> 0.1.7", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:mime, ">= 1.0.0", [hex: :mime, repo: "hexpm", optional: true]}, {:phoenix, ">= 1.7.10", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "0d090b0b6deb4193797f7bee8f19ecabdc4bb4000db51ccd140dded0b2d57be3"}, "phoenix_view": {:hex, :phoenix_view, "2.0.4", "b45c9d9cf15b3a1af5fb555c674b525391b6a1fe975f040fb4d913397b31abf4", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "4e992022ce14f31fe57335db27a28154afcc94e9983266835bb3040243eb620b"}, "picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"}, - "playwright": {:hex, :playwright_ex, "1.65.0-rc.4", "be9390181664ad361880c5da24771b0ea524add332c10cad1c9b0da9ed2e33ae", [:mix], [], "hexpm", "7505d4ba8260bc88c096f4a8c538d21639d7d71a7166f8d6e0afade506b569cc"}, + "playwright": {:hex, :playwright_ex, "1.65.0-rc.5", "55f43c8b0f2c18a698712450a0769c4f9f9ef564be8ce92dfba58fadf3dbb172", [:mix], [], "hexpm", "84687be548278c3d7056614b5d4ad269c94d877534a006cc64bb45ff06829aee"}, "plug": {:hex, :plug, "1.20.4", "8fca521b31eb586dbb91968dd9fa95be6b60fb40f9ca77b005361e06836aed75", [: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", "96ee42c0b8b35bcb14e3e65afb85abe9bb7745a8576e8c602802bbb01e5acf72"}, "plug_crypto": {:hex, :plug_crypto, "2.2.1", "bd1d0358a2e2f5ffb818217e64c394f9d24ed191d862b7fa1bcce264ace2b8ea", [:mix], [], "hexpm", "4417ccbd8f85e627321cd07d2ab9c4b621f1fd883b9905af241f9b4b780b94b6"}, "postgrex": {:hex, :postgrex, "0.23.0", "f106e1429559f0db8799c250279ee5fa16e364a39380cd9523e725df3625b235", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "f001ab3fd56f5ef2b8b3cd4a512005614fcaeccca068ddb29e57d338a7f104ec"}, From 67b0d2de81fc1476a5ddbb999e146f16259bfb62 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 09:23:14 +0100 Subject: [PATCH 04/14] test(browser): stop the sandbox owner after the browser contexts close --- test/browser/support/hooks.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/browser/support/hooks.exs b/test/browser/support/hooks.exs index 76e16ba16..c51f727a3 100644 --- a/test/browser/support/hooks.exs +++ b/test/browser/support/hooks.exs @@ -26,10 +26,13 @@ defmodule BrowserHooks do context end + # ExUnit runs `on_exit` callbacks in reverse: the sandbox owner, registered + # first, stops last, after the scenario's browser contexts have closed. + Huddlz.DataCase.setup_sandbox(context) + # Cucumber creates the ExUnit modules, so no `use Playwright.Test` can # register the scenario: run its per-test setup here. Playwright.Test.__setup__(context) - Huddlz.DataCase.setup_sandbox(context) conn = Fluffy.PhoenixTest.start_session(:playwright, From 5d461e4a6816e9808e96774a8f7c22647977312f Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 09:41:36 +0100 Subject: [PATCH 05/14] test(browser): write the steps on Fluffy's own API Steps act through Fluffy's strict locators, Keyboard and Mouse instead of the PhoenixTest facade and Playwright.Page calls with selectors, so a duplicated control fails the scenario again. --- test/browser/README.md | 2 +- test/browser/steps/appearance_menu_steps.exs | 78 ++--- .../steps/calendar_day_sheet_steps.exs | 124 ++++---- .../browser/steps/calendar_timezone_steps.exs | 36 ++- test/browser/steps/copy_huddl_steps.exs | 37 ++- test/browser/steps/cover_crop_steps.exs | 137 ++++---- .../steps/cover_upload_progress_steps.exs | 122 ++++---- .../steps/discover_navigation_steps.exs | 46 ++- .../steps/email_confirmation_steps.exs | 54 ++-- test/browser/steps/group_cover_steps.exs | 105 ++++--- test/browser/steps/huddl_photos_steps.exs | 296 +++++++++--------- test/browser/steps/keyboard_focus_steps.exs | 244 +++++++-------- .../browser/steps/location_keyboard_steps.exs | 93 +++--- test/browser/steps/member_menu_steps.exs | 91 +++--- .../browser/steps/mobile_navigation_steps.exs | 117 +++---- test/browser/steps/mobile_rsvp_steps.exs | 60 ++-- .../steps/notification_preferences_steps.exs | 65 ++-- .../steps/organizer_keyboard_steps.exs | 87 ++--- test/browser/steps/overview_cards_steps.exs | 56 ++-- test/browser/steps/profile_picture_steps.exs | 130 ++++---- test/browser/steps/report_review_steps.exs | 83 ++--- test/browser/steps/share_links_steps.exs | 83 +++-- test/browser/steps/sidebar_scroll_steps.exs | 183 ++++++----- test/browser/steps/sign_in_return_steps.exs | 67 ++-- test/browser/steps/social_schedule_steps.exs | 221 +++++++------ test/browser/support/hooks.exs | 15 +- test/support/browser_helpers.ex | 28 +- 27 files changed, 1308 insertions(+), 1352 deletions(-) diff --git a/test/browser/README.md b/test/browser/README.md index 5febbc916..c6de12da5 100644 --- a/test/browser/README.md +++ b/test/browser/README.md @@ -58,4 +58,4 @@ Screenshots and traces are captured for every attempt under `_build/browser/test MIX_ENV=test mix playwright.cli show-trace _build/browser/test-results//trace.zip ``` -Assertions wait for observable browser state instead of sleeping. `visit` waits for the LiveView to connect, so steps don't assert `.phx-connected` after it. JavaScript used in steps observes layout, image loading, or native form submissions; it does not implement the application behavior. The failed-cover scenario intentionally requests a missing image, so its expected 404 is not a suite-wide console failure. +Steps use Fluffy's own locators, actions and assertions. They are strict: a locator that matches more than one element fails the step instead of acting on the first. Assertions wait for observable browser state instead of sleeping. `visit` waits for the LiveView to connect, so steps don't assert `.phx-connected` after it. JavaScript used in steps observes layout, image loading, or native form submissions; it does not implement the application behavior. The failed-cover scenario intentionally requests a missing image, so its expected 404 is not a suite-wide console failure. diff --git a/test/browser/steps/appearance_menu_steps.exs b/test/browser/steps/appearance_menu_steps.exs index cbc9436ca..88bf7189c 100644 --- a/test/browser/steps/appearance_menu_steps.exs +++ b/test/browser/steps/appearance_menu_steps.exs @@ -1,67 +1,67 @@ defmodule BrowserAppearanceMenuSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions - import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator - @menu_open "document.querySelector('#theme-menu').matches(':popover-open')" + alias Fluffy.Playwright.Keyboard - step "I open the appearance menu with the keyboard", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "#theme-menu-trigger", "Enter")) - |> assert_browser(@menu_open) + step "I open the appearance menu with the keyboard", %{session: session} do + session + |> press(trigger(), "Enter") + |> assert(visible(open_menu())) - Map.put(context, :conn, conn) + :ok end - step "I pick {string} with the keyboard", %{args: [label]} = context do - conn = tab_to_option(context.conn, label) - Map.put(context, :conn, unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Enter"))) + step "I pick {string} with the keyboard", %{args: [label], session: session} do + session + |> tab_to_option(label) + |> Keyboard.press("Enter") + + :ok end - step "the page uses the dark appearance and the menu is closed", context do - conn = - assert_browser( - context.conn, - "document.documentElement.dataset.theme === 'dark' && !#{@menu_open}" - ) + step "the page uses the dark appearance and the menu is closed", %{session: session} do + session + |> assert(attribute(by_css("html"), "data-theme", "dark")) + |> refute(visible(open_menu())) - Map.put(context, :conn, conn) + :ok end - step "I press Escape", context do - Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Escape"))) + step "I press Escape", %{session: session} do + Keyboard.press(session, "Escape") + :ok end - step "the menu is closed and focus is back on its trigger", context do - conn = - context.conn - |> assert_browser("!#{@menu_open}") - |> assert_has("#theme-menu-trigger:focus") + step "the menu is closed and focus is back on its trigger", %{session: session} do + session + |> refute(visible(open_menu())) + |> assert(focused(trigger())) - Map.put(context, :conn, conn) + :ok end + defp trigger, do: by_role(:button, name: ~r/^Appearance: /) + defp open_menu, do: by_css("#theme-menu:popover-open") + # Tab from the trigger into the menu, one option at a time, until the # wanted one has focus. - defp tab_to_option(conn, label, tries \\ 4) + defp tab_to_option(session, label, tries \\ 4) - defp tab_to_option(_conn, label, 0), do: flunk("no appearance option labelled #{label}") + defp tab_to_option(_session, label, 0), do: flunk("no appearance option labelled #{label}") - defp tab_to_option(conn, label, tries) do - conn = unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Tab")) + defp tab_to_option(session, label, tries) do + session = Keyboard.press(session, "Tab") focused = - unwrap_and_return( - conn, - &Playwright.Page.evaluate!( - &1, - "document.activeElement.querySelector('.theme-option-label')?.textContent" - ) + Fluffy.Playwright.evaluate( + session, + "document.activeElement.querySelector('.theme-option-label')?.textContent" ) - if focused == label, do: conn, else: tab_to_option(conn, label, tries - 1) + if focused == label, do: session, else: tab_to_option(session, label, tries - 1) end end diff --git a/test/browser/steps/calendar_day_sheet_steps.exs b/test/browser/steps/calendar_day_sheet_steps.exs index 3e64acc84..579be7ef2 100644 --- a/test/browser/steps/calendar_day_sheet_steps.exs +++ b/test/browser/steps/calendar_day_sheet_steps.exs @@ -1,9 +1,11 @@ defmodule BrowserCalendarDaySheetSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest step "I am going to {string} on the 17th of next month", %{args: [title]} = context do attendee = generate(user(role: :user)) @@ -25,89 +27,89 @@ defmodule BrowserCalendarDaySheetSteps do ) Huddlz.Communities.rsvp_huddl!(huddl, actor: attendee) + sign_in(context.session, attendee) - Map.merge(context, %{conn: sign_in(context.conn, attendee), huddl: huddl, day: date}) + %{huddl: huddl, day: date} end - step "I have opened next month's calendar in a narrow browser", context do + step "I have opened next month's calendar in a narrow browser", %{session: session} = context do %Date{year: y, month: m} = context.day month = "#{y}-#{String.pad_leading(to_string(m), 2, "0")}" - conn = - context.conn - |> visit("/calendar/month?month=#{month}") - |> assert_browser("innerWidth === 320 && !document.querySelector('#calendar-day-panel')") + session + |> visit("/calendar/month?month=#{month}") + |> assert(count(day_panel(), 0)) - Map.put(context, :conn, conn) + assert %{width: 320} = Fluffy.Playwright.viewport_size(session) + :ok end - step "I tap the 17th", context do + step "I tap the 17th", %{session: session} = context do link = day_link(context.day) # Bring the day into the middle of the screen first, so there is a scroll # position to come back to. - conn = - assert_browser(context.conn, """ - (() => { - const link = document.querySelector('#{link}'); - if (!link) return false; - link.scrollIntoView({ block: 'center' }); - sessionStorage.setItem('calendar-scroll', String(Math.round(scrollY))); - return scrollY > 0; - })() - """) - - Map.put(context, :conn, click_link(conn, link, "17")) + session + |> assert_browser(""" + (() => { + const link = document.querySelector('#{link}'); + if (!link) return false; + link.scrollIntoView({ block: 'center' }); + sessionStorage.setItem('calendar-scroll', String(Math.round(scrollY))); + return scrollY > 0; + })() + """) + |> click(by_css(link)) + + :ok end step "the day sheet is docked to the bottom edge and lists {string}", - %{args: [title]} = context do - conn = - context.conn - |> assert_has("#calendar-day-panel .cal-agenda-title", text: title) - |> assert_browser(""" - (() => { - const sheet = document.querySelector('#calendar-day-panel'); - if (!sheet) return false; - const rect = sheet.getBoundingClientRect(); - return Math.abs(rect.bottom - innerHeight) < 1 && - rect.left === 0 && Math.abs(rect.right - innerWidth) < 1 && - rect.top > 0 && - document.documentElement.scrollWidth <= innerWidth; - })() - """) - - Map.put(context, :conn, conn) + %{args: [title], session: session} do + session + |> assert(visible(entry(title))) + |> assert_browser(""" + (() => { + const sheet = document.querySelector('#calendar-day-panel'); + if (!sheet) return false; + const rect = sheet.getBoundingClientRect(); + return Math.abs(rect.bottom - innerHeight) < 1 && + rect.left === 0 && Math.abs(rect.right - innerWidth) < 1 && + rect.top > 0 && + document.documentElement.scrollWidth <= innerWidth; + })() + """) + + :ok end - step "I open {string} from the sheet and go back", %{args: [title]} = context do - conn = - context.conn - |> click_link("#calendar-day-panel .cal-agenda-entry", title) - |> assert_has("h1", text: title) - |> assert_browser("(() => { history.back(); return true; })()") + step "I open {string} from the sheet and go back", %{args: [title], session: session} do + session + |> click(entry(title)) + |> assert(visible(by_role(:heading, level: 1, name: title))) + |> Fluffy.Playwright.go_back() - Map.put(context, :conn, conn) + :ok end - step "the calendar returns with the sheet open on the 17th where I left it", context do - conn = - context.conn - |> assert_has("#calendar-day-panel .cal-agenda-day-title", - text: Calendar.strftime(context.day, "%B %-d") - ) - |> assert_browser(""" - (() => { - const expected = Number(sessionStorage.getItem('calendar-scroll')); - return location.search.includes('day=#{Date.to_iso8601(context.day)}') && - document.querySelector('#month-calendar') && - Math.abs(scrollY - expected) < 2; - })() - """) - - Map.put(context, :conn, conn) + step "the calendar returns with the sheet open on the 17th where I left it", + %{session: session} = context do + day = Date.to_iso8601(context.day) + + session + |> assert( + text(by_role(day_panel(), :heading, level: 2), Calendar.strftime(context.day, "%B %-d")) + ) + |> assert(page_url(&(URI.decode_query(&1.query || "")["day"] == day))) + |> assert(visible(by_css("#month-calendar"))) + |> assert_browser("Math.abs(scrollY - Number(sessionStorage.getItem('calendar-scroll'))) < 2") + + :ok end + defp day_panel, do: by_css("#calendar-day-panel") + defp entry(title), do: by_role(day_panel(), :link, name: title) + defp day_of_next_month(day) do today = eastern_today() total = today.year * 12 + today.month diff --git a/test/browser/steps/calendar_timezone_steps.exs b/test/browser/steps/calendar_timezone_steps.exs index 427a9f8e8..ccefea74e 100644 --- a/test/browser/steps/calendar_timezone_steps.exs +++ b/test/browser/steps/calendar_timezone_steps.exs @@ -1,9 +1,11 @@ defmodule BrowserCalendarSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest step "I attend a Denver huddl late on July 15", context do attendee = generate(user(role: :user)) @@ -38,26 +40,30 @@ defmodule BrowserCalendarSteps do ) Huddlz.Communities.rsvp_huddl!(huddl, actor: attendee) - Map.merge(context, %{conn: sign_in(context.conn, attendee), huddl: huddl}) + sign_in(context.session, attendee) + %{huddl: huddl} end - step "I open Calendar in a New York browser", context do - conn = - context.conn - |> visit("/calendar/month?month=2030-07") - |> assert_browser("Intl.DateTimeFormat().resolvedOptions().timeZone === 'America/New_York'") + step "I open Calendar in a New York browser", %{session: session} do + session + |> visit("/calendar/month?month=2030-07") + |> assert_browser("Intl.DateTimeFormat().resolvedOptions().timeZone === 'America/New_York'") - Map.put(context, :conn, conn) + :ok end - step "the huddl appears on July 16 with its Denver local time", context do - context.conn - |> assert_has("#calendar-time-zone", text: "America/New_York") - |> assert_has( - "td[aria-label^='Tuesday, July 16, 2030'] #calendar-entry-#{context.huddl.id} .cal-pill-time", - text: "11:30 PM MDT" + step "the huddl appears on July 16 with its Denver local time", %{session: session} = context do + day = by_css("td[aria-label^='Tuesday, July 16, 2030']") + + session + |> assert(text(by_css("#calendar-time-zone"), "America/New_York")) + |> assert( + visible( + by_css(day, "#calendar-entry-#{context.huddl.id} .cal-pill-time") + |> filter(has_text: "11:30 PM MDT") + ) ) - context + :ok end end diff --git a/test/browser/steps/copy_huddl_steps.exs b/test/browser/steps/copy_huddl_steps.exs index ba1112979..4389a0aaf 100644 --- a/test/browser/steps/copy_huddl_steps.exs +++ b/test/browser/steps/copy_huddl_steps.exs @@ -1,38 +1,37 @@ defmodule BrowserCopyHuddlSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I opened a copied huddl on my phone", context do + step "I opened a copied huddl on my phone", %{session: session} do owner = generate(user(role: :user)) group = generate(group(owner_id: owner.id, is_public: true, actor: owner)) huddl = generate(huddl(group_id: group.id, actor: owner)) - conn = - context.conn - |> sign_in(owner) - |> visit("/groups/#{group.slug}/huddlz/new?copy=#{huddl.id}") - |> assert_has("h2", text: "Copied from") + session + |> sign_in(owner) + |> visit("/groups/#{group.slug}/huddlz/new?copy=#{huddl.id}") + |> assert(visible(by_role(:heading, level: 2, name: "Copied from"))) - Map.put(context, :conn, conn) + :ok end - step "I review the copied description", context do - unwrap( - context.conn, - &Playwright.Page.evaluate!( - &1, - "document.querySelector('#form_description').scrollIntoView({block: 'center'})" - ) + step "I review the copied description", %{session: session} do + Fluffy.Playwright.evaluate( + session, + by_label("Description", exact: true), + "field => field.scrollIntoView({block: 'center'})" ) - context + :ok end - step "I can reach Schedule huddl and Save as draft without scrolling", context do - assert_browser(context.conn, """ + step "I can reach Schedule huddl and Save as draft without scrolling", %{session: session} do + assert_browser(session, """ (() => ['publish-huddl', 'save-huddl-draft'].every(id => { const button = document.getElementById(id); const rect = button.getBoundingClientRect(); @@ -42,6 +41,6 @@ defmodule BrowserCopyHuddlSteps do }))() """) - context + :ok end end diff --git a/test/browser/steps/cover_crop_steps.exs b/test/browser/steps/cover_crop_steps.exs index b538a84e5..1c0e4e124 100644 --- a/test/browser/steps/cover_crop_steps.exs +++ b/test/browser/steps/cover_crop_steps.exs @@ -1,45 +1,43 @@ defmodule BrowserCoverCropSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest require Ash.Query - alias Playwright.Mouse - alias Playwright.Page + alias Fluffy.Playwright.Mouse - step "I am creating a group in a browser", context do + step "I am creating a group in a browser", %{session: session} do owner = generate(user(role: :user)) ExUnit.Callbacks.on_exit(fn -> File.rm_rf!("priv/static/uploads/group_images/pending") end) - conn = - context.conn - |> sign_in(owner) - |> visit("/groups/new") - |> assert_has("#group-cover-upload[data-state=idle]") + session + |> sign_in(owner) + |> visit("/groups/new") + |> assert(visible(by_css("#group-cover-upload[data-state=idle]"))) - Map.put(context, :conn, conn) + :ok end - step "I choose a tall picture for the cover", context do - unwrap( - context.conn, - &Page.set_input_files!(&1, "#group-cover-upload input[type=file]", [ - Path.expand("test/fixtures/tall_red_blue.png") - ]) + step "I choose a tall picture for the cover", %{session: session} do + set_input_files( + session, + by_label("Cover image", exact: true), + "test/fixtures/tall_red_blue.png" ) - context + :ok end - step "the crop sheet opens with the picture fit to the 16:9 window", context do - assert_browser(context.conn, """ + step "the crop sheet opens with the picture fit to the 16:9 window", %{session: session} do + assert_browser(session, """ (() => { const sheet = document.querySelector('#group-cover-upload-crop'); if (!sheet || !sheet.open) return false; @@ -53,11 +51,12 @@ defmodule BrowserCoverCropSteps do })() """) - context + :ok end - step "the crop sheet fills the screen with the window and Use photo in view", context do - assert_browser(context.conn, """ + step "the crop sheet fills the screen with the window and Use photo in view", + %{session: session} do + assert_browser(session, """ (() => { const sheet = document.querySelector('#group-cover-upload-crop'); if (!sheet || !sheet.open) return false; @@ -72,66 +71,52 @@ defmodule BrowserCoverCropSteps do })() """) - context + :ok end - step "I drag the picture up to keep its bottom and use the photo", context do - conn = context.conn + step "I drag the picture up to keep its bottom and use the photo", %{session: session} do + window = + Fluffy.Playwright.bounding_box(session, by_css("#group-cover-upload-crop .crop-window")) - %{"x" => x, "top" => top, "bottom" => bottom} = - unwrap_and_return( - conn, - &Page.evaluate!(&1, """ - (() => { - const win = document.querySelector('#group-cover-upload-crop .crop-window').getBoundingClientRect(); - return {x: win.left + win.width / 2, top: win.top + 4, bottom: win.bottom - 4}; - })() - """) - ) + x = window.x + window.width / 2 + top = window.y + 4 + bottom = window.y + window.height - 4 # Three drags from the bottom of the window to its top; the picture # stops at its own bottom edge, whatever it was dragged past. - conn = - conn - |> unwrap(fn page -> - mouse = Page.mouse(page) - - for _ <- 1..3 do - Mouse.move!(mouse, x, bottom) - Mouse.down!(mouse) - Mouse.move!(mouse, x, top, steps: 6) - Mouse.up!(mouse) - end - end) - |> assert_browser(""" - (() => { - const sheet = document.querySelector('#group-cover-upload-crop'); - const pic = sheet.querySelector('.crop-pic').getBoundingClientRect(); - const win = sheet.querySelector('.crop-window').getBoundingClientRect(); - return Math.abs(pic.bottom - win.bottom) < 1 && !sheet.querySelector('[data-crop-reset]').hidden; - })() - """) - |> click_button("Use photo") - - Map.put(context, :conn, conn) + for _ <- 1..3 do + session + |> Mouse.move(x, bottom) + |> Mouse.down() + |> Mouse.move(x, top, steps: 6) + |> Mouse.up() + end + + session + |> assert_browser(""" + (() => { + const sheet = document.querySelector('#group-cover-upload-crop'); + const pic = sheet.querySelector('.crop-pic').getBoundingClientRect(); + const win = sheet.querySelector('.crop-window').getBoundingClientRect(); + return Math.abs(pic.bottom - win.bottom) < 1; + })() + """) + |> assert(visible(by_role(:button, name: "Reset"))) + |> click(by_role(:button, name: "Use photo")) + + :ok end - step "the slot uploads a 16:9 cover showing only the bottom of my picture", context do - conn = - context.conn - |> refute_has("#group-cover-upload-crop[open]") - |> assert_has( - "#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']" - ) - - thumbnail_path = - unwrap_and_return( - conn, - &Page.evaluate!( - &1, - "document.querySelector('#group-cover-upload .cover-slot img').getAttribute('src')" - ) - ) + step "the slot uploads a 16:9 cover showing only the bottom of my picture", + %{session: session} do + cover = + by_css("#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']") + + session + |> refute(visible(by_css("#group-cover-upload-crop[open]"))) + |> assert(visible(cover)) + + thumbnail_path = get_attribute(session, cover, "src") image = Huddlz.Communities.GroupImage @@ -153,6 +138,6 @@ defmodule BrowserCoverCropSteps do assert r < 90 and b > 180, "expected blue at #{x},#{y}, got #{inspect({r, b})}" end - Map.put(context, :conn, conn) + :ok end end diff --git a/test/browser/steps/cover_upload_progress_steps.exs b/test/browser/steps/cover_upload_progress_steps.exs index c32d0f548..f16aa8897 100644 --- a/test/browser/steps/cover_upload_progress_steps.exs +++ b/test/browser/steps/cover_upload_progress_steps.exs @@ -1,13 +1,16 @@ defmodule BrowserCoverUploadSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest alias Huddlz.Storage.GroupImages - step "I am creating a group in a browser where preparing a cover takes a moment", context do + step "I am creating a group in a browser where preparing a cover takes a moment", + %{session: session} do owner = generate(user(role: :user)) # Preparing the cover normally takes a few hundred milliseconds; hold it @@ -21,14 +24,12 @@ defmodule BrowserCoverUploadSteps do File.rm_rf!("priv/static/uploads/group_images/pending") end) - conn = - context.conn - |> sign_in(owner) - |> visit("/groups/new") - |> assert_has("#group-cover-upload[data-state=idle]") - # Remember where the slot and the name field sit before anything happens. - assert_browser(conn, """ + session + |> sign_in(owner) + |> visit("/groups/new") + |> assert(visible(by_css("#group-cover-upload[data-state=idle]"))) + |> assert_browser(""" (() => { const slot = document.querySelector('#group-cover-upload .cover-slot').getBoundingClientRect(); const name = document.querySelector('#group-form input[name="form[name]"]').getBoundingClientRect(); @@ -37,74 +38,65 @@ defmodule BrowserCoverUploadSteps do })() """) - Map.put(context, :conn, conn) + :ok end - step "I choose a picture for the cover", context do - unwrap( - context.conn, - &Playwright.Page.set_input_files!(&1, "#group-cover-upload input[type=file]", [ - Path.expand("test/fixtures/test_image.jpg") - ]) - ) - + step "I choose a picture for the cover", %{session: session} do # The crop sheet opens first; the picture already fits, so use it as is. - conn = - context.conn - |> assert_has("#group-cover-upload-crop[open]") - |> click_button("Use photo") + session + |> set_input_files(by_label("Cover image", exact: true), "test/fixtures/test_image.jpg") + |> assert(visible(by_css("#group-cover-upload-crop[open]"))) + |> click(by_role(:button, name: "Use photo")) - Map.put(context, :conn, conn) + :ok end step "the slot shows my picture with the upload in progress and the form is still usable", - context do - conn = - assert_browser(context.conn, """ - (() => { - const root = document.querySelector('#group-cover-upload'); - if (!root || root.dataset.state !== 'uploading') return false; - const img = root.querySelector('.cover-slot img'); - const bar = root.querySelector('.cover-slot-bar'); - const slot = root.querySelector('.cover-slot').getBoundingClientRect(); - const name = document.querySelector('#group-form input[name="form[name]"]'); - const before = window.__coverBefore; - return img && img.src.startsWith('blob:') && img.complete && img.naturalWidth > 0 && - bar && bar.getBoundingClientRect().bottom <= slot.bottom + 1 && - Math.abs(slot.top - before.slot[0]) < 1 && Math.abs(slot.height - before.slot[1]) < 1 && - !name.disabled && !document.querySelector('#group-form [disabled]') && - Math.abs(name.getBoundingClientRect().top - before.name[0]) < 1; - })() - """) - + %{session: session} do + session + |> assert_browser(""" + (() => { + const root = document.querySelector('#group-cover-upload'); + if (!root || root.dataset.state !== 'uploading') return false; + const img = root.querySelector('.cover-slot img'); + const bar = root.querySelector('.cover-slot-bar'); + const slot = root.querySelector('.cover-slot').getBoundingClientRect(); + const name = document.querySelector('#group-form input[name="form[name]"]'); + const before = window.__coverBefore; + return img && img.src.startsWith('blob:') && img.complete && img.naturalWidth > 0 && + bar && bar.getBoundingClientRect().bottom <= slot.bottom + 1 && + Math.abs(slot.top - before.slot[0]) < 1 && Math.abs(slot.height - before.slot[1]) < 1 && + !name.disabled && !document.querySelector('#group-form [disabled]') && + Math.abs(name.getBoundingClientRect().top - before.name[0]) < 1; + })() + """) # Typing while the cover is prepared must work. - conn = - conn - |> fill_in("Group name", with: "Typed while uploading") - |> assert_has("#group-cover-upload[data-state=uploading]") + |> fill(by_label("Group name", exact: true), "Typed while uploading") + |> assert(visible(by_css("#group-cover-upload[data-state=uploading]"))) - Map.put(context, :conn, conn) + :ok end - step "the slot settles on the prepared cover without moving", context do - conn = - context.conn - |> assert_has( - "#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']" + step "the slot settles on the prepared cover without moving", %{session: session} do + session + |> assert( + visible( + by_css("#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']") ) - |> assert_browser(""" - (() => { - const root = document.querySelector('#group-cover-upload'); - const img = root.querySelector('.cover-slot img'); - const slot = root.querySelector('.cover-slot').getBoundingClientRect(); - const before = window.__coverBefore; - return img.complete && img.naturalWidth > 0 && - Math.abs(slot.top - before.slot[0]) < 1 && Math.abs(slot.height - before.slot[1]) < 1 && - !root.querySelector('.cover-slot-bar') && - document.querySelector('#group-form input[name="form[name]"]').value === 'Typed while uploading'; - })() - """) + ) + |> assert_browser(""" + (() => { + const root = document.querySelector('#group-cover-upload'); + const img = root.querySelector('.cover-slot img'); + const slot = root.querySelector('.cover-slot').getBoundingClientRect(); + const before = window.__coverBefore; + return img.complete && img.naturalWidth > 0 && + Math.abs(slot.top - before.slot[0]) < 1 && Math.abs(slot.height - before.slot[1]) < 1 && + !root.querySelector('.cover-slot-bar') && + document.querySelector('#group-form input[name="form[name]"]').value === 'Typed while uploading'; + })() + """) - Map.put(context, :conn, conn) + :ok end end diff --git a/test/browser/steps/discover_navigation_steps.exs b/test/browser/steps/discover_navigation_steps.exs index 05496c970..8b653137e 100644 --- a/test/browser/steps/discover_navigation_steps.exs +++ b/test/browser/steps/discover_navigation_steps.exs @@ -1,11 +1,13 @@ defmodule BrowserDiscoverNavigationSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "a public huddl titled {string} is upcoming", %{args: [title]} = context do + step "a public huddl titled {string} is upcoming", %{args: [title]} do host = generate(user(role: :user)) group = generate(group(is_public: true, owner_id: host.id, actor: host)) @@ -20,37 +22,33 @@ defmodule BrowserDiscoverNavigationSteps do ) ) - Map.put(context, :huddl, huddl) + %{huddl: huddl} end - step "I have opened my agenda in a browser", context do + step "I have opened my agenda in a browser", %{session: session} do member = generate(user(role: :user)) - conn = - context.conn - |> sign_in(member) - |> visit("/agenda") - |> assert_has("h1", text: "Agenda") + session + |> sign_in(member) + |> visit("/agenda") + |> assert(visible(by_role(:heading, level: 1, name: "Agenda"))) - Map.merge(context, %{conn: conn, member: member}) + %{member: member} end - step "I follow Discover in the sidebar", context do - unwrap(context.conn, &Playwright.Page.evaluate!(&1, "window.__huddlzPage = 'kept'")) - - conn = click_link(context.conn, ".sb-nav a", "Discover") - - Map.put(context, :conn, conn) + step "I follow Discover in the sidebar", %{session: session} do + Fluffy.Playwright.evaluate(session, "window.__huddlzPage = 'kept'") + click(session, by_role(by_css(".sb-nav"), :link, name: "Discover")) + :ok end - step "the discover results arrive without a page load", context do - conn = - context.conn - |> assert_has("h1", text: "Browse huddlz") - |> assert_has("h3.card-title", text: context.huddl.title) - |> refute_has(".grid-skeleton") - |> assert_browser("window.__huddlzPage === 'kept'") + step "the discover results arrive without a page load", %{session: session} = context do + session + |> assert(visible(by_role(:heading, level: 1, name: "Browse huddlz"))) + |> assert(visible(by_role(:heading, level: 3, name: context.huddl.title))) + |> assert(count(by_css(".grid-skeleton") |> filter(visible: true), 0)) + |> assert_browser("window.__huddlzPage === 'kept'") - Map.put(context, :conn, conn) + :ok end end diff --git a/test/browser/steps/email_confirmation_steps.exs b/test/browser/steps/email_confirmation_steps.exs index ea7ad885c..8effc2a59 100644 --- a/test/browser/steps/email_confirmation_steps.exs +++ b/test/browser/steps/email_confirmation_steps.exs @@ -1,32 +1,33 @@ defmodule BrowserEmailConfirmationSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest import Swoosh.TestAssertions - step "I have hidden the reminder for my unconfirmed address in a browser", context do + step "I have hidden the reminder for my unconfirmed address in a browser", %{session: session} do member = generate(user(confirmed_at: nil)) set_swoosh_global() - conn = - context.conn - |> sign_in(member) - |> visit("/agenda") - |> click_button("Hide until next time") - |> visit("/profile") + session + |> sign_in(member) + |> visit("/agenda") + |> click(by_role(:button, name: "Hide until next time")) + |> visit("/profile") - Map.merge(context, %{conn: conn, member: member}) + %{member: member} end - step "I request confirmation from my profile", context do - Map.put(context, :conn, click_button(context.conn, "Resend confirmation")) + step "I request confirmation from my profile", %{session: session} do + click(session, by_role(:button, name: "Resend confirmation")) + :ok end - step "a confirmation email is sent to my current address", context do - conn = assert_has(context.conn, "[role=alert]", text: "Confirmation sent to") + step "a confirmation email is sent to my current address", %{session: session} = context do + assert(session, visible(alert("Confirmation sent to"))) email = to_string(context.member.email) assert_email_sent(fn sent -> @@ -34,19 +35,20 @@ defmodule BrowserEmailConfirmationSteps do assert sent.subject == "Confirm your email address" end) - Map.put(context, :conn, conn) + :ok end - step "I can still save my display name", context do - conn = - context.conn - |> assert_has("body .phx-connected") - |> fill_in("Display name", with: "Confirmation Reviewer") - |> click_button("Save changes") - |> assert_has("[role=alert]", text: "Display name updated successfully") - |> visit("/profile") - |> assert_has("input", label: "Display name", value: "Confirmation Reviewer") - - Map.put(context, :conn, conn) + step "I can still save my display name", %{session: session} do + session + |> assert(visible(by_css("body .phx-connected") |> first())) + |> fill(by_label("Display name", exact: true), "Confirmation Reviewer") + |> click(by_role(:button, name: "Save changes")) + |> assert(visible(alert("Display name updated successfully"))) + |> visit("/profile") + |> assert(value(by_label("Display name", exact: true), "Confirmation Reviewer")) + + :ok end + + defp alert(text), do: by_role(:alert) |> filter(has_text: text) end diff --git a/test/browser/steps/group_cover_steps.exs b/test/browser/steps/group_cover_steps.exs index fd479b8de..739ee5418 100644 --- a/test/browser/steps/group_cover_steps.exs +++ b/test/browser/steps/group_cover_steps.exs @@ -1,14 +1,15 @@ defmodule BrowserCoverSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest alias Huddlz.Storage.Local - step "a group with long details and a {string} cover", %{args: [state]} = context do + step "a group with long details and a {string} cover", %{args: [state]} do owner = generate(user(role: :user)) group = @@ -46,25 +47,25 @@ defmodule BrowserCoverSteps do ) end - Map.merge(context, %{group: group, cover_state: state}) + %{group: group, cover_state: state} end - step "I open that group in the browser", context do - conn = - context.conn - |> visit("/groups/#{context.group.slug}") - |> assert_has("h1", text: to_string(context.group.name)) + step "I open that group in the browser", %{session: session} = context do + session + |> visit("/groups/#{context.group.slug}") + |> assert(visible(by_role(:heading, level: 1, name: to_string(context.group.name)))) - Map.put(context, :conn, conn) + :ok end - step "its cover has the expected image or visible fallback", context do - assert_cover(context.conn, context.cover_state) - context + step "its cover has the expected image or visible fallback", %{session: session} = context do + assert_cover(session, context.cover_state) + :ok end - step "its title and location fit without clipping or horizontal overflow", context do - assert_browser(context.conn, """ + step "its title and location fit without clipping or horizontal overflow", + %{session: session} do + assert_browser(session, """ (() => { const hero = document.querySelector('#group-detail-hero'); const bounds = hero.getBoundingClientRect(); @@ -79,11 +80,11 @@ defmodule BrowserCoverSteps do })() """) - context + :ok end - step "the mobile cover stays above the group details", context do - assert_browser(context.conn, """ + step "the mobile cover stays above the group details", %{session: session} do + assert_browser(session, """ (() => { const cover = document.querySelector('#group-detail-hero .group-cover').getBoundingClientRect(); const details = document.querySelector('#group-detail-hero .hero-content').getBoundingClientRect(); @@ -91,11 +92,11 @@ defmodule BrowserCoverSteps do })() """) - context + :ok end - step "the group sidebar aligns with the top of the cover", context do - assert_browser(context.conn, """ + step "the group sidebar aligns with the top of the cover", %{session: session} do + assert_browser(session, """ (() => { const cover = document.querySelector('#group-detail-hero .group-cover').getBoundingClientRect(); const sidebar = document.querySelector('.huddl-side').getBoundingClientRect(); @@ -103,43 +104,45 @@ defmodule BrowserCoverSteps do })() """) - context + :ok end - defp assert_cover(conn, "missing") do - conn - |> refute_has("#group-detail-hero .cover-image") + defp assert_cover(session, "missing") do + session + |> refute(visible(cover_image())) |> assert_fallback() end - defp assert_cover(conn, state) do - conn = assert_has(conn, "#group-detail-hero .cover-image") - - unwrap(conn, fn page -> - decoded = - Playwright.Page.evaluate!(page, """ - (async () => { - const element = document.querySelector('#group-detail-hero .cover-image'); - const url = getComputedStyle(element).backgroundImage.slice(5, -2); - const image = new Image(); - image.src = url; - try { await image.decode(); return image.naturalWidth > 0; } - catch { return false; } - })() - """) - - assert decoded == (state == "valid") - end) + defp assert_cover(session, state) do + assert(session, visible(cover_image())) + + decoded = + Fluffy.Playwright.evaluate(session, """ + (async () => { + const element = document.querySelector('#group-detail-hero .cover-image'); + const url = getComputedStyle(element).backgroundImage.slice(5, -2); + const image = new Image(); + image.src = url; + try { await image.decode(); return image.naturalWidth > 0; } + catch { return false; } + })() + """) + + assert decoded == (state == "valid") outcome = if state == "valid", do: "loaded", else: "failed" - conn = assert_has(conn, "#group-detail-hero .cover-image[data-cover-state='#{outcome}']") - refute_has(conn, "#group-detail-hero .cover-image.is-pending") - if state == "failed", do: assert_fallback(conn), else: assert_painted_cover(conn) + session + |> assert(attribute(cover_image(), "data-cover-state", outcome)) + |> refute(contain_class(cover_image(), "is-pending")) + + if state == "failed", do: assert_fallback(session), else: assert_painted_cover(session) end - defp assert_painted_cover(conn) do - assert_browser(conn, """ + defp cover_image, do: by_css("#group-detail-hero .cover-image") + + defp assert_painted_cover(session) do + assert_browser(session, """ (() => { const cover = document.querySelector('#group-detail-hero .group-cover'); const layer = cover.querySelector('.cover-image'); @@ -158,9 +161,9 @@ defmodule BrowserCoverSteps do """) end - defp assert_fallback(conn) do - conn - |> assert_has("#group-detail-hero .group-cover-signal") + defp assert_fallback(session) do + session + |> assert(visible(by_css("#group-detail-hero .group-cover-signal"))) |> assert_browser(""" (() => { const cover = document.querySelector('#group-detail-hero .group-cover'); diff --git a/test/browser/steps/huddl_photos_steps.exs b/test/browser/steps/huddl_photos_steps.exs index 268bd88d6..8628972e9 100644 --- a/test/browser/steps/huddl_photos_steps.exs +++ b/test/browser/steps/huddl_photos_steps.exs @@ -1,10 +1,16 @@ defmodule BrowserPhotoSteps do use Cucumber.StepDefinition + use Fluffy.Assert + + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I am viewing my completed huddl in the browser", context do + alias Fluffy.Event + alias Fluffy.Playwright.Keyboard + + step "I am viewing my completed huddl in the browser", %{session: session} do owner = generate(user(display_name: "Sam Rivera")) group = generate(group(owner_id: owner.id, actor: owner)) huddl = generate(past_huddl(group_id: group.id, creator_id: owner.id)) @@ -13,151 +19,138 @@ defmodule BrowserPhotoSteps do File.rm_rf!("priv/static/uploads/huddl_photos/#{huddl.id}") end) - conn = - context.conn - |> sign_in(owner) - |> visit("/groups/#{group.slug}/huddlz/#{huddl.id}") + session + |> sign_in(owner) + |> visit("/groups/#{group.slug}/huddlz/#{huddl.id}") - Map.merge(context, %{conn: conn, huddl: huddl}) + %{huddl: huddl} end - step "I select a valid photo and an oversized photo", context do + step "I select a valid photo and an oversized photo", %{session: session} = context do path = Path.join(System.tmp_dir!(), "oversized-#{context.huddl.id}.jpg") File.write!(path, :binary.copy(<<0>>, 6_000_000)) ExUnit.Callbacks.on_exit(fn -> File.rm(path) end) - unwrap( - context.conn, - &Playwright.Page.set_input_files!(&1, "#huddl-photo-upload-form input[type=file]", [ - Path.expand("test/fixtures/test_image.jpg"), - path - ]) - ) - - context + set_input_files(session, photo_input(), ["test/fixtures/test_image.jpg", path]) + :ok end - step "I can upload the valid photo and understand why the other was skipped", context do - conn = - context.conn - |> assert_has(".upload-error", text: "Each photo must be 5 MB or smaller.") - |> click_button("Upload photos") - |> assert_has(".photo-tile", count: 1) - |> assert_has("#flash-info", text: "Photos uploaded.") - - assert_browser( - conn, + step "I can upload the valid photo and understand why the other was skipped", + %{session: session} do + session + |> assert(visible(upload_error("Each photo must be 5 MB or smaller."))) + |> click(upload_button()) + |> assert(count(tiles(), 1)) + |> assert(visible(by_css("#flash-info") |> filter(has_text: "Photos uploaded."))) + |> assert_browser( "[...document.querySelectorAll('.photo-tile img')].every(i => i.complete && i.naturalWidth > 0)" ) - context + :ok end - step "I select a corrupt image and submit it", context do - unwrap( - context.conn, - &Playwright.Page.set_input_files!(&1, "#huddl-photo-upload-form input[type=file]", [ - Path.expand("test/fixtures/corrupt_image.jpg") - ]) - ) + step "I select a corrupt image and submit it", %{session: session} do + session + |> set_input_files(photo_input(), "test/fixtures/corrupt_image.jpg") + |> click(upload_button()) - Map.put(context, :conn, click_button(context.conn, "Upload photos")) + :ok end - step "I am told to choose a supported image instead of retrying it", context do - context.conn - |> assert_has(".upload-error", text: "corrupt_image.jpg: Choose a JPG, PNG, or WebP image.") - |> refute_has(".photo-tile") - |> refute_has("#flash-error", text: "Please try again.") + step "I am told to choose a supported image instead of retrying it", %{session: session} do + session + |> assert(visible(upload_error("corrupt_image.jpg: Choose a JPG, PNG, or WebP image."))) + |> assert(count(tiles(), 0)) + |> refute(visible(by_css("#flash-error") |> filter(has_text: "Please try again."))) - context + :ok end - step "I choose two photos using the keyboard upload control", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "#huddl-hero-group", "Tab")) - |> assert_has("#browse-photos:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Enter")) - - unwrap( - conn, - &Playwright.Page.set_input_files!(&1, "#huddl-photo-upload-form input[type=file]", [ - Path.expand("test/fixtures/test_image.jpg"), - Path.expand("priv/static/icon-512.png") - ]) - ) + step "I choose two photos using the keyboard upload control", %{session: session} do + session + |> press(by_css("#huddl-hero-group"), "Tab") + |> assert(focused(by_role(:button, name: "Browse photos"))) - Map.put(context, :conn, conn) - end + # Enter on the control opens the browser's file chooser. + chooser = wait_for(session, Event.file_chooser()) + Keyboard.press(session, "Enter") - step "the upload queue names each photo and its remove control", context do - context.conn - |> assert_has(".photo-upload-entry", text: "test_image.jpg") - |> assert_has("button[aria-label='Remove test_image.jpg']") - |> assert_has("button[aria-label='Remove icon-512.png']") + set_input_files(session, await(chooser), [ + "test/fixtures/test_image.jpg", + "priv/static/icon-512.png" + ]) - context + :ok end - step "I share the selected photos and open the first one", context do - conn = - context.conn - |> click_button("Upload photos") - |> assert_has(".photo-tile", count: 2) - |> refute_has(".photo-upload-entry") + step "the upload queue names each photo and its remove control", %{session: session} do + session + |> assert(visible(by_css(".photo-upload-entry") |> filter(has_text: "test_image.jpg"))) + |> assert(visible(by_role(:button, name: "Remove test_image.jpg", exact: true))) + |> assert(visible(by_role(:button, name: "Remove icon-512.png", exact: true))) - conn = - unwrap(conn, &Playwright.Page.press!(&1, ".photo-tile:first-child .photo-open", "Enter")) + :ok + end - Map.put(context, :conn, conn) + step "I share the selected photos and open the first one", %{session: session} do + session + |> click(upload_button()) + |> assert(count(tiles(), 2)) + |> assert(count(by_css(".photo-upload-entry"), 0)) + |> press(first_tile_button("View photo"), "Enter") + + :ok end - step "Tab and Shift+Tab stay inside the photo viewer", context do - conn = - context.conn - |> assert_has("#photo-lightbox button[aria-label='Previous photo']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#photo-lightbox button[aria-label='Next photo']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#photo-lightbox .lightbox-actions button:focus", text: "Close") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#photo-lightbox button[aria-label='close']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#photo-lightbox button[aria-label='Previous photo']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) - |> assert_has("#photo-lightbox button[aria-label='close']:focus") - - Map.put(context, :conn, conn) + step "Tab and Shift+Tab stay inside the photo viewer", %{session: session} do + lightbox = by_css("#photo-lightbox") + + session + |> assert(focused(by_role(lightbox, :button, name: "Previous photo"))) + |> Keyboard.press("Tab") + |> assert(focused(by_role(lightbox, :button, name: "Next photo"))) + |> Keyboard.press("Tab") + |> assert(focused(by_role(lightbox, :button, name: "Close", exact: true))) + |> Keyboard.press("Tab") + |> assert(focused(by_role(lightbox, :button, name: "close", exact: true))) + |> Keyboard.press("Tab") + |> assert(focused(by_role(lightbox, :button, name: "Previous photo"))) + |> Keyboard.press("Shift+Tab") + |> assert(focused(by_role(lightbox, :button, name: "close", exact: true))) + + :ok end - step "I can navigate with arrow keys and see the contributor and photo position", context do - conn = - context.conn - |> assert_has("#photo-lightbox [role='dialog']", text: "Sam Rivera") - |> assert_has("#photo-position", text: "1 of 2") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowRight")) - |> assert_has("#photo-position", text: "2 of 2") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowRight")) - |> assert_has("#photo-position", text: "1 of 2") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowLeft")) - |> assert_has("#photo-position", text: "2 of 2") - - Map.put(context, :conn, conn) + step "I can navigate with arrow keys and see the contributor and photo position", + %{session: session} do + position = by_css("#photo-position") + + session + |> assert( + visible(by_role(by_css("#photo-lightbox"), :dialog) |> filter(has_text: "Sam Rivera")) + ) + |> assert(text(position, "1 of 2")) + |> Keyboard.press("ArrowRight") + |> assert(text(position, "2 of 2")) + |> Keyboard.press("ArrowRight") + |> assert(text(position, "1 of 2")) + |> Keyboard.press("ArrowLeft") + |> assert(text(position, "2 of 2")) + + :ok end - step "Escape returns focus to the photo I opened", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Escape")) - |> assert_browser("!document.querySelector('#photo-lightbox')") - |> assert_has(".photo-tile:first-child .photo-open:focus") + step "Escape returns focus to the photo I opened", %{session: session} do + session + |> Keyboard.press("Escape") + |> assert(count(by_css("#photo-lightbox"), 0)) + |> assert(focused(first_tile_button("View photo"))) - Map.put(context, :conn, conn) + :ok end - step "the gallery fits above the huddl details on mobile", context do - assert_browser(context.conn, """ + step "the gallery fits above the huddl details on mobile", %{session: session} do + assert_browser(session, """ (() => { const gallery = document.querySelector('.huddl-photos').getBoundingClientRect(); const details = document.querySelector('.huddl-side').getBoundingClientRect(); @@ -165,48 +158,55 @@ defmodule BrowserPhotoSteps do })() """) - context + :ok end - step "I consider deleting the first photo", context do - Map.put( - context, - :conn, - unwrap( - context.conn, - &Playwright.Page.press!(&1, ".photo-tile:first-child .photo-delete", "Enter") - ) - ) + step "I consider deleting the first photo", %{session: session} do + press(session, first_tile_button("Delete photo"), "Enter") + :ok end - step "Tab and Shift+Tab stay inside the photo deletion dialog", context do - conn = - context.conn - |> assert_has("#cancel-delete-photo:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#confirm-delete-photo:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#delete-photo-modal button[aria-label='close']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#cancel-delete-photo:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) - |> assert_has("#delete-photo-modal button[aria-label='close']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#cancel-delete-photo:focus") - - Map.put(context, :conn, conn) + step "Tab and Shift+Tab stay inside the photo deletion dialog", %{session: session} do + modal = by_css("#delete-photo-modal") + keep = by_role(modal, :button, name: "Keep photo") + delete = by_role(modal, :button, name: "Delete photo") + close = by_role(modal, :button, name: "close", exact: true) + + session + |> assert(focused(keep)) + |> Keyboard.press("Tab") + |> assert(focused(delete)) + |> Keyboard.press("Tab") + |> assert(focused(close)) + |> Keyboard.press("Tab") + |> assert(focused(keep)) + |> Keyboard.press("Shift+Tab") + |> assert(focused(close)) + |> Keyboard.press("Tab") + |> assert(focused(keep)) + + :ok end - step "I see which photo will be deleted and can keep it", context do - conn = - context.conn - |> assert_has("#delete-photo-modal img") - |> assert_has("#delete-photo-modal [role='dialog']", text: "Sam Rivera") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Enter")) - |> refute_has("#delete-photo-modal [role='dialog']") - |> assert_has(".photo-tile", count: 2) - - assert_has(conn, ".photo-tile:first-child .photo-delete:focus") - context + step "I see which photo will be deleted and can keep it", %{session: session} do + dialog = by_role(by_css("#delete-photo-modal"), :dialog) + + session + |> assert(visible(by_css("#delete-photo-modal img"))) + |> assert(visible(dialog |> filter(has_text: "Sam Rivera"))) + |> Keyboard.press("Enter") + |> assert(count(dialog, 0)) + |> assert(count(tiles(), 2)) + |> assert(focused(first_tile_button("Delete photo"))) + + :ok end + + defp photo_input, do: by_label("Photos", exact: true) + defp upload_button, do: by_role(:button, name: "Upload photos") + defp tiles, do: by_css(".photo-tile") + defp upload_error(text), do: by_css(".upload-error") |> filter(has_text: text) + + defp first_tile_button(name), + do: by_role(tiles() |> first(), :button, name: name, exact: true) end diff --git a/test/browser/steps/keyboard_focus_steps.exs b/test/browser/steps/keyboard_focus_steps.exs index 88dc402a8..374a0f08b 100644 --- a/test/browser/steps/keyboard_focus_steps.exs +++ b/test/browser/steps/keyboard_focus_steps.exs @@ -1,62 +1,67 @@ defmodule BrowserKeyboardFocusSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers import Huddlz.Test.MoxHelpers - import Fluffy.PhoenixTest - step "I am signed in and looking at my groups in a browser", context do + alias Fluffy.Playwright.Keyboard + + step "I am signed in and looking at my groups in a browser", %{session: session} do member = generate(user(role: :user)) - conn = context.conn |> sign_in(member) |> visit("/groups") - Map.put(context, :conn, conn) + session |> sign_in(member) |> visit("/groups") + :ok end step "I open {string} in a browser", %{args: [page]} = context do open_page(context, page) end - step "I press Tab from the top of the page", context do - Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, "body", "Tab"))) + step "I press Tab from the top of the page", %{session: session} do + press(session, by_css("body"), "Tab") + :ok end - step "I press Tab", context do - Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Tab"))) + step "I press Tab", %{session: session} do + Keyboard.press(session, "Tab") + :ok end - step "I follow the skip link with Enter", context do - Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Enter"))) + step "I follow the skip link with Enter", %{session: session} do + Keyboard.press(session, "Enter") + :ok end - step "{string} has keyboard focus", %{args: [name]} = context do - assert_focused(context.conn, name) - context + step "{string} has keyboard focus", %{args: [name], session: session} do + assert_focused(session, name) + :ok end - step "{string} still has keyboard focus", %{args: [name]} = context do + step "{string} still has keyboard focus", %{args: [name], session: session} = context do # Let the save's reply land before looking. - context.conn |> assert_has(context.focus_form <> ":not(.phx-submit-loading)") - assert_focused(context.conn, name) - context - end + session + |> assert(visible(by_css(context.focus_form <> ":not(.phx-submit-loading)"))) + |> assert_focused(name) - step "keyboard focus is in the page content", context do - assert_browser(context.conn, "document.activeElement.id === 'main-content'") - context + :ok end - step "the main content landmark has keyboard focus", context do - assert_browser(context.conn, "document.activeElement.matches('main, [role=main]')") - context + step "keyboard focus is in the page content", %{session: session} do + assert(session, focused(by_css("#main-content"))) + :ok end - step "keyboard focus is still in the page content", context do - assert_browser(context.conn, """ - document.activeElement !== document.getElementById('main-content') && - document.getElementById('main-content').contains(document.activeElement) - """) + step "the main content landmark has keyboard focus", %{session: session} do + assert(session, focused(by_role(:main))) + :ok + end - context + step "keyboard focus is still in the page content", %{session: session} do + assert(session, attached(by_css("#main-content :focus"))) + :ok end step "I open the {string} form in a browser", %{args: [form]} = context do @@ -71,93 +76,85 @@ defmodule BrowserKeyboardFocusSteps do save_with(context, label, value) end - step "I register without accepting the terms", context do - conn = - context.conn - |> fill_in("Email", with: "focus-#{System.unique_integer([:positive])}@example.com") - |> fill_in("Display Name", with: "Keyboard Person") - |> fill_in("Password", with: "ValidPassword123!") - |> fill_in("Confirm Password", with: "ValidPassword123!") - |> unwrap(&Playwright.Page.press!(&1, "#registration-form button[type=submit]", "Enter")) + step "I register without accepting the terms", %{session: session} do + session + |> fill( + by_label("Email", exact: true), + "focus-#{System.unique_integer([:positive])}@example.com" + ) + |> fill(by_label("Display Name", exact: true), "Keyboard Person") + |> fill(by_label("Password", exact: true), "ValidPassword123!") + |> fill(by_label("Confirm Password", exact: true), "ValidPassword123!") + |> press(by_css("#registration-form button[type=submit]"), "Enter") - Map.put(context, :conn, conn) + :ok end step "I send an invitation twice to someone who already has an account", context do invitee = generate(user(role: :user)) email = to_string(invitee.email) - context = save_with(context, "Email", email) - assert_has(context.conn, "#flash-info", text: "Invitation sent to #{email}.") + save_with(context, "Email", email) + assert(context.session, visible(flash_info("Invitation sent to #{email}."))) save_with(context, "Email", email) end - step "I save the new group without a location", context do - conn = - context.conn - |> fill_in("Group name", with: "Keyboard Review Group") - |> fill_in("Description", with: "A group for reviewing keyboard access") - |> unwrap(&Playwright.Page.press!(&1, "#group-form button[type=submit]", "Enter")) + step "I save the new group without a location", %{session: session} do + session + |> fill(by_label("Group name", exact: true), "Keyboard Review Group") + |> fill(by_label("Description", exact: true), "A group for reviewing keyboard access") + |> press(by_css("#group-form button[type=submit]"), "Enter") - Map.put(context, :conn, conn) + :ok end - step "I clear the group location and save", context do - conn = - context.conn - |> within("#group-location", &click_button(&1, "Clear")) - |> assert_has("#group-location-input") - |> unwrap(&Playwright.Page.press!(&1, "#edit-group-form button[type=submit]", "Enter")) + step "I clear the group location and save", %{session: session} do + session + |> click(by_role(by_css("#group-location"), :button, name: "Clear")) + |> assert(visible(by_css("#group-location-input"))) + |> press(by_css("#edit-group-form button[type=submit]"), "Enter") - Map.put(context, :conn, conn) + :ok end - step "I finish with an opening line longer than 140 characters", context do - conn = - context.conn - |> fill_in("Opening line", with: String.duplicate("a", 141)) - |> unwrap(&Playwright.Page.press!(&1, "#schedule-form button[type=submit]", "Enter")) + step "I finish with an opening line longer than 140 characters", %{session: session} do + session + |> fill(by_label("Opening line", exact: true), String.duplicate("a", 141)) + |> press(by_css("#schedule-form button[type=submit]"), "Enter") - Map.put(context, :conn, conn) + :ok end - step "I try to record turnout without a count", context do - conn = - context.conn - |> click_button("#turnout-nudge button", "Add turnout") - |> unwrap(&Playwright.Page.press!(&1, "#turnout-form-nudge button[type=submit]", "Enter")) + step "I try to record turnout without a count", %{session: session} do + session + |> click(by_role(by_css("#turnout-nudge"), :button, name: "Add turnout")) + |> press(by_css("#turnout-form-nudge button[type=submit]"), "Enter") - Map.put(context, :conn, conn) + :ok end - step "the agreement has keyboard focus and describes what is wrong", context do - assert_focused(context.conn, Huddlz.Legal.acceptance_text()) - - assert_browser(context.conn, """ - (() => { - const field = document.activeElement; - return field.getAttribute('aria-invalid') === 'true' && - (field.getAttribute('aria-describedby') || '').split(/\\s+/).some(id => - document.getElementById(id)?.textContent.includes('accept')); - })() + step "the agreement has keyboard focus and describes what is wrong", %{session: session} do + session + |> assert_focused(Huddlz.Legal.acceptance_text()) + |> assert(attribute(focused_field(), "aria-invalid", "true")) + |> assert_browser(""" + (document.activeElement.getAttribute('aria-describedby') || '').split(/\\s+/).some(id => + document.getElementById(id)?.textContent.includes('accept')) """) - context + :ok end - step "{string} describes what is wrong with it", %{args: [name]} = context do - assert_browser(context.conn, """ - (() => { - const field = document.activeElement; - const described = (field.getAttribute('aria-describedby') || '').split(/\\s+/) - .map(id => document.getElementById(id)) - .filter(element => element?.getAttribute('role') === 'alert'); - return #{label_matches("field")} === #{Jason.encode!(name)} && - field.getAttribute('aria-invalid') === 'true' && - described.some(element => element.textContent.trim() !== ''); - })() + step "{string} describes what is wrong with it", %{args: [name], session: session} do + session + |> assert_focused(name) + |> assert(attribute(focused_field(), "aria-invalid", "true")) + |> assert_browser(""" + (document.activeElement.getAttribute('aria-describedby') || '').split(/\\s+/) + .map(id => document.getElementById(id)) + .some(element => element?.getAttribute('role') === 'alert' && element.textContent.trim() !== '') """) - context + :ok end defp open_page(context, "the home page"), do: visit_signed_out(context, "/") @@ -165,7 +162,8 @@ defmodule BrowserKeyboardFocusSteps do defp open_page(context, "discover"), do: visit_signed_out(context, "/discover") defp visit_signed_out(context, path) do - Map.put(context, :conn, context.conn |> visit(path)) + visit(context.session, path) + :ok end defp open_form(context, "sign in"), @@ -220,9 +218,9 @@ defmodule BrowserKeyboardFocusSteps do {owner, group} = owned_group() generate(group_location(group_id: group.id, actor: owner)) - context = signed_in_form(context, owner, "/groups/#{group.slug}/locations", nil) - conn = click_button(context.conn, "Edit") - Map.merge(context, %{conn: conn, focus_form: "#location-rename-form"}) + signed_in_form(context, owner, "/groups/#{group.slug}/locations", nil) + click(context.session, by_role(:button, name: "Edit", exact: true)) + %{focus_form: "#location-rename-form"} end defp open_form(context, "new address") do @@ -230,19 +228,20 @@ defmodule BrowserKeyboardFocusSteps do stub_places_autocomplete(%{"saint" => [:saint_augustine]}) stub_place_details(:defaults) - context = + form = signed_in_form(context, owner, "/groups/#{group.slug}/locations/new", "#new-location-form") - conn = - context.conn - |> fill_in("Search for an address", with: "saint") - |> assert_has("[role='option']") - |> unwrap(&Playwright.Page.press!(&1, "#modal-address-autocomplete-input", "ArrowDown")) - |> assert_has("#modal-address-autocomplete[data-has-highlight='true']") - |> unwrap(&Playwright.Page.press!(&1, "#modal-address-autocomplete-input", "Enter")) - |> assert_has("#new-location-form button[type=submit]:not([disabled])") + search = by_label("Search for an address", exact: true) + + context.session + |> fill(search, "saint") + |> assert(visible(by_role(:option) |> first())) + |> press(search, "ArrowDown") + |> assert(attribute(by_css("#modal-address-autocomplete"), "data-has-highlight", "true")) + |> press(search, "Enter") + |> assert(enabled(by_css("#new-location-form button[type=submit]"))) - Map.put(context, :conn, conn) + form end defp open_form(context, "invitation") do @@ -263,12 +262,13 @@ defmodule BrowserKeyboardFocusSteps do end defp signed_out_form(context, path, form) do - context |> visit_signed_out(path) |> Map.put(:focus_form, form) + visit(context.session, path) + %{focus_form: form} end defp signed_in_form(context, member, path, form, submit \\ nil) do - conn = context.conn |> sign_in(member) |> visit(path) - Map.merge(context, %{conn: conn, focus_form: form, focus_submit: submit}) + context.session |> sign_in(member) |> visit(path) + %{focus_form: form, focus_submit: submit} end # Clear or set the field, then press Enter on the form's submit button, @@ -276,29 +276,17 @@ defmodule BrowserKeyboardFocusSteps do defp save_with(context, label, value) do submit = context[:focus_submit] || context.focus_form <> " button[type=submit]" - conn = - context.conn - |> within(context.focus_form, &fill_in(&1, label, with: value)) - |> unwrap(&Playwright.Page.press!(&1, submit, "Enter")) + context.session + |> fill(by_label(by_css(context.focus_form), label, exact: true), value) + |> press(by_css(submit), "Enter") - Map.put(context, :conn, conn) + :ok end - defp assert_focused(conn, name) do - assert_browser(conn, """ - (() => { - const field = document.activeElement; - return #{label_matches("field")} === #{Jason.encode!(name)}; - })() - """) - end + defp flash_info(text), do: by_css("#flash-info") |> filter(has_text: text) - # The accessible name the step reads: a control's label, else its - # aria-label, else its own text. - defp label_matches(var) do - """ - ((#{var}.labels && #{var}.labels[0]?.textContent) || - #{var}.getAttribute('aria-label') || #{var}.textContent || '').replace(/\\s+/g, ' ').trim() - """ - end + defp focused_field, do: by_css(":focus") + + # A control's accessible name: its label, else its aria-label, else its own text. + defp assert_focused(session, name), do: assert(session, accessible_name(focused_field(), name)) end diff --git a/test/browser/steps/location_keyboard_steps.exs b/test/browser/steps/location_keyboard_steps.exs index c7028090f..34a61342b 100644 --- a/test/browser/steps/location_keyboard_steps.exs +++ b/test/browser/steps/location_keyboard_steps.exs @@ -1,83 +1,72 @@ defmodule BrowserLocationKeyboardSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers import Huddlz.Test.MoxHelpers - import Fluffy.PhoenixTest - step "I have opened my profile in a browser", context do + step "I have opened my profile in a browser", %{session: session} do member = generate(user(role: :user, display_name: "Browser Member")) stub_places_autocomplete(%{"saint" => [:saint_augustine]}) stub_place_details(:defaults) - conn = - context.conn - |> sign_in(member) - |> visit("/profile") - |> assert_has("h1", text: "Profile") - |> unwrap(fn page -> - assert Playwright.Page.evaluate!(page, """ - (() => { - window.observedSubmissions = 0; - document.addEventListener('submit', () => window.observedSubmissions++, true); - return true; - })() - """) - end) + session + |> sign_in(member) + |> visit("/profile") + |> assert(visible(by_role(:heading, level: 1, name: "Profile"))) + + assert Fluffy.Playwright.evaluate(session, """ + (() => { + window.observedSubmissions = 0; + document.addEventListener('submit', () => window.observedSubmissions++, true); + return true; + })() + """) ExUnit.Callbacks.on_exit(fn -> File.rm_rf!("priv/static/uploads/profile_pictures/#{member.id}") end) - Map.put(context, :conn, conn) + :ok end - step "I type {string} into my home location", %{args: [query]} = context do - conn = - context.conn - |> unwrap( - &(&1 - |> Playwright.Page.locator("#profile-location-input") - |> Playwright.Locator.press_sequentially!(query)) - ) - |> assert_has("[role='option']") - - Map.put(context, :conn, conn) + step "I type {string} into my home location", %{args: [query], session: session} do + session + |> Fluffy.Playwright.press_sequentially(home_location(), query) + |> assert(visible(by_role(:option) |> first())) + + :ok end - step "I highlight the first home location suggestion", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "#profile-location-input", "ArrowDown")) - |> assert_has("#profile-location[data-has-highlight='true']") + step "I highlight the first home location suggestion", %{session: session} do + session + |> press(home_location(), "ArrowDown") + |> assert(attribute(by_css("#profile-location"), "data-has-highlight", "true")) - Map.put(context, :conn, conn) + :ok end - step "I select the highlighted home location with Enter", context do - Map.put( - context, - :conn, - unwrap(context.conn, &Playwright.Page.press!(&1, "#profile-location-input", "Enter")) - ) + step "I select the highlighted home location with Enter", %{session: session} do + press(session, home_location(), "Enter") + :ok end - step "my home location is {string}", %{args: [location]} = context do - context.conn - |> assert_has("[data-testid='location-selected']", text: location) - |> assert_has("[role='alert']", text: "Home location updated") + step "my home location is {string}", %{args: [location], session: session} do + session + |> assert(visible(by_test_id("location-selected") |> filter(has_text: location))) + |> assert(visible(by_role(:alert) |> filter(has_text: "Home location updated"))) - context + :ok end - step "Enter did not submit a form", context do - unwrap(context.conn, fn page -> - assert Playwright.Page.evaluate!(page, "window.observedSubmissions") == 0 - end) - - context + step "Enter did not submit a form", %{session: session} do + assert Fluffy.Playwright.evaluate(session, "window.observedSubmissions") == 0 + :ok end + + defp home_location, do: by_label("Location", exact: true) end diff --git a/test/browser/steps/member_menu_steps.exs b/test/browser/steps/member_menu_steps.exs index 8843a73a9..1f1eb280e 100644 --- a/test/browser/steps/member_menu_steps.exs +++ b/test/browser/steps/member_menu_steps.exs @@ -1,12 +1,15 @@ defmodule BrowserMemberMenuSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I have opened a group's roster in a browser", context do + alias Fluffy.Playwright.Keyboard + + step "I have opened a group's roster in a browser", %{session: session} do owner = generate(user(role: :user, display_name: "Owner Olive")) member = generate(user(role: :user, display_name: "Member Maya")) @@ -17,70 +20,60 @@ defmodule BrowserMemberMenuSteps do members: [%{user: member, role: :member}] ) - conn = - context.conn - |> sign_in(owner) - |> visit("/organize/#{group.slug}/members") - |> assert_has("h1", text: "Members") + session + |> sign_in(owner) + |> visit("/organize/#{group.slug}/members") + |> assert(visible(by_role(:heading, level: 1, name: "Members"))) - Map.merge(context, %{conn: conn, owner: owner, member: member, group: group}) + %{owner: owner, member: member, group: group} end - step "I open the menu for {string} with the keyboard", %{args: [name]} = context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, trigger_for(name), "Enter")) - |> assert_browser(menu_open(name)) + step "I open the menu for {string} with the keyboard", %{args: [name], session: session} do + session + |> press(trigger(name), "Enter") + |> assert(visible(menu(name))) - Map.merge(context, %{conn: conn, menu_name: name}) + %{menu_name: name} end - step "I choose {string} with the keyboard", %{args: [label]} = context do - conn = tab_to_item(context.conn, label) - Map.put(context, :conn, unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Enter"))) - end + step "I choose {string} with the keyboard", %{args: [label], session: session} do + session + |> tab_to_item(label) + |> Keyboard.press("Enter") - step "the member menu is closed and focus is back on its button", context do - name = context.menu_name + :ok + end - conn = - context.conn - |> assert_browser("!#{menu_open(name)}") - |> assert_has("#{trigger_for(name)}:focus") + step "the member menu is closed and focus is back on its button", + %{session: session, menu_name: name} do + session + |> refute(visible(menu(name))) + |> assert(focused(trigger(name))) - Map.put(context, :conn, conn) + :ok end - step "the promotion confirmation is open and the menu is closed", context do - conn = - context.conn - |> assert_has("[role='dialog']", text: "Promote #{context.menu_name}?") - |> assert_browser("!#{menu_open(context.menu_name)}") + step "the promotion confirmation is open and the menu is closed", + %{session: session, menu_name: name} do + session + |> assert(visible(by_role(:dialog) |> filter(has_text: "Promote #{name}?"))) + |> refute(visible(menu(name))) - Map.put(context, :conn, conn) + :ok end - defp trigger_for(name), do: "button[aria-label='Manage #{name}']" - - defp menu_open(name), - do: - "document.querySelector(\"[role='menu'][aria-label='Manage #{name}']\").matches(':popover-open')" + defp trigger(name), do: by_role(:button, name: "Manage #{name}", exact: true) + defp menu(name), do: by_role(:menu, name: "Manage #{name}", exact: true) # Tab from the trigger into the menu, one item at a time, until the wanted # one has focus. - defp tab_to_item(conn, label, tries \\ 4) + defp tab_to_item(session, label, tries \\ 4) - defp tab_to_item(_conn, label, 0), do: flunk("no menu item labelled #{label}") - - defp tab_to_item(conn, label, tries) do - conn = unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Tab")) - - focused = - unwrap_and_return( - conn, - &Playwright.Page.evaluate!(&1, "document.activeElement.textContent.trim()") - ) + defp tab_to_item(_session, label, 0), do: flunk("no menu item labelled #{label}") - if focused == label, do: conn, else: tab_to_item(conn, label, tries - 1) + defp tab_to_item(session, label, tries) do + session = Keyboard.press(session, "Tab") + focused = Fluffy.Playwright.evaluate(session, "document.activeElement.textContent.trim()") + if focused == label, do: session, else: tab_to_item(session, label, tries - 1) end end diff --git a/test/browser/steps/mobile_navigation_steps.exs b/test/browser/steps/mobile_navigation_steps.exs index cf32675a2..c241b23cc 100644 --- a/test/browser/steps/mobile_navigation_steps.exs +++ b/test/browser/steps/mobile_navigation_steps.exs @@ -1,77 +1,84 @@ defmodule BrowserNavigationSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I open mobile navigation with the keyboard", context do - conn = - context.conn - |> assert_browser("document.querySelector('#mobile-navigation-drawer').inert") - |> unwrap(&Playwright.Page.press!(&1, "#mobile-nav-trigger", "Enter")) - |> assert_has("#mobile-nav-close:focus") + alias Fluffy.Playwright.Keyboard - Map.put(context, :conn, conn) + step "I open mobile navigation with the keyboard", %{session: session} do + session + |> assert(inert(drawer())) + |> press(trigger(), "Enter") + |> assert(focused(close_button())) + + :ok end - step "the drawer contains focus and the page behind it is inert", context do - conn = - context.conn - |> assert_has("[data-mobile-nav-background][inert]") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) - |> assert_has("#mobile-navigation-drawer a[aria-label='huddlz home']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) - |> assert_has("#sidebar-user:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#mobile-navigation-drawer a[aria-label='huddlz home']:focus") - |> assert_browser(""" - (() => { - const drawer = document.querySelector('#mobile-navigation-drawer').getBoundingClientRect(); - return drawer.left >= 0 && drawer.right <= innerWidth; - })() - """) + step "the drawer contains focus and the page behind it is inert", %{session: session} do + home = by_role(drawer(), :link, name: "huddlz home") + + session + |> assert(inert(background())) + |> Keyboard.press("Shift+Tab") + |> assert(focused(home)) + |> Keyboard.press("Shift+Tab") + |> assert(focused(by_role(:link, name: "View profile"))) + |> Keyboard.press("Tab") + |> assert(focused(home)) + |> assert_browser(""" + (() => { + const drawer = document.querySelector('#mobile-navigation-drawer').getBoundingClientRect(); + return drawer.left >= 0 && drawer.right <= innerWidth; + })() + """) - Map.put(context, :conn, conn) + :ok end - step "I close mobile navigation with Escape", context do - Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Escape"))) + step "I close mobile navigation with Escape", %{session: session} do + Keyboard.press(session, "Escape") + :ok end - step "focus returns to the navigation trigger and the page is usable", context do - conn = - context.conn - |> assert_has("#mobile-nav-trigger:focus[aria-expanded='false']") - |> assert_browser("document.querySelector('#mobile-navigation-drawer').inert") - |> refute_has("[data-mobile-nav-background][inert]") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_browser( - "document.querySelector('[data-mobile-nav-background]').contains(document.activeElement)" - ) + step "focus returns to the navigation trigger and the page is usable", %{session: session} do + session + |> assert(focused(trigger())) + |> assert(attribute(trigger(), "aria-expanded", "false")) + |> assert(inert(drawer())) + |> refute(inert(background())) + |> Keyboard.press("Tab") + |> assert(attached(by_css("[data-mobile-nav-background] :focus"))) - Map.put(context, :conn, conn) + :ok end - step "I reopen mobile navigation and visit Groups", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "#mobile-nav-trigger", "Enter")) - |> click_link("#mobile-navigation-drawer a", "Groups") + step "I reopen mobile navigation and visit Groups", %{session: session} do + session + |> press(trigger(), "Enter") + |> click(by_role(drawer(), :link, name: "Groups", exact: true)) - Map.put(context, :conn, conn) + :ok end - step "Groups loads with the drawer closed and can reopen navigation", context do - conn = - context.conn - |> assert_has("h1", text: "Groups") - |> assert_has(".phx-connected") - |> assert_browser("document.querySelector('#mobile-navigation-drawer').inert") - |> refute_has("[data-mobile-nav-background][inert]") - |> unwrap(&Playwright.Page.press!(&1, "#mobile-nav-trigger", "Enter")) - |> assert_has("#mobile-nav-close:focus") - |> assert_has("[data-mobile-nav-background][inert]") + step "Groups loads with the drawer closed and can reopen navigation", %{session: session} do + session + |> assert(visible(by_role(:heading, level: 1, name: "Groups"))) + |> assert(visible(by_css(".phx-connected") |> first())) + |> assert(inert(drawer())) + |> refute(inert(background())) + |> press(trigger(), "Enter") + |> assert(focused(close_button())) + |> assert(inert(background())) - Map.put(context, :conn, conn) + :ok end + + defp drawer, do: by_css("#mobile-navigation-drawer") + defp background, do: by_css("[data-mobile-nav-background]") + defp trigger, do: by_role(:button, name: "Open navigation", exact: true) + defp close_button, do: by_role(:button, name: "Close navigation", exact: true) + defp inert(locator), do: js_property(locator, "inert", true) end diff --git a/test/browser/steps/mobile_rsvp_steps.exs b/test/browser/steps/mobile_rsvp_steps.exs index e6de8e207..a95ddac68 100644 --- a/test/browser/steps/mobile_rsvp_steps.exs +++ b/test/browser/steps/mobile_rsvp_steps.exs @@ -1,11 +1,13 @@ defmodule BrowserMobileRsvpSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I am viewing an upcoming huddl in a narrow browser", context do + step "I am viewing an upcoming huddl in a narrow browser", %{session: session} do owner = generate(user(display_name: "Sam Rivera")) member = generate(user(display_name: "Ada Park")) group = generate(group(owner_id: owner.id, actor: owner)) @@ -22,16 +24,15 @@ defmodule BrowserMobileRsvpSteps do ) ) - conn = - context.conn - |> sign_in(member) - |> visit("/groups/#{group.slug}/huddlz/#{huddl.id}") + session + |> sign_in(member) + |> visit("/groups/#{group.slug}/huddlz/#{huddl.id}") - Map.merge(context, %{conn: conn, huddl: huddl}) + %{huddl: huddl} end - step "the RSVP button is docked to the bottom edge before I scroll", context do - assert_browser(context.conn, """ + step "the RSVP button is docked to the bottom edge before I scroll", %{session: session} do + assert_browser(session, """ (() => { const dock = document.querySelector('.rsvp-state[data-dock]'); if (!dock) return false; @@ -43,22 +44,22 @@ defmodule BrowserMobileRsvpSteps do })() """) - context + :ok end - step "I scroll to the end of the page", context do - assert_browser(context.conn, """ + step "I scroll to the end of the page", %{session: session} do + assert_browser(session, """ (() => { window.scrollTo(0, document.documentElement.scrollHeight); return window.scrollY > 0; })() """) - context + :ok end - step "the dock still sits on the bottom edge and covers nothing", context do - assert_browser(context.conn, """ + step "the dock still sits on the bottom edge and covers nothing", %{session: session} do + assert_browser(session, """ (() => { const dock = document.querySelector('.rsvp-state[data-dock]').getBoundingClientRect(); const last = document.querySelector('#huddl-group').getBoundingClientRect(); @@ -66,30 +67,29 @@ defmodule BrowserMobileRsvpSteps do })() """) - context + :ok end - step "I RSVP from the dock", context do - Map.put( - context, - :conn, - click_button(context.conn, ".rsvp-state[data-dock]", "RSVP to this huddl") - ) + step "I RSVP from the dock", %{session: session} do + click(session, by_role(dock(), :button, name: "RSVP to this huddl")) + :ok end - step "the dock shows I am attending and offers to cancel", context do - conn = - context.conn - |> assert_has(".rsvp-state[data-dock] .rsvp-banner.cyan", text: "You're attending") - |> assert_has(".rsvp-state[data-dock] button", text: "Cancel RSVP") - - assert_browser(conn, """ + step "the dock shows I am attending and offers to cancel", %{session: session} do + session + |> assert( + visible(by_css(dock(), ".rsvp-banner.cyan") |> filter(has_text: "You're attending")) + ) + |> assert(visible(by_role(dock(), :button, name: "Cancel RSVP"))) + |> assert_browser(""" (() => { const dock = document.querySelector('.rsvp-state[data-dock]').getBoundingClientRect(); return Math.abs(dock.bottom - innerHeight) < 1 && document.documentElement.scrollWidth <= innerWidth; })() """) - Map.put(context, :conn, conn) + :ok end + + defp dock, do: by_css(".rsvp-state[data-dock]") end diff --git a/test/browser/steps/notification_preferences_steps.exs b/test/browser/steps/notification_preferences_steps.exs index 8dd9a2731..a1fb299c1 100644 --- a/test/browser/steps/notification_preferences_steps.exs +++ b/test/browser/steps/notification_preferences_steps.exs @@ -1,63 +1,52 @@ defmodule BrowserNotificationPreferencesSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I have opened my notification preferences in a browser", context do + step "I have opened my notification preferences in a browser", %{session: session} do member = generate(user(role: :user)) - conn = - context.conn - |> sign_in(member) - |> visit("/profile/notifications") - |> assert_has("h1", text: "Notifications") + session + |> sign_in(member) + |> visit("/profile/notifications") + |> assert(visible(by_role(:heading, level: 1, name: "Notifications"))) - Map.merge(context, %{conn: conn, member: member}) + %{member: member} end step "my account has been removed underneath the page", context do Huddlz.Repo.delete!(context.member) - context + :ok end # A person flips a switch by clicking its row label; the checkbox itself # is visually hidden behind the track. - step "I flip {string} off", %{args: [label]} = context do - Map.put( - context, - :conn, - unwrap(context.conn, fn page -> - page - |> Playwright.Page.locator("label", has: Playwright.Page.get_by_text(page, label)) - |> Playwright.Locator.click!() - end) - ) + step "I flip {string} off", %{args: [label], session: session} do + click(session, by_css("label") |> filter(has: by_text(label))) + :ok end - step "the row says the change could not be saved", context do - Map.put(context, :conn, assert_has(context.conn, "[role=alert]", text: "Couldn't save")) + step "the row says the change could not be saved", %{session: session} do + assert(session, visible(by_role(:alert) |> filter(has_text: "Couldn't save"))) + :ok end - step "{string} is shown as on", %{args: [label]} = context do - conn = - assert_browser(context.conn, """ - (() => { - const label = [...document.querySelectorAll('label')] - .find((l) => l.textContent.trim() === #{Jason.encode!(label)}); - const input = label && document.getElementById(label.htmlFor); - return !!input && input.checked && input.getAttribute('aria-checked') === 'true'; - })() - """) - - Map.put(context, :conn, conn) - end + step "{string} is shown as on", %{args: [label], session: session} do + switch = by_role(:switch, name: label, exact: true) + + session + |> assert(checked(switch)) + |> assert(attribute(switch, "aria-checked", "true")) - step "the preference switch keeps keyboard focus", context do - conn = - assert_browser(context.conn, "document.activeElement?.getAttribute('role') === 'switch'") + :ok + end - Map.put(context, :conn, conn) + step "the preference switch keeps keyboard focus", %{session: session} do + assert(session, attached(by_css("[role='switch']:focus"))) + :ok end end diff --git a/test/browser/steps/organizer_keyboard_steps.exs b/test/browser/steps/organizer_keyboard_steps.exs index 816ed7c59..72ecb8740 100644 --- a/test/browser/steps/organizer_keyboard_steps.exs +++ b/test/browser/steps/organizer_keyboard_steps.exs @@ -1,66 +1,81 @@ defmodule BrowserOrganizerSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I have opened a new huddl as its group organizer", context do + alias Fluffy.Playwright.Keyboard + + step "I have opened a new huddl as its group organizer", %{session: session} do owner = generate(user(role: :user)) group = generate(group(owner_id: owner.id, is_public: true, actor: owner)) - conn = - context.conn - |> sign_in(owner) - |> visit("/groups/#{group.slug}/huddlz/new") + session + |> sign_in(owner) + |> visit("/groups/#{group.slug}/huddlz/new") - Map.put(context, :conn, conn) + :ok end - step "I tab into the format choices and choose virtual with an arrow key", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "textarea[name='form[description]']", "Tab")) - |> assert_has("#event-type-in_person:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "ArrowRight")) + step "I tab into the format choices and choose virtual with an arrow key", %{session: session} do + session + |> press(by_label("Description", exact: true), "Tab") + |> assert(focused(by_role(:radio, name: "In person", exact: true))) + |> Keyboard.press("ArrowRight") - Map.put(context, :conn, conn) + :ok end - step "the virtual choice has visible keyboard focus and reveals the online link", context do - context.conn - |> assert_has("#event-type-virtual:checked:focus-visible") - |> assert_has("input[name='form[virtual_link]']") + step "the virtual choice has visible keyboard focus and reveals the online link", + %{session: session} do + virtual = by_role(:radio, name: "Virtual", exact: true) + + session + |> assert(checked(virtual)) + |> assert(attached(focus_visible(virtual))) + |> assert(visible(by_label("Online link", exact: true))) |> assert_browser(""" getComputedStyle(document.querySelector('#event-type-virtual').closest('.event-type-option')).outlineStyle !== 'none' """) - context + :ok end - step "I enable recurrence and members only using Space", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "select[name='form[duration_minutes]']", "Tab")) - |> assert_has("input[name='form[is_recurring]']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Space")) - |> assert_has("input[name='form[is_recurring]']:checked:focus-visible[aria-checked='true']") - |> assert_has("select[name='form[frequency]']") - |> unwrap(&Playwright.Page.press!(&1, "input[name='form[max_attendees]']", "Tab")) - |> assert_has("input[name='form[is_private]']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Space")) + step "I enable recurrence and members only using Space", %{session: session} do + session + |> press(by_label("Duration", exact: true), "Tab") + |> assert(focused(recurring())) + |> Keyboard.press("Space") + |> assert(checked(recurring())) + |> assert(attached(focus_visible(recurring()))) + |> assert(attribute(recurring(), "aria-checked", "true")) + |> assert(visible(by_label("Frequency", exact: true))) + |> press(by_label("Max attendees", exact: true), "Tab") + |> assert(focused(members_only())) + |> Keyboard.press("Space") - Map.put(context, :conn, conn) + :ok end - step "both switches stay focused when changed and expose their checked state", context do - context.conn - |> assert_has("input[name='form[is_recurring]']:checked[aria-checked='true']") - |> assert_has("input[name='form[is_private]']:checked:focus-visible[aria-checked='true']") + step "both switches stay focused when changed and expose their checked state", + %{session: session} do + session + |> assert(checked(recurring())) + |> assert(attribute(recurring(), "aria-checked", "true")) + |> assert(checked(members_only())) + |> assert(attached(focus_visible(members_only()))) + |> assert(attribute(members_only(), "aria-checked", "true")) |> assert_browser(""" getComputedStyle(document.querySelector('input[name="form[is_private]"] + .track')).boxShadow !== 'none' """) - context + :ok end + + defp recurring, do: by_role(:switch, name: "Recurring huddl", exact: true) + defp members_only, do: by_role(:switch, name: "Members only", exact: true) + defp focus_visible(locator), do: and_(locator, by_css(":focus-visible")) end diff --git a/test/browser/steps/overview_cards_steps.exs b/test/browser/steps/overview_cards_steps.exs index 09ee59ae9..e5923847d 100644 --- a/test/browser/steps/overview_cards_steps.exs +++ b/test/browser/steps/overview_cards_steps.exs @@ -1,13 +1,16 @@ defmodule BrowserOverviewCardsSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest alias Huddlz.Communities.HuddlAttendee - step "I have opened the overview of a group with an uncounted past huddl", context do + step "I have opened the overview of a group with an uncounted past huddl", + %{session: session} do owner = generate(user(role: :user)) group = generate(group(owner_id: owner.id, is_public: true, actor: owner)) starts_at = DateTime.add(DateTime.utc_now(), -2, :day) @@ -32,42 +35,41 @@ defmodule BrowserOverviewCardsSteps do |> Ash.create!(authorize?: false) end - conn = - context.conn - |> sign_in(owner) - |> visit("/organize/#{group.slug}") - |> assert_has("#turnout-nudge", text: "Elixir office hours") + session + |> sign_in(owner) + |> visit("/organize/#{group.slug}") + |> assert(visible(by_css("#turnout-nudge") |> filter(has_text: "Elixir office hours"))) - Map.merge(context, %{conn: conn, group: group}) + %{group: group} end - step "the Show rate card is as tall as the RSVPs card", context do - Map.put(context, :conn, assert_same_height(context.conn)) + step "the Show rate card is as tall as the RSVPs card", %{session: session} do + assert_same_height(session) + :ok end - step "I record turnout from the overview reminder", context do - conn = - context.conn - |> click_button("#turnout-nudge button", "Add turnout") - |> fill_in("People in the room", with: 6) - |> click_button("Save turnout") - |> assert_has("#flash-info", text: "Turnout saved") + step "I record turnout from the overview reminder", %{session: session} do + session + |> click(by_role(by_css("#turnout-nudge"), :button, name: "Add turnout")) + |> fill(by_label("People in the room", exact: true), 6) + |> click(by_role(:button, name: "Save turnout")) + |> assert(visible(by_css("#flash-info") |> filter(has_text: "Turnout saved"))) - Map.put(context, :conn, conn) + :ok end - step "the Show rate card shows a rate and is still as tall as the RSVPs card", context do - conn = - context.conn - |> assert_has("#kpi-showrate .value", text: "50%", exact: true) - |> assert_has("#spark-showrate:not([data-empty])") - |> assert_same_height() + step "the Show rate card shows a rate and is still as tall as the RSVPs card", + %{session: session} do + session + |> assert(text(by_css("#kpi-showrate .value"), "50%")) + |> assert(visible(by_css("#spark-showrate:not([data-empty])"))) + |> assert_same_height() - Map.put(context, :conn, conn) + :ok end - defp assert_same_height(conn) do - assert_browser(conn, """ + defp assert_same_height(session) do + assert_browser(session, """ (() => { const rate = document.querySelector('#kpi-showrate').getBoundingClientRect(); const rsvps = document.querySelector('#kpi-rsvps').getBoundingClientRect(); diff --git a/test/browser/steps/profile_picture_steps.exs b/test/browser/steps/profile_picture_steps.exs index 6dfd25175..653ef739a 100644 --- a/test/browser/steps/profile_picture_steps.exs +++ b/test/browser/steps/profile_picture_steps.exs @@ -1,59 +1,54 @@ defmodule BrowserPictureSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - step "I upload a profile picture through the file input", context do - # The app intentionally hides its file input behind a visible upload label. - unwrap( - context.conn, - &Playwright.Page.set_input_files!(&1, "#avatar-form input[type=file]", [ - Path.expand("test/fixtures/test_image.jpg") - ]) - ) + alias Fluffy.Playwright.Keyboard + step "I upload a profile picture through the file input", %{session: session} do + # The app intentionally hides its file input behind a visible upload label. # The crop sheet opens first; the picture is used as it is. - conn = - context.conn - |> assert_has("#avatar-upload-crop[open]") - |> click_button("Use photo") - |> assert_has("#open-remove-avatar-dialog") + session + |> set_input_files(by_label("Upload a photo…", exact: true), "test/fixtures/test_image.jpg") + |> assert(visible(by_css("#avatar-upload-crop[open]"))) + |> click(by_role(:button, name: "Use photo")) + |> assert(visible(remove())) - Map.put(context, :conn, conn) + :ok end - step "my uploaded picture is decoded and displayed by the browser", context do - assert_browser(context.conn, """ + step "my uploaded picture is decoded and displayed by the browser", %{session: session} do + assert_browser(session, """ (() => { const image = document.querySelector('img.big-avatar'); return image && image.complete && image.naturalWidth > 0 && image.getBoundingClientRect().width > 0; })() """) - context + :ok end - step "I open the remove picture confirmation with the keyboard", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, "#open-remove-avatar-dialog", "Enter")) - |> assert_has("#cancel-remove-avatar:focus") + step "I open the remove picture confirmation with the keyboard", %{session: session} do + session + |> press(remove(), "Enter") + |> assert(focused(keep())) - Map.put(context, :conn, conn) + :ok end - step "I open the remove picture confirmation by clicking Remove", context do - conn = - context.conn - |> click_button("Remove") - |> assert_has("#remove-avatar-dialog [role='dialog']") + step "I open the remove picture confirmation by clicking Remove", %{session: session} do + session + |> click(remove()) + |> assert(visible(dialog())) - Map.put(context, :conn, conn) + :ok end - step "the Remove picture button is above the backdrop", context do - assert_browser(context.conn, """ + step "the Remove picture button is above the backdrop", %{session: session} do + assert_browser(session, """ (() => { const button = document.querySelector('#confirm-remove-avatar'); if (!button) return false; @@ -65,49 +60,56 @@ defmodule BrowserPictureSteps do })() """) - context + :ok end - step "I confirm picture removal by clicking Remove picture", context do - Map.put(context, :conn, click_button(context.conn, "Remove picture")) + step "I confirm picture removal by clicking Remove picture", %{session: session} do + click(session, confirm()) + :ok end - step "my profile picture is replaced by initials", context do - conn = - context.conn - |> refute_has("#remove-avatar-dialog [role='dialog']") - |> assert_has("[role='alert']", text: "Profile picture removed") - |> refute_has("img.big-avatar") - |> assert_has("main .big-avatar", text: "BM") + step "my profile picture is replaced by initials", %{session: session} do + session + |> assert(count(dialog(), 0)) + |> assert(visible(by_role(:alert) |> filter(has_text: "Profile picture removed"))) + |> assert(count(by_css("img.big-avatar"), 0)) + |> assert(visible(by_css("main .big-avatar") |> filter(has_text: "BM"))) - Map.put(context, :conn, conn) + :ok end - step "Tab stays inside the confirmation dialog", context do - conn = - context.conn - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#confirm-remove-avatar:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#remove-avatar-dialog button[aria-label='close']:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Tab")) - |> assert_has("#cancel-remove-avatar:focus") - |> unwrap(&Playwright.Page.press!(&1, ":focus", "Shift+Tab")) - |> assert_has("#remove-avatar-dialog button[aria-label='close']:focus") - - Map.put(context, :conn, conn) + step "Tab stays inside the confirmation dialog", %{session: session} do + close = by_role(by_css("#remove-avatar-dialog"), :button, name: "close", exact: true) + + session + |> Keyboard.press("Tab") + |> assert(focused(confirm())) + |> Keyboard.press("Tab") + |> assert(focused(close)) + |> Keyboard.press("Tab") + |> assert(focused(keep())) + |> Keyboard.press("Shift+Tab") + |> assert(focused(close)) + + :ok end - step "I dismiss the confirmation with Escape", context do - Map.put(context, :conn, unwrap(context.conn, &Playwright.Page.press!(&1, ":focus", "Escape"))) + step "I dismiss the confirmation with Escape", %{session: session} do + Keyboard.press(session, "Escape") + :ok end - step "focus returns to Remove and my picture remains", context do - context.conn - |> refute_has("#remove-avatar-dialog [role='dialog']") - |> assert_has("#open-remove-avatar-dialog:focus") - |> assert_has("img.big-avatar") + step "focus returns to Remove and my picture remains", %{session: session} do + session + |> assert(count(dialog(), 0)) + |> assert(focused(remove())) + |> assert(visible(by_css("img.big-avatar"))) - context + :ok end + + defp remove, do: by_role(:button, name: "Remove", exact: true) + defp dialog, do: by_role(by_css("#remove-avatar-dialog"), :dialog) + defp keep, do: by_role(dialog(), :button, name: "Keep picture") + defp confirm, do: by_role(dialog(), :button, name: "Remove picture") end diff --git a/test/browser/steps/report_review_steps.exs b/test/browser/steps/report_review_steps.exs index 6a7c2da00..9bcfb54ba 100644 --- a/test/browser/steps/report_review_steps.exs +++ b/test/browser/steps/report_review_steps.exs @@ -1,13 +1,15 @@ defmodule BrowserReportReviewSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest alias Huddlz.Accounts - step "I am reviewing a reported account in a browser", context do + step "I am reviewing a reported account in a browser", %{session: session} do owner = generate(user(display_name: "Sam Rivera")) reporter = generate(user(display_name: "Ada Park")) admin = generate(user(role: :admin, display_name: "Alex Admin")) @@ -20,68 +22,67 @@ defmodule BrowserReportReviewSteps do Accounts.suspend_user!(owner, "Repeated advertisements", actor: admin) - conn = - context.conn |> sign_in(admin) |> visit("/admin/reports") + session |> sign_in(admin) |> visit("/admin/reports") - Map.merge(context, %{conn: conn, reported: owner}) + %{reported: owner} end - step "the report review controls stay together", context do - check_controls(context.conn) - unwrap(context.conn, &screenshot(&1, "reports-#{size(context)}.png")) - context + step "the report review controls stay together", %{session: session} = context do + check_controls(session) + screenshot(session, "reports-#{size(context)}.png") + :ok end - step "I handle and reopen the report", context do - conn = - context.conn - |> click_button("Review") - |> click_button(".review-card button", "Mark handled") - |> click_link("Handled") - |> click_button("Review") - |> click_button("Reopen") + step "I handle and reopen the report", %{session: session} do + session + |> click(review()) + |> click(by_role(review_card(), :button, name: "Mark handled")) + |> click(by_role(:link, name: "Handled")) + |> click(review()) + |> click(by_role(:button, name: "Reopen")) - Map.put(context, :conn, conn) + :ok end - step "the reopened report is ready for review", context do - conn = - context.conn - |> assert_has(".review-card", text: "Repeated advertisements") - |> assert_has(".review-card button", text: "Mark handled") - |> refute_has("button", text: "Suspend account") - |> assert_browser("!new URL(window.location.href).searchParams.has('account_id')") + step "the reopened report is ready for review", %{session: session} do + session + |> assert(visible(review_card() |> filter(has_text: "Repeated advertisements"))) + |> assert(visible(by_role(review_card(), :button, name: "Mark handled"))) + |> assert(count(by_role(:button, name: "Suspend account"), 0)) + |> assert(page_url(&(not Map.has_key?(URI.decode_query(&1.query || ""), "account_id")))) - Map.put(context, :conn, conn) + :ok end - step "I review the suspended account in Users", context do - conn = - context.conn - |> visit("/admin/users?scope=suspended") - |> click_button("Review") - |> assert_has(".review-card a", text: "1 open report") + step "I review the suspended account in Users", %{session: session} do + session + |> visit("/admin/users?scope=suspended") + |> click(review()) + |> assert(visible(by_role(review_card(), :link, name: "1 open report"))) - Map.put(context, :conn, conn) + :ok end - step "the account review controls stay together", context do - check_controls(context.conn) - unwrap(context.conn, &screenshot(&1, "users-review-#{size(context)}.png")) - context + step "the account review controls stay together", %{session: session} = context do + check_controls(session) + screenshot(session, "users-review-#{size(context)}.png") + :ok end - defp screenshot(page, name), + defp review, do: by_role(:button, name: "Review", exact: true) + defp review_card, do: by_css(".review-card") + + defp screenshot(session, name), do: - Playwright.Page.screenshot!(page, + Fluffy.Playwright.screenshot(session, path: "_build/browser/screenshots/#{name}", full_page: true ) defp size(context), do: if(Map.get(context, :mobile), do: "mobile", else: "desktop") - defp check_controls(conn) do - assert_browser(conn, """ + defp check_controls(session) do + assert_browser(session, """ (() => { const row = document.querySelector('.member-row'); const review = row.querySelector('button[phx-click="review"]').getBoundingClientRect(); diff --git a/test/browser/steps/share_links_steps.exs b/test/browser/steps/share_links_steps.exs index 6872edbc0..bc3f479a0 100644 --- a/test/browser/steps/share_links_steps.exs +++ b/test/browser/steps/share_links_steps.exs @@ -1,75 +1,70 @@ defmodule BrowserShareLinksSteps do use Cucumber.StepDefinition + use Fluffy.Assert - import ExUnit.Assertions + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator - import Fluffy.PhoenixTest - step "I am viewing a public {string} to share", %{args: [page]} = context do + step "I am viewing a public {string} to share", %{args: [page], session: session} do owner = generate(user()) group = generate(group(is_public: true, owner_id: owner.id, actor: owner)) path = page_path(page, group, owner) - conn = context.conn |> visit(path) + visit(session, path) # Retain real clipboard access for observation even when the app's API is unavailable. - unwrap( - conn, - &Playwright.Page.evaluate!(&1, """ - window.readClipboard = navigator.clipboard.readText.bind(navigator.clipboard); - navigator.clipboard.writeText('previous clipboard contents'); - """) - ) - - Map.merge(context, %{conn: conn, share_url: HuddlzWeb.Endpoint.url() <> path}) - end - - step "direct clipboard access is {string}", %{args: [availability]} = context do - unwrap(context.conn, &Playwright.Page.evaluate!(&1, clipboard_availability(availability))) + Fluffy.Playwright.evaluate(session, """ + window.readClipboard = navigator.clipboard.readText.bind(navigator.clipboard); + navigator.clipboard.writeText('previous clipboard contents'); + """) - context + %{share_url: HuddlzWeb.Endpoint.url() <> path} end - step "I copy the address from the Share section", context do - refute_has(context.conn, "[role='dialog']") - Map.put(context, :conn, click_button(context.conn, "#share-actions button", "Copy link")) + step "direct clipboard access is {string}", %{args: [availability], session: session} do + Fluffy.Playwright.evaluate(session, clipboard_availability(availability)) + :ok end - step "my clipboard contains the page's address", context do - copied = - unwrap_and_return(context.conn, &Playwright.Page.evaluate!(&1, "window.readClipboard()")) + step "I copy the address from the Share section", %{session: session} do + session + |> assert(count(by_role(:dialog), 0)) + |> click(by_role(share_actions(), :button, name: "Copy link")) - assert copied == context.share_url + :ok + end - context + step "my clipboard contains the page's address", %{session: session} = context do + assert Fluffy.Playwright.evaluate(session, "window.readClipboard()") == context.share_url + :ok end - step "the Share section confirms the address was copied", context do - conn = - context.conn - |> assert_has("#share-actions", text: "Copied!") - |> assert_has("#share-actions button:focus", text: "Copied!") + step "the Share section confirms the address was copied", %{session: session} do + session + |> assert(visible(share_actions() |> filter(has_text: "Copied!"))) + |> assert(focused(by_role(share_actions(), :button, name: "Copied!"))) - Map.put(context, :conn, conn) + :ok end - step "I copy the address from the QR code dialog", context do - conn = - context.conn - |> click_button("#share-actions button", "QR code") - |> click_button("[role='dialog'] button", "Copy link") + step "I copy the address from the QR code dialog", %{session: session} do + session + |> click(by_role(share_actions(), :button, name: "QR code")) + |> click(by_role(by_role(:dialog), :button, name: "Copy link")) - Map.put(context, :conn, conn) + :ok end - step "the QR code dialog confirms the address was copied", context do - conn = - context.conn - |> assert_has("[role='dialog']", text: "Copied!") - |> assert_has("[role='dialog'] button:focus", text: "Copied!") + step "the QR code dialog confirms the address was copied", %{session: session} do + session + |> assert(visible(by_role(:dialog) |> filter(has_text: "Copied!"))) + |> assert(focused(by_role(by_role(:dialog), :button, name: "Copied!"))) - Map.put(context, :conn, conn) + :ok end + defp share_actions, do: by_css("#share-actions") + defp page_path("group", group, _owner), do: "/groups/#{group.slug}" defp page_path("huddl", group, owner) do diff --git a/test/browser/steps/sidebar_scroll_steps.exs b/test/browser/steps/sidebar_scroll_steps.exs index 8f3b26b53..5d5599a4b 100644 --- a/test/browser/steps/sidebar_scroll_steps.exs +++ b/test/browser/steps/sidebar_scroll_steps.exs @@ -1,14 +1,19 @@ defmodule BrowserSidebarScrollSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest + + alias Fluffy.Playwright.Keyboard + alias Fluffy.Playwright.Mouse @sidebar "document.querySelector('#mobile-navigation-drawer')" step "I have opened my agenda in a browser with enough groups to overflow the sidebar", - context do + %{session: session} do member = generate(user(role: :user)) for n <- 1..14 do @@ -17,132 +22,120 @@ defmodule BrowserSidebarScrollSteps do ) end - conn = - context.conn - |> sign_in(member) - |> visit("/agenda") - |> assert_has(".sb-org-row", text: "Overflow group 14") + session + |> sign_in(member) + |> visit("/agenda") + |> assert(visible(by_css(".sb-org-row") |> filter(has_text: "Overflow group 14"))) - Map.merge(context, %{conn: conn, member: member}) + %{member: member} end - step "the sidebar is one scroll region", context do - conn = - assert_browser(context.conn, """ - (() => { - const sidebar = #{@sidebar}; - const nav = sidebar.querySelector('.sb-nav'); - const scrolls = (el) => ['auto', 'scroll'].includes(getComputedStyle(el).overflowY); - return sidebar.scrollHeight > sidebar.clientHeight + 40 && scrolls(sidebar) && !scrolls(nav); - })() - """) - - Map.put(context, :conn, conn) + step "the sidebar is one scroll region", %{session: session} do + assert_browser(session, """ + (() => { + const sidebar = #{@sidebar}; + const nav = sidebar.querySelector('.sb-nav'); + const scrolls = (el) => ['auto', 'scroll'].includes(getComputedStyle(el).overflowY); + return sidebar.scrollHeight > sidebar.clientHeight + 40 && scrolls(sidebar) && !scrolls(nav); + })() + """) + + :ok end - step "the brand and account rows keep their height", context do - conn = - assert_browser(context.conn, """ - (() => { - const brand = document.querySelector('#mobile-navigation-drawer .sidebar-brand').getBoundingClientRect().height; - const user = document.querySelector('#sidebar-user').getBoundingClientRect().height; - return Math.round(brand) === 64 && user >= 60; - })() - """) + step "the brand and account rows keep their height", %{session: session} do + assert_browser(session, """ + (() => { + const brand = document.querySelector('#mobile-navigation-drawer .sidebar-brand').getBoundingClientRect().height; + const user = document.querySelector('#sidebar-user').getBoundingClientRect().height; + return Math.round(brand) === 64 && user >= 60; + })() + """) - Map.put(context, :conn, conn) + :ok end - step "I tab through to Sign out", context do + step "I tab through to Sign out", %{session: session} do # Nothing is focused on a fresh page, so the first Tab starts from the body. - conn = - Enum.reduce_while( - 1..60, - unwrap(context.conn, &Playwright.Page.press!(&1, "body", "Tab")), - fn _n, conn -> - conn = unwrap(conn, &Playwright.Page.press!(&1, ":focus", "Tab")) - - if evaluate(conn, "document.activeElement.id === 'sign-out-link'"), - do: {:halt, conn}, - else: {:cont, conn} - end - ) + press(session, by_css("body"), "Tab") - Map.put(context, :conn, assert_has(conn, "#sign-out-link:focus")) - end + Enum.find(1..60, fn _n -> + session + |> Keyboard.press("Tab") + |> Fluffy.Playwright.evaluate("document.activeElement.id === 'sign-out-link'") + end) - step "Sign out is scrolled into view", context do - conn = - assert_browser(context.conn, """ - (() => { - const sidebar = #{@sidebar}; - const box = sidebar.getBoundingClientRect(); - const link = document.querySelector('#sign-out-link').getBoundingClientRect(); - return sidebar.scrollTop > 0 && link.top >= box.top && link.bottom <= box.bottom; - })() - """) + assert(session, focused(by_css("#sign-out-link"))) + :ok + end - Map.put(context, :conn, conn) + step "Sign out is scrolled into view", %{session: session} do + assert_browser(session, """ + (() => { + const sidebar = #{@sidebar}; + const box = sidebar.getBoundingClientRect(); + const link = document.querySelector('#sign-out-link').getBoundingClientRect(); + return sidebar.scrollTop > 0 && link.top >= box.top && link.bottom <= box.bottom; + })() + """) + + :ok end # Real wheel events, so an intercepted wheel or a second scroll container # would fail here where setting scrollTop from a script would not. - step "I scroll up with the wheel over the account area", context do - Map.put(context, :conn, wheel_over(context.conn, "#sidebar-user", -2000)) + step "I scroll up with the wheel over the account area", %{session: session} do + wheel_over(session, by_css("#sidebar-user"), -2000) + :ok end - step "I scroll down with the wheel over the top navigation", context do - Map.put(context, :conn, wheel_over(context.conn, "#mobile-navigation-drawer .sb-item", 2000)) + step "I scroll down with the wheel over the top navigation", %{session: session} do + wheel_over(session, by_css("#mobile-navigation-drawer .sb-item") |> first(), 2000) + :ok end - step "the top navigation is in view and the account area has scrolled away", context do - conn = - assert_browser(context.conn, """ - (() => { - const sidebar = #{@sidebar}; - const box = sidebar.getBoundingClientRect(); - const discover = sidebar.querySelector('.sb-item').getBoundingClientRect(); - const user = document.querySelector('#sidebar-user').getBoundingClientRect(); - return discover.top >= box.top && discover.bottom <= box.bottom && user.top > box.bottom; - })() - """) - - Map.put(context, :conn, conn) + step "the top navigation is in view and the account area has scrolled away", + %{session: session} do + assert_browser(session, """ + (() => { + const sidebar = #{@sidebar}; + const box = sidebar.getBoundingClientRect(); + const discover = sidebar.querySelector('.sb-item').getBoundingClientRect(); + const user = document.querySelector('#sidebar-user').getBoundingClientRect(); + return discover.top >= box.top && discover.bottom <= box.bottom && user.top > box.bottom; + })() + """) + + :ok end - step "the page behind the sidebar has not moved and is still usable", context do - conn = - context.conn - |> assert_has("main h1", text: "Agenda") - |> assert_browser(""" - window.scrollY === 0 && !document.querySelector('main').inert && - document.querySelector('main').getBoundingClientRect().left > 0 - """) + step "the page behind the sidebar has not moved and is still usable", %{session: session} do + session + |> assert(visible(by_role(by_css("main"), :heading, level: 1, name: "Agenda"))) + |> assert_browser(""" + window.scrollY === 0 && !document.querySelector('main').inert && + document.querySelector('main').getBoundingClientRect().left > 0 + """) - Map.put(context, :conn, conn) + :ok end # The pointer goes to the middle of the element's on-screen part: an element # partly below the fold has its centre off the page, where a wheel reaches # nothing. - defp wheel_over(conn, selector, delta_y) do + defp wheel_over(session, locator, delta_y) do %{"x" => x, "y" => y} = - evaluate(conn, """ - (() => { - const r = document.querySelector(#{inspect(selector)}).getBoundingClientRect(); + Fluffy.Playwright.evaluate(session, locator, """ + element => { + const r = element.getBoundingClientRect(); const top = Math.max(r.top, 0); const bottom = Math.min(r.bottom, window.innerHeight); return {x: r.left + r.width / 2, y: (top + bottom) / 2}; - })() + } """) - unwrap(conn, fn page -> - mouse = Playwright.Page.mouse(page) - Playwright.Mouse.move!(mouse, x, y) - Playwright.Mouse.wheel!(mouse, 0, delta_y) - end) + session + |> Mouse.move(x, y) + |> Mouse.wheel(0, delta_y) end - - defp evaluate(conn, expression), - do: unwrap_and_return(conn, &Playwright.Page.evaluate!(&1, expression)) end diff --git a/test/browser/steps/sign_in_return_steps.exs b/test/browser/steps/sign_in_return_steps.exs index 1996951f0..c0db026e3 100644 --- a/test/browser/steps/sign_in_return_steps.exs +++ b/test/browser/steps/sign_in_return_steps.exs @@ -1,12 +1,13 @@ defmodule BrowserSignInReturnSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator - import Fluffy.PhoenixTest - import ExUnit.Assertions import Swoosh.TestAssertions, only: [set_swoosh_global: 0] - step "I am signed out looking at a public huddl in a browser", context do + step "I am signed out looking at a public huddl in a browser", %{session: session} do set_swoosh_global() member = @@ -19,31 +20,27 @@ defmodule BrowserSignInReturnSteps do generate(huddl(group_id: group.id, creator_id: owner.id, actor: owner, is_private: false)) path = "/groups/#{group.slug}/huddlz/#{huddl.id}" - conn = context.conn |> visit(path) - - Map.merge(context, %{ - conn: conn, - return_member: member, - return_huddl: huddl, - return_path: path - }) + visit(session, path) + + %{return_member: member, return_huddl: huddl, return_path: path} end - step "I choose the header Sign in in a browser", context do - Map.put(context, :conn, click_link(context.conn, ".content-topbar a", "Sign in")) + step "I choose the header Sign in in a browser", %{session: session} do + click(session, by_role(by_css(".content-topbar"), :link, name: "Sign in")) + :ok end - step "I recover my password through its email in this browser", context do + step "I recover my password through its email in this browser", + %{session: session} = context do email = to_string(context.return_member.email) - conn = - context.conn - |> click_link("Forgot your password?") - |> assert_has("h1", text: "Reset your password") - |> assert_has(".phx-connected") - |> fill_in("Email", with: email) - |> click_button("Send reset instructions") - |> assert_has("h2", text: "Check your email") + session + |> click(by_role(:link, name: "Forgot your password?")) + |> assert(visible(by_role(:heading, level: 1, name: "Reset your password"))) + |> assert(visible(by_css(".phx-connected") |> first())) + |> fill(by_label("Email", exact: true), email) + |> click(by_role(:button, name: "Send reset instructions")) + |> assert(visible(by_role(:heading, level: 2, name: "Check your email"))) token = receive do @@ -55,27 +52,27 @@ defmodule BrowserSignInReturnSteps do 2000 -> flunk("No password reset email for the return visit") end - conn = - conn - |> visit("/reset/#{token}") - |> fill_in("New password", with: "ChangedPassword123!") - |> fill_in("Confirm new password", with: "ChangedPassword123!") - |> click_button("Reset password") + session + |> visit("/reset/#{token}") + |> fill(by_label("New password", exact: true), "ChangedPassword123!") + |> fill(by_label("Confirm new password", exact: true), "ChangedPassword123!") + |> click(by_role(:button, name: "Reset password")) - Map.put(context, :conn, conn) + :ok end - step "I return to that huddl without reserving a spot in a browser", context do - context.conn - |> assert_path(context.return_path) - |> assert_has("h1", text: context.return_huddl.title) - |> assert_has("button", text: "RSVP") + step "I return to that huddl without reserving a spot in a browser", + %{session: session} = context do + session + |> assert(page_url(&(&1.path == context.return_path))) + |> assert(visible(by_role(:heading, level: 1, name: context.return_huddl.title))) + |> assert(visible(by_role(:button, name: "RSVP"))) assert [] = Huddlz.Communities.check_user_rsvp!(context.return_huddl.id, actor: context.return_member ) - context + :ok end end diff --git a/test/browser/steps/social_schedule_steps.exs b/test/browser/steps/social_schedule_steps.exs index bb529c695..f8c2c670e 100644 --- a/test/browser/steps/social_schedule_steps.exs +++ b/test/browser/steps/social_schedule_steps.exs @@ -1,148 +1,161 @@ defmodule BrowserSocialScheduleSteps do use Cucumber.StepDefinition + use Fluffy.Assert + import Fluffy, except: [step: 2, step: 3] + import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers - import Fluffy.PhoenixTest - - step "I am editing a social connection as its owner", context do - {conn, group, _place} = connected_place(context.conn) - - conn = - conn - |> visit("/organize/#{group.slug}/social") - |> click_button("Edit") - |> assert_has("#social-post-preview", text: "Morning-of post preview") - # The sheet moves focus to its first control again two animation - # frames after mounting; wait for it to finish opening before typing. - |> assert_browser( - "getComputedStyle(document.querySelector('#schedule-sheet-container')).opacity === '1'" - ) - - Map.put(context, :conn, conn) + + alias Fluffy.Playwright + + step "I am editing a social connection as its owner", %{session: session} do + {session, group, _place} = connected_place(session) + + session + |> visit("/organize/#{group.slug}/social") + |> click(edit()) + |> assert(visible(preview() |> filter(has_text: "Morning-of post preview"))) + # The sheet moves focus to its first control again two animation + # frames after mounting; wait for it to finish opening before typing. + |> assert(css(sheet(), "opacity", "1")) + + :ok end - step "I ask to remove the place and cancel", context do - conn = context.conn |> click_button("Remove") |> click_button("Cancel") - Map.put(context, :conn, conn) + step "I ask to remove the place and cancel", %{session: session} do + session + |> click(by_role(:button, name: "Remove", exact: true)) + |> click(by_role(:button, name: "Cancel", exact: true)) + + :ok end - step "I can continue editing its schedule", context do - conn = - context.conn - |> assert_has("#schedule-form") - |> fill_in("Opening line", with: "Still connected!") - |> assert_has("#social-post-preview", text: "Still connected!") + step "I can continue editing its schedule", %{session: session} do + session + |> assert(visible(by_css("#schedule-form"))) + |> fill(opening_line(), "Still connected!") + |> assert(visible(preview() |> filter(has_text: "Still connected!"))) - Map.put(context, :conn, conn) + :ok end - step "I ask to remove the place again and confirm", context do - conn = context.conn |> click_button("Remove") |> click_button("Remove connection") - Map.put(context, :conn, conn) + step "I ask to remove the place again and confirm", %{session: session} do + session + |> click(by_role(:button, name: "Remove", exact: true)) + |> click(by_role(:button, name: "Remove connection", exact: true)) + + :ok end - step "Social lists no connected places", context do - context.conn - |> assert_has("#social-connections", text: "Nothing connected yet") - |> reload_page() - |> assert_has("#social-connections", text: "Nothing connected yet") + step "Social lists no connected places", %{session: session} do + empty_list = by_css("#social-connections") |> filter(has_text: "Nothing connected yet") + + session + |> assert(visible(empty_list)) + |> reload() + |> assert(visible(empty_list)) - context + :ok end - step "I choose morning-of posting with Space", context do - conn = unwrap(context.conn, &Playwright.Page.press!(&1, "#moments_morning_of", "Space")) - Map.put(context, :conn, conn) + step "I choose morning-of posting with Space", %{session: session} do + press(session, morning_of(), "Space") + :ok end - step "the social schedule choice stays focused and checked", context do - assert_has(context.conn, "#moments_morning_of:checked:focus[aria-checked='true']") - context + step "the social schedule choice stays focused and checked", %{session: session} do + session + |> assert(checked(morning_of())) + |> assert(focused(morning_of())) + |> assert(attribute(morning_of(), "aria-checked", "true")) + + :ok end - step "I enter an opening line and finish immediately", context do - conn = - context.conn - |> fill_in("Opening line", with: "See you tonight!") - |> click_button("Done") - |> refute_has("#schedule-sheet [role='dialog']") + step "I enter an opening line and finish immediately", %{session: session} do + session + |> fill(opening_line(), "See you tonight!") + |> click(by_role(:button, name: "Done", exact: true)) + |> assert(count(by_role(by_css("#schedule-sheet"), :dialog), 0)) - Map.put(context, :conn, conn) + :ok end - step "reopening the social schedule shows both changes", context do - conn = - context.conn - |> click_button("Edit") - |> assert_has("#moments_morning_of:checked") - |> assert_has("#social-post-preview", text: "See you tonight!") - |> assert_browser( - "getComputedStyle(document.querySelector('#schedule-sheet-container')).opacity === '1'" - ) - |> unwrap(&Playwright.Page.press!(&1, "#opening-line", "Tab")) - |> assert_has("#remove-connection:focus") - |> assert_browser(""" - Array.from(document.querySelectorAll('#schedule-form button, #schedule-form a')).every(control => { - const bounds = control.getBoundingClientRect(); - return bounds.left >= 0 && bounds.right <= window.innerWidth; - }) - """) - - Map.put(context, :conn, conn) + step "reopening the social schedule shows both changes", %{session: session} do + session + |> click(edit()) + |> assert(checked(morning_of())) + |> assert(visible(preview() |> filter(has_text: "See you tonight!"))) + |> assert(css(sheet(), "opacity", "1")) + |> press(opening_line(), "Tab") + |> assert(focused(by_role(:button, name: "Remove", exact: true))) + |> assert_browser(""" + Array.from(document.querySelectorAll('#schedule-form button, #schedule-form a')).every(control => { + const bounds = control.getBoundingClientRect(); + return bounds.left >= 0 && bounds.right <= window.innerWidth; + }) + """) + + :ok end - step "I have returned to Social after connecting a place", context do - {conn, group, place} = connected_place(context.conn) + step "I have returned to Social after connecting a place", %{session: session} = context do + {session, group, place} = connected_place(session) + schedule = schedule_dialog() |> filter(has_text: place.channel_name) - conn = - conn - |> visit("/organize/#{group.slug}/social?connected=#{place.id}") - |> assert_has("#schedule-sheet", text: place.channel_name) - |> reload_page() - |> assert_has("body .phx-connected") - |> assert_has("#schedule-sheet", text: place.channel_name) + session + |> visit("/organize/#{group.slug}/social?connected=#{place.id}") + |> assert(visible(schedule)) + |> reload() + |> assert(visible(schedule)) - Map.merge(context, %{conn: conn, place: place}) + Map.put(context, :place, place) end - step "I finish its schedule and open Members", context do - conn = - context.conn - |> click_button("Start posting") - |> assert_browser("location.search === ''") - |> refute_has("#schedule-sheet [role='dialog']") - |> click_link("Members") - |> assert_has("h1", text: "Members") + step "I finish its schedule and open Members", %{session: session} do + session + |> click(by_role(:button, name: "Start posting", exact: true)) + |> assert_browser("location.search === ''") + |> assert(count(schedule_dialog(), 0)) + |> click(by_role(:link, name: "Members", exact: true)) + |> assert(visible(by_role(:heading, name: "Members", level: 1))) - Map.put(context, :conn, conn) + :ok end - step "Back returns to Social and back again reopens the connected place's schedule", context do - conn = - context.conn - |> unwrap(&Playwright.Page.evaluate!(&1, "requestAnimationFrame(() => history.back())")) - |> assert_has("a[aria-current='page']", text: "Social") - |> refute_has("#schedule-sheet [role='dialog']") - |> unwrap(&Playwright.Page.evaluate!(&1, "requestAnimationFrame(() => history.back())")) - |> assert_has("#schedule-sheet", text: context.place.channel_name) + step "Back returns to Social and back again reopens the connected place's schedule", + %{session: session, place: place} do + session + |> Playwright.go_back() + |> assert(attribute(by_role(:link, name: "Social", exact: true), "aria-current", "page")) + |> assert(count(schedule_dialog(), 0)) + |> Playwright.go_back() + |> assert(visible(schedule_dialog() |> filter(has_text: place.channel_name))) - Map.put(context, :conn, conn) + :ok end - step "Forward returns to Social with the schedule closed", context do - context.conn - |> unwrap(&Playwright.Page.evaluate!(&1, "requestAnimationFrame(() => history.forward())")) - |> refute_has("#schedule-sheet [role='dialog']") - |> assert_has("h1", text: "Social") + step "Forward returns to Social with the schedule closed", %{session: session} do + session + |> Playwright.go_forward() + |> assert(count(schedule_dialog(), 0)) + |> assert(visible(by_role(:heading, name: "Social", level: 1))) - context + :ok end - defp connected_place(conn) do + defp connected_place(session) do owner = generate(user(role: :user)) group = generate(group(owner_id: owner.id, is_public: true, actor: owner)) place = generate(social_connection(group_id: group.id, actor: owner)) - {sign_in(conn, owner), group, place} + {sign_in(session, owner), group, place} end + + defp edit, do: by_role(:button, name: "Edit", exact: true) + defp preview, do: by_css("#social-post-preview") + defp sheet, do: by_css("#schedule-sheet-container") + defp schedule_dialog, do: by_role(by_css("#schedule-sheet"), :dialog) + defp morning_of, do: by_role(:switch, name: "The morning of", exact: true) + defp opening_line, do: by_label("Opening line", exact: true) end diff --git a/test/browser/support/hooks.exs b/test/browser/support/hooks.exs index c51f727a3..3f1b03b84 100644 --- a/test/browser/support/hooks.exs +++ b/test/browser/support/hooks.exs @@ -34,13 +34,12 @@ defmodule BrowserHooks do # register the scenario: run its per-test setup here. Playwright.Test.__setup__(context) - conn = - Fluffy.PhoenixTest.start_session(:playwright, - browser_context: Map.get(context, :browser_context_opts, []) - ) + session = + :playwright + |> Fluffy.start_session(browser_context: Map.get(context, :browser_context_opts, [])) + |> answer_external_requests_locally() - answer_external_requests_locally(conn) - Map.put(context, :conn, conn) + Map.put(context, :session, session) end @inter_url "https://fonts.gstatic.com/s/inter/v20/inter-latin.woff2" @@ -62,10 +61,10 @@ defmodule BrowserHooks do # holds the load event that visit waits for, so every external request is # answered locally: Inter from a fixture, so layouts measure as they do in # production, and anything else with an empty response. - defp answer_external_requests_locally(conn) do + defp answer_external_requests_locally(session) do # Playwright resolves a bare "https://**" to "https://**/", which only # matches URLs ending in a slash. - Fluffy.Playwright.route(conn.session, "https://*/**", fn route, request -> + Fluffy.Playwright.route(session, "https://*/**", fn route, request -> Playwright.Route.fulfill!(route, response(Playwright.Request.url(request))) end) end diff --git a/test/support/browser_helpers.ex b/test/support/browser_helpers.ex index 250f46e28..52b2f3357 100644 --- a/test/support/browser_helpers.ex +++ b/test/support/browser_helpers.ex @@ -1,31 +1,17 @@ defmodule Huddlz.Test.BrowserHelpers do @moduledoc false - import Fluffy.PhoenixTest, only: [unwrap: 2] - import Phoenix.ConnTest, only: [build_conn: 0, dispatch: 4] - - def sign_in(conn, member) do + def sign_in(session, member) do {:ok, token, _claims} = AshAuthentication.Jwt.token_for_user(member, %{}, domain: Huddlz.Accounts) - # One request through the endpoint signs the session cookie. - signed = - build_conn() - |> Plug.Test.init_test_session(%{ - user_token: token, - live_socket_id: "users_sessions:#{Base.url_encode64(token)}" - }) - |> dispatch(HuddlzWeb.Endpoint, :get, "/") - - cookies = - for {name, %{value: value}} <- signed.resp_cookies, - do: %{name: name, value: value, url: Fluffy.base_url(conn.session)} - - %{conn | session: Fluffy.add_cookies(conn.session, cookies)} + Fluffy.add_session_cookie(session, %{ + "user_token" => token, + "live_socket_id" => "users_sessions:#{Base.url_encode64(token)}" + }) end # Observe actual browser state with a bounded wait; never simulate app behavior. - def assert_browser(conn, expression) do - unwrap(conn, &Playwright.Page.wait_for_function!(&1, expression, nil, timeout: 5_000)) - end + def assert_browser(session, expression), + do: Fluffy.Playwright.wait_for_function(session, expression, timeout: 5_000) end From 8478770d767d9e3c8617e31c5cbfcdf99c763710 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 09:43:33 +0100 Subject: [PATCH 06/14] test(browser): explain the Playwright.Test setup as a stop-gap --- test/browser/support/hooks.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/browser/support/hooks.exs b/test/browser/support/hooks.exs index 3f1b03b84..099a237c6 100644 --- a/test/browser/support/hooks.exs +++ b/test/browser/support/hooks.exs @@ -30,8 +30,10 @@ defmodule BrowserHooks do # first, stops last, after the scenario's browser contexts have closed. Huddlz.DataCase.setup_sandbox(context) - # Cucumber creates the ExUnit modules, so no `use Playwright.Test` can - # register the scenario: run its per-test setup here. + # A stop-gap until Cucumber can add a case template's `use` to the modules + # it generates. They only `use ExUnit.Case`, so run Playwright.Test's + # per-test setup here. Without its `test`, Playwright.Test never learns a + # scenario's result, so every scenario's screenshot is named as failed. Playwright.Test.__setup__(context) session = From 67ad7c83497ca336fa21c53b6e34b38010689f0c Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 14:56:07 +0100 Subject: [PATCH 07/14] test(browser): take Cucumber from the fork's playwright branch It combines the case_template and step_wrapper drafts (huddlz-hq/cucumber#84, #85). --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index cd94676c3..eecfdd365 100644 --- a/mix.exs +++ b/mix.exs @@ -140,7 +140,7 @@ defmodule Huddlz.MixProject do {:dns_cluster, "~> 0.3"}, {:bandit, "~> 1.5"}, {:corsica, "~> 2.1"}, - {:cucumber, "~> 1.2", only: [:dev, :test]}, + {:cucumber, github: "ftes/cucumber", branch: "playwright", only: [:dev, :test]}, {:mox, "~> 1.0", only: :test}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, {:phoenix_test, "~> 0.12", only: :test}, diff --git a/mix.lock b/mix.lock index b307b264c..e871af12f 100644 --- a/mix.lock +++ b/mix.lock @@ -29,7 +29,7 @@ "corsica": {:hex, :corsica, "2.1.3", "dccd094ffce38178acead9ae743180cdaffa388f35f0461ba1e8151d32e190e6", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "616c08f61a345780c2cf662ff226816f04d8868e12054e68963e95285b5be8bc"}, "credo": {:hex, :credo, "1.7.19", "cc52129665fc7c15143d47838fda0f9cd6dac9ceced7bf4da6f85fcbfe64b12a", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "2d8bc95d5a7bb99dd2613621d4f08c6a3575c3fd4b62e6a2b48a100352a557b8"}, "crux": {:hex, :crux, "0.1.5", "fe95455065e20f3c70a492beb16d3f477c20d659725d93525f932cac4304ad93", [:mix], [{:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: true]}], "hexpm", "56f4941d362a262a83e5f2ba4fae2173ac2f556a03b5b3965f58b6eb0aedbba3"}, - "cucumber": {:hex, :cucumber, "1.2.0", "629123f8edf285820c54ff0ffa4445d8896f5234dd4e91ebdb189f19c2e589bb", [:mix], [{:igniter, "~> 0.8.3", [hex: :igniter, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "78b03a9b516a8fdaaab4dfb8d451ce6c79ca04a5fed0f38f3ee1a40c7053aa63"}, + "cucumber": {:git, "https://github.com/ftes/cucumber.git", "819ce9852f674afcc7016b2d8f19be722e0728b8", [branch: "playwright"]}, "db_connection": {:hex, :db_connection, "2.10.3", "9d641d9cb56ed7cd03d0f5520b64f023f8c9a2531944991c952aa38e8afd5405", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ff441940bfd9ef5cced632e0e36d4ac823abeb9cae2767203fb9b4ccd1bd83cb"}, "decimal": {:hex, :decimal, "3.2.0", "f1235f05d841a211fda78a08fdb9777f2ff51a71f18455233fae186ff76187c6", [:mix], [], "hexpm", "190bca80580ce61aa69bb0eacadd7677710205c770225c2c2c07e32a5c31b234"}, "dns_cluster": {:hex, :dns_cluster, "0.3.1", "b4e707e4ddaf0d3f13580ee7dc4ab0e685f7f7f5bbe90e84535524bc12d1cf3e", [:mix], [], "hexpm", "afa60bbbd84463e977eeeecc0c564d8c5ddea260beccdb8d5f45cbb860846627"}, From 5211e189b7a5f666d8ff574a89d851c20fb0853b Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 14:56:18 +0100 Subject: [PATCH 08/14] test(browser): generate the scenario modules with a case template Cucumber now uses HuddlzWeb.BrowserCase in place of ExUnit.Case, so each scenario is a Playwright.Test test and the hook no longer runs its per-test setup. The template owns the sandbox, which stops after the contexts close. --- test/browser/README.md | 4 ++-- test/browser/browser_features_test.exs | 3 ++- test/browser/support/hooks.exs | 10 ---------- test/support/browser_case.ex | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 test/support/browser_case.ex diff --git a/test/browser/README.md b/test/browser/README.md index c6de12da5..2edc64878 100644 --- a/test/browser/README.md +++ b/test/browser/README.md @@ -42,11 +42,11 @@ The command builds the actual app assets, starts the test endpoint and Chromium, | Crop on upload | The crop sheet opens on choosing a picture, real pointer drags move it, and the upload is the 16:9 crop that was chosen; full-screen sheet at 320px | | Password recovery | A reset finished in the same browser returns to the huddl where Sign in was chosen; the destination rides on the session cookie written during a LiveView redirect, which the fast suite does not keep | -Browser scenarios live in `features/`, their steps in `steps/`, and Cucumber hooks in `support/`. `browser_features_test.exs` supplies explicit feature/step/support globs to Cucumber. The existing fast root and its steps are loaded only by the normal test runner. No Cucumber fork or second library is needed. Use descriptive tags such as `@calendar_browser`; `@browser` conflicts with the adapter's browser-selection option. +Browser scenarios live in `features/`, their steps in `steps/`, and Cucumber hooks in `support/`. `browser_features_test.exs` supplies explicit feature/step/support globs and the case template to Cucumber. The existing fast root and its steps are loaded only by the normal test runner. Use descriptive tags such as `@calendar_browser`; `@browser` conflicts with the adapter's browser-selection option. Keep this suite serial: its SQL sandbox ownership and global Mox stubs are shared with HTTP/LiveView processes. Do not add `@async` or extra workers without changing that fixture strategy. Each scenario gets a fresh browser context. Authentication uses a signed session cookie; apart from password recovery, these are not sign-in UI tests. Places/geocoding are deterministic stubs, with no external service credentials needed. The test endpoint serves the app over HTTP. Each browser context answers HTTPS requests locally so third-party services cannot delay page loads. Google Fonts requests receive the Inter fixture from `test/fixtures/fonts` to preserve layout measurements. Other HTTPS requests, including Maps embeds, receive an empty response. Browser contexts use `America/New_York`; `@mobile` selects a 320×720 viewport. -Browser setup calls `Playwright.Test`'s per-test setup from the hook because Cucumber creates the ExUnit modules, so none of them can `use Playwright.Test`. SQL sandbox HTTP metadata and the LiveView allowance hook are enabled only in test builds, before authentication queries. +Cucumber generates each feature's test module with `HuddlzWeb.BrowserCase` as its case template, which brings in `Playwright.Test` and owns the SQL sandbox. SQL sandbox HTTP metadata and the LiveView allowance hook are enabled only in test builds, before authentication queries. ## CI and diagnostics diff --git a/test/browser/browser_features_test.exs b/test/browser/browser_features_test.exs index 7649ad146..b5f435613 100644 --- a/test/browser/browser_features_test.exs +++ b/test/browser/browser_features_test.exs @@ -1,5 +1,6 @@ Cucumber.compile_features!( features: ["test/browser/features/**/*.feature"], steps: ["test/browser/steps/**/*.exs"], - support: ["test/browser/support/**/*.exs"] + support: ["test/browser/support/**/*.exs"], + case_template: HuddlzWeb.BrowserCase ) diff --git a/test/browser/support/hooks.exs b/test/browser/support/hooks.exs index 099a237c6..8042973c6 100644 --- a/test/browser/support/hooks.exs +++ b/test/browser/support/hooks.exs @@ -26,16 +26,6 @@ defmodule BrowserHooks do context end - # ExUnit runs `on_exit` callbacks in reverse: the sandbox owner, registered - # first, stops last, after the scenario's browser contexts have closed. - Huddlz.DataCase.setup_sandbox(context) - - # A stop-gap until Cucumber can add a case template's `use` to the modules - # it generates. They only `use ExUnit.Case`, so run Playwright.Test's - # per-test setup here. Without its `test`, Playwright.Test never learns a - # scenario's result, so every scenario's screenshot is named as failed. - Playwright.Test.__setup__(context) - session = :playwright |> Fluffy.start_session(browser_context: Map.get(context, :browser_context_opts, [])) diff --git a/test/support/browser_case.ex b/test/support/browser_case.ex new file mode 100644 index 000000000..4001744c6 --- /dev/null +++ b/test/support/browser_case.ex @@ -0,0 +1,21 @@ +defmodule HuddlzWeb.BrowserCase do + @moduledoc """ + The case template of the browser scenarios' test modules, which Cucumber + generates (see `test/browser/browser_features_test.exs`). + """ + + use ExUnit.CaseTemplate + + using opts do + quote do + use Playwright.Test, unquote(opts) + end + end + + # Runs before Playwright.Test's setup, so the sandbox owner stops after the + # scenario's browser contexts have closed. + setup tags do + Huddlz.DataCase.setup_sandbox(tags) + :ok + end +end From d53a9273369591595769a7fb35bb2d8794c4216b Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 14:59:16 +0100 Subject: [PATCH 09/14] test(browser): show each Gherkin step as a step in the trace Cucumber's step wrapper runs every step inside Playwright.Test.step, so a trace groups each step's actions under its Given/When/Then line. It is set in the browser suite's helper, as the fast suite's steps are no Playwright tests. --- test/browser/test_helper.exs | 2 ++ test/support/browser_case.ex | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/test/browser/test_helper.exs b/test/browser/test_helper.exs index 94292fd93..8b2a26233 100644 --- a/test/browser/test_helper.exs +++ b/test/browser/test_helper.exs @@ -1,5 +1,7 @@ # Loaded only by mix test.browser. ExUnit.start(capture_log: true, max_cases: 1) Ecto.Adapters.SQL.Sandbox.mode(Huddlz.Repo, :manual) +# Set here, not in config: the fast Cucumber suite's steps are no Playwright tests. +Application.put_env(:cucumber, :step_wrapper, {HuddlzWeb.BrowserCase, :wrap}) System.put_env("PLAYWRIGHT_BROWSERS_PATH", Path.expand("_build/browser/browsers")) diff --git a/test/support/browser_case.ex b/test/support/browser_case.ex index 4001744c6..83ba3fcd0 100644 --- a/test/support/browser_case.ex +++ b/test/support/browser_case.ex @@ -6,6 +6,8 @@ defmodule HuddlzWeb.BrowserCase do use ExUnit.CaseTemplate + require Playwright.Test + using opts do quote do use Playwright.Test, unquote(opts) @@ -18,4 +20,10 @@ defmodule HuddlzWeb.BrowserCase do Huddlz.DataCase.setup_sandbox(tags) :ok end + + @doc """ + Cucumber's step wrapper (`test/browser/test_helper.exs`): each Gherkin step + is a step in the trace, with its actions inside. + """ + def wrap(step, _context, run), do: Playwright.Test.step("#{step.keyword} #{step.text}", run) end From 6c87f54531a7f3a6778ae01fc0f6d64c63ae9182 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 14:59:25 +0100 Subject: [PATCH 10/14] test(browser): keep traces and screenshots of failed scenarios only Playwright.Test now learns each scenario's result, so a passing run leaves no per-scenario artifacts and CI's failure upload holds just the failures. --- config/test.exs | 4 ++-- test/browser/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/test.exs b/config/test.exs index 814124c15..1cc327fdf 100644 --- a/config/test.exs +++ b/config/test.exs @@ -40,8 +40,8 @@ config :fluffy, Fluffy.Sandbox, header: "user-agent" config :playwright, :test, timezone_id: "America/New_York", - screenshot: :on, - trace: :on, + screenshot: :only_on_failure, + trace: :retain_on_failure, output_dir: "_build/browser/test-results" # Disable swoosh api client in test diff --git a/test/browser/README.md b/test/browser/README.md index 2edc64878..2e7f5e558 100644 --- a/test/browser/README.md +++ b/test/browser/README.md @@ -52,7 +52,7 @@ Cucumber generates each feature's test module with `HuddlzWeb.BrowserCase` as it The **Browser scenarios (Chromium)** job runs separately on every PR, including stacked PRs, and every push to `main`, alongside the fast tests. It installs the Playwright driver that Fluffy pins, Chromium headless shell, and Linux libraries. It uses one worker, a two-minute test-step timeout, and no automatic retries. Dependency compilation is cached; browser binaries and diagnostics are not part of that cache. -Screenshots and traces are captured for every attempt under `_build/browser/test-results`, one directory per scenario; explicit screenshots go to `_build/browser/screenshots`. Failed CI runs upload these directories as `browser-failure-diagnostics` for seven days. Inspect the original failure before rerunning: +A failed scenario keeps a screenshot, its trace and `error-context.md` under `_build/browser/test-results`, one directory per scenario; passing scenarios keep none. Explicit screenshots go to `_build/browser/screenshots`. Failed CI runs upload these directories as `browser-failure-diagnostics` for seven days. Inspect the original failure before rerunning: ```sh MIX_ENV=test mix playwright.cli show-trace _build/browser/test-results//trace.zip From 3bd1a5283eefb8433b997590f570454e66f69eb0 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 15:01:18 +0100 Subject: [PATCH 11/14] test(browser): exclude only the step/3 that clashes with Cucumber's Fluffy has no step/2, so excluding it did nothing. --- test/browser/steps/appearance_menu_steps.exs | 2 +- test/browser/steps/calendar_day_sheet_steps.exs | 2 +- test/browser/steps/calendar_timezone_steps.exs | 2 +- test/browser/steps/copy_huddl_steps.exs | 2 +- test/browser/steps/cover_crop_steps.exs | 2 +- test/browser/steps/cover_upload_progress_steps.exs | 2 +- test/browser/steps/discover_navigation_steps.exs | 2 +- test/browser/steps/email_confirmation_steps.exs | 2 +- test/browser/steps/group_cover_steps.exs | 2 +- test/browser/steps/huddl_photos_steps.exs | 2 +- test/browser/steps/keyboard_focus_steps.exs | 2 +- test/browser/steps/location_keyboard_steps.exs | 2 +- test/browser/steps/member_menu_steps.exs | 2 +- test/browser/steps/mobile_navigation_steps.exs | 2 +- test/browser/steps/mobile_rsvp_steps.exs | 2 +- test/browser/steps/notification_preferences_steps.exs | 2 +- test/browser/steps/organizer_keyboard_steps.exs | 2 +- test/browser/steps/overview_cards_steps.exs | 2 +- test/browser/steps/profile_picture_steps.exs | 2 +- test/browser/steps/report_review_steps.exs | 2 +- test/browser/steps/share_links_steps.exs | 2 +- test/browser/steps/sidebar_scroll_steps.exs | 2 +- test/browser/steps/sign_in_return_steps.exs | 2 +- test/browser/steps/social_schedule_steps.exs | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test/browser/steps/appearance_menu_steps.exs b/test/browser/steps/appearance_menu_steps.exs index 88bf7189c..5aa43482b 100644 --- a/test/browser/steps/appearance_menu_steps.exs +++ b/test/browser/steps/appearance_menu_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserAppearanceMenuSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator alias Fluffy.Playwright.Keyboard diff --git a/test/browser/steps/calendar_day_sheet_steps.exs b/test/browser/steps/calendar_day_sheet_steps.exs index 579be7ef2..d009843fc 100644 --- a/test/browser/steps/calendar_day_sheet_steps.exs +++ b/test/browser/steps/calendar_day_sheet_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserCalendarDaySheetSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/calendar_timezone_steps.exs b/test/browser/steps/calendar_timezone_steps.exs index ccefea74e..65d1b2597 100644 --- a/test/browser/steps/calendar_timezone_steps.exs +++ b/test/browser/steps/calendar_timezone_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserCalendarSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/copy_huddl_steps.exs b/test/browser/steps/copy_huddl_steps.exs index 4389a0aaf..a1066edbe 100644 --- a/test/browser/steps/copy_huddl_steps.exs +++ b/test/browser/steps/copy_huddl_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserCopyHuddlSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/cover_crop_steps.exs b/test/browser/steps/cover_crop_steps.exs index 1c0e4e124..3e416ddfc 100644 --- a/test/browser/steps/cover_crop_steps.exs +++ b/test/browser/steps/cover_crop_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserCoverCropSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/cover_upload_progress_steps.exs b/test/browser/steps/cover_upload_progress_steps.exs index f16aa8897..e26c31533 100644 --- a/test/browser/steps/cover_upload_progress_steps.exs +++ b/test/browser/steps/cover_upload_progress_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserCoverUploadSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/discover_navigation_steps.exs b/test/browser/steps/discover_navigation_steps.exs index 8b653137e..a5c0c0cd8 100644 --- a/test/browser/steps/discover_navigation_steps.exs +++ b/test/browser/steps/discover_navigation_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserDiscoverNavigationSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/email_confirmation_steps.exs b/test/browser/steps/email_confirmation_steps.exs index 8effc2a59..ecc26d6e8 100644 --- a/test/browser/steps/email_confirmation_steps.exs +++ b/test/browser/steps/email_confirmation_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserEmailConfirmationSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/group_cover_steps.exs b/test/browser/steps/group_cover_steps.exs index 739ee5418..8b5aea0f3 100644 --- a/test/browser/steps/group_cover_steps.exs +++ b/test/browser/steps/group_cover_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserCoverSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/huddl_photos_steps.exs b/test/browser/steps/huddl_photos_steps.exs index 8628972e9..6227740f7 100644 --- a/test/browser/steps/huddl_photos_steps.exs +++ b/test/browser/steps/huddl_photos_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserPhotoSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/keyboard_focus_steps.exs b/test/browser/steps/keyboard_focus_steps.exs index 374a0f08b..a4628a113 100644 --- a/test/browser/steps/keyboard_focus_steps.exs +++ b/test/browser/steps/keyboard_focus_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserKeyboardFocusSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/location_keyboard_steps.exs b/test/browser/steps/location_keyboard_steps.exs index 34a61342b..fe92e5284 100644 --- a/test/browser/steps/location_keyboard_steps.exs +++ b/test/browser/steps/location_keyboard_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserLocationKeyboardSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/member_menu_steps.exs b/test/browser/steps/member_menu_steps.exs index 1f1eb280e..520de3540 100644 --- a/test/browser/steps/member_menu_steps.exs +++ b/test/browser/steps/member_menu_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserMemberMenuSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/mobile_navigation_steps.exs b/test/browser/steps/mobile_navigation_steps.exs index c241b23cc..163f221f8 100644 --- a/test/browser/steps/mobile_navigation_steps.exs +++ b/test/browser/steps/mobile_navigation_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserNavigationSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/mobile_rsvp_steps.exs b/test/browser/steps/mobile_rsvp_steps.exs index a95ddac68..c1fed1af8 100644 --- a/test/browser/steps/mobile_rsvp_steps.exs +++ b/test/browser/steps/mobile_rsvp_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserMobileRsvpSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/notification_preferences_steps.exs b/test/browser/steps/notification_preferences_steps.exs index a1fb299c1..60dbee9ed 100644 --- a/test/browser/steps/notification_preferences_steps.exs +++ b/test/browser/steps/notification_preferences_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserNotificationPreferencesSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/organizer_keyboard_steps.exs b/test/browser/steps/organizer_keyboard_steps.exs index 72ecb8740..897cf4e30 100644 --- a/test/browser/steps/organizer_keyboard_steps.exs +++ b/test/browser/steps/organizer_keyboard_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserOrganizerSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/overview_cards_steps.exs b/test/browser/steps/overview_cards_steps.exs index e5923847d..da02b5062 100644 --- a/test/browser/steps/overview_cards_steps.exs +++ b/test/browser/steps/overview_cards_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserOverviewCardsSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/profile_picture_steps.exs b/test/browser/steps/profile_picture_steps.exs index 653ef739a..5ceaa41fd 100644 --- a/test/browser/steps/profile_picture_steps.exs +++ b/test/browser/steps/profile_picture_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserPictureSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/report_review_steps.exs b/test/browser/steps/report_review_steps.exs index 9bcfb54ba..7e250b7ed 100644 --- a/test/browser/steps/report_review_steps.exs +++ b/test/browser/steps/report_review_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserReportReviewSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/share_links_steps.exs b/test/browser/steps/share_links_steps.exs index bc3f479a0..93379748a 100644 --- a/test/browser/steps/share_links_steps.exs +++ b/test/browser/steps/share_links_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserShareLinksSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator diff --git a/test/browser/steps/sidebar_scroll_steps.exs b/test/browser/steps/sidebar_scroll_steps.exs index 5d5599a4b..8be265464 100644 --- a/test/browser/steps/sidebar_scroll_steps.exs +++ b/test/browser/steps/sidebar_scroll_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserSidebarScrollSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers diff --git a/test/browser/steps/sign_in_return_steps.exs b/test/browser/steps/sign_in_return_steps.exs index c0db026e3..a45912fdb 100644 --- a/test/browser/steps/sign_in_return_steps.exs +++ b/test/browser/steps/sign_in_return_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserSignInReturnSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Swoosh.TestAssertions, only: [set_swoosh_global: 0] diff --git a/test/browser/steps/social_schedule_steps.exs b/test/browser/steps/social_schedule_steps.exs index f8c2c670e..5af030373 100644 --- a/test/browser/steps/social_schedule_steps.exs +++ b/test/browser/steps/social_schedule_steps.exs @@ -2,7 +2,7 @@ defmodule BrowserSocialScheduleSteps do use Cucumber.StepDefinition use Fluffy.Assert - import Fluffy, except: [step: 2, step: 3] + import Fluffy, except: [step: 3] import Fluffy.Locator import Huddlz.Generator import Huddlz.Test.BrowserHelpers From ce6fec9ac6247a4e423d7a7a66f9282df0d7be12 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 15:14:06 +0100 Subject: [PATCH 12/14] test(browser): pass the step wrapper to compile_features! Cucumber now takes it as an option, so it wraps only the browser features without setting the app env. Bumps the fork to d75ec023. --- mix.lock | 2 +- test/browser/browser_features_test.exs | 3 ++- test/browser/test_helper.exs | 2 -- test/support/browser_case.ex | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mix.lock b/mix.lock index e871af12f..c6bbb5e65 100644 --- a/mix.lock +++ b/mix.lock @@ -29,7 +29,7 @@ "corsica": {:hex, :corsica, "2.1.3", "dccd094ffce38178acead9ae743180cdaffa388f35f0461ba1e8151d32e190e6", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "616c08f61a345780c2cf662ff226816f04d8868e12054e68963e95285b5be8bc"}, "credo": {:hex, :credo, "1.7.19", "cc52129665fc7c15143d47838fda0f9cd6dac9ceced7bf4da6f85fcbfe64b12a", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "2d8bc95d5a7bb99dd2613621d4f08c6a3575c3fd4b62e6a2b48a100352a557b8"}, "crux": {:hex, :crux, "0.1.5", "fe95455065e20f3c70a492beb16d3f477c20d659725d93525f932cac4304ad93", [:mix], [{:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: true]}], "hexpm", "56f4941d362a262a83e5f2ba4fae2173ac2f556a03b5b3965f58b6eb0aedbba3"}, - "cucumber": {:git, "https://github.com/ftes/cucumber.git", "819ce9852f674afcc7016b2d8f19be722e0728b8", [branch: "playwright"]}, + "cucumber": {:git, "https://github.com/ftes/cucumber.git", "d75ec0239b758d0c6e994b15f6a3ba5a50906381", [branch: "playwright"]}, "db_connection": {:hex, :db_connection, "2.10.3", "9d641d9cb56ed7cd03d0f5520b64f023f8c9a2531944991c952aa38e8afd5405", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ff441940bfd9ef5cced632e0e36d4ac823abeb9cae2767203fb9b4ccd1bd83cb"}, "decimal": {:hex, :decimal, "3.2.0", "f1235f05d841a211fda78a08fdb9777f2ff51a71f18455233fae186ff76187c6", [:mix], [], "hexpm", "190bca80580ce61aa69bb0eacadd7677710205c770225c2c2c07e32a5c31b234"}, "dns_cluster": {:hex, :dns_cluster, "0.3.1", "b4e707e4ddaf0d3f13580ee7dc4ab0e685f7f7f5bbe90e84535524bc12d1cf3e", [:mix], [], "hexpm", "afa60bbbd84463e977eeeecc0c564d8c5ddea260beccdb8d5f45cbb860846627"}, diff --git a/test/browser/browser_features_test.exs b/test/browser/browser_features_test.exs index b5f435613..a0467bd33 100644 --- a/test/browser/browser_features_test.exs +++ b/test/browser/browser_features_test.exs @@ -2,5 +2,6 @@ Cucumber.compile_features!( features: ["test/browser/features/**/*.feature"], steps: ["test/browser/steps/**/*.exs"], support: ["test/browser/support/**/*.exs"], - case_template: HuddlzWeb.BrowserCase + case_template: HuddlzWeb.BrowserCase, + step_wrapper: {HuddlzWeb.BrowserCase, :wrap} ) diff --git a/test/browser/test_helper.exs b/test/browser/test_helper.exs index 8b2a26233..94292fd93 100644 --- a/test/browser/test_helper.exs +++ b/test/browser/test_helper.exs @@ -1,7 +1,5 @@ # Loaded only by mix test.browser. ExUnit.start(capture_log: true, max_cases: 1) Ecto.Adapters.SQL.Sandbox.mode(Huddlz.Repo, :manual) -# Set here, not in config: the fast Cucumber suite's steps are no Playwright tests. -Application.put_env(:cucumber, :step_wrapper, {HuddlzWeb.BrowserCase, :wrap}) System.put_env("PLAYWRIGHT_BROWSERS_PATH", Path.expand("_build/browser/browsers")) diff --git a/test/support/browser_case.ex b/test/support/browser_case.ex index 83ba3fcd0..96b269271 100644 --- a/test/support/browser_case.ex +++ b/test/support/browser_case.ex @@ -22,8 +22,8 @@ defmodule HuddlzWeb.BrowserCase do end @doc """ - Cucumber's step wrapper (`test/browser/test_helper.exs`): each Gherkin step - is a step in the trace, with its actions inside. + Cucumber's step wrapper (`test/browser/browser_features_test.exs`): each + Gherkin step is a step in the trace, with its actions inside. """ def wrap(step, _context, run), do: Playwright.Test.step("#{step.keyword} #{step.text}", run) end From 63399a1cbbe4d10221990b4fe12c2541ed0bbd54 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Wed, 25 Nov 2026 15:37:23 +0100 Subject: [PATCH 13/14] test(browser): bump Cucumber to the fork's latest playwright branch --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index c6bbb5e65..e7bcb44ee 100644 --- a/mix.lock +++ b/mix.lock @@ -29,7 +29,7 @@ "corsica": {:hex, :corsica, "2.1.3", "dccd094ffce38178acead9ae743180cdaffa388f35f0461ba1e8151d32e190e6", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "616c08f61a345780c2cf662ff226816f04d8868e12054e68963e95285b5be8bc"}, "credo": {:hex, :credo, "1.7.19", "cc52129665fc7c15143d47838fda0f9cd6dac9ceced7bf4da6f85fcbfe64b12a", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "2d8bc95d5a7bb99dd2613621d4f08c6a3575c3fd4b62e6a2b48a100352a557b8"}, "crux": {:hex, :crux, "0.1.5", "fe95455065e20f3c70a492beb16d3f477c20d659725d93525f932cac4304ad93", [:mix], [{:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: true]}], "hexpm", "56f4941d362a262a83e5f2ba4fae2173ac2f556a03b5b3965f58b6eb0aedbba3"}, - "cucumber": {:git, "https://github.com/ftes/cucumber.git", "d75ec0239b758d0c6e994b15f6a3ba5a50906381", [branch: "playwright"]}, + "cucumber": {:git, "https://github.com/ftes/cucumber.git", "9072141cb016458de20ef81b78d54848f65dda9c", [branch: "playwright"]}, "db_connection": {:hex, :db_connection, "2.10.3", "9d641d9cb56ed7cd03d0f5520b64f023f8c9a2531944991c952aa38e8afd5405", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ff441940bfd9ef5cced632e0e36d4ac823abeb9cae2767203fb9b4ccd1bd83cb"}, "decimal": {:hex, :decimal, "3.2.0", "f1235f05d841a211fda78a08fdb9777f2ff51a71f18455233fae186ff76187c6", [:mix], [], "hexpm", "190bca80580ce61aa69bb0eacadd7677710205c770225c2c2c07e32a5c31b234"}, "dns_cluster": {:hex, :dns_cluster, "0.3.1", "b4e707e4ddaf0d3f13580ee7dc4ab0e685f7f7f5bbe90e84535524bc12d1cf3e", [:mix], [], "hexpm", "afa60bbbd84463e977eeeecc0c564d8c5ddea260beccdb8d5f45cbb860846627"}, From 634a48475664acfe785f868f2807cd651ff1067e Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Thu, 26 Nov 2026 15:37:53 +0100 Subject: [PATCH 14/14] test(browser): upgrade Fluffy to 0.9.0-rc.7 --- lib/huddlz_web/hooks/allow_ecto_sandbox.ex | 2 +- mix.exs | 3 ++- mix.lock | 4 ++-- test/browser/steps/appearance_menu_steps.exs | 14 ++++-------- .../steps/calendar_day_sheet_steps.exs | 6 ++--- .../browser/steps/calendar_timezone_steps.exs | 8 +++---- test/browser/steps/copy_huddl_steps.exs | 2 +- test/browser/steps/cover_crop_steps.exs | 8 +++---- .../steps/cover_upload_progress_steps.exs | 12 +++++----- .../steps/discover_navigation_steps.exs | 6 ++--- .../steps/email_confirmation_steps.exs | 5 ++--- test/browser/steps/group_cover_steps.exs | 8 +++---- test/browser/steps/huddl_photos_steps.exs | 22 +++++++++---------- test/browser/steps/keyboard_focus_steps.exs | 13 +++++------ .../browser/steps/location_keyboard_steps.exs | 19 +++++++--------- test/browser/steps/member_menu_steps.exs | 12 +++++----- .../browser/steps/mobile_navigation_steps.exs | 11 ++-------- test/browser/steps/mobile_rsvp_steps.exs | 6 ++--- .../steps/notification_preferences_steps.exs | 4 ++-- .../steps/organizer_keyboard_steps.exs | 12 ++++------ test/browser/steps/overview_cards_steps.exs | 6 ++--- test/browser/steps/profile_picture_steps.exs | 12 +++++----- test/browser/steps/report_review_steps.exs | 6 ++--- test/browser/steps/share_links_steps.exs | 4 ++-- test/browser/steps/sidebar_scroll_steps.exs | 21 +++++++----------- test/browser/steps/sign_in_return_steps.exs | 9 ++++---- test/browser/steps/social_schedule_steps.exs | 4 ++-- 27 files changed, 101 insertions(+), 138 deletions(-) diff --git a/lib/huddlz_web/hooks/allow_ecto_sandbox.ex b/lib/huddlz_web/hooks/allow_ecto_sandbox.ex index 348e09196..c2ef11b0d 100644 --- a/lib/huddlz_web/hooks/allow_ecto_sandbox.ex +++ b/lib/huddlz_web/hooks/allow_ecto_sandbox.ex @@ -18,6 +18,6 @@ defmodule HuddlzWeb.Hooks.AllowEctoSandbox do if connected?(socket), do: get_connect_info(socket, :user_agent) end) - Sandbox.allow(metadata, Ecto.Adapters.SQL.Sandbox) + Sandbox.allow(metadata, Fluffy.Sandbox) end end diff --git a/mix.exs b/mix.exs index eecfdd365..45b338853 100644 --- a/mix.exs +++ b/mix.exs @@ -144,7 +144,8 @@ defmodule Huddlz.MixProject do {:mox, "~> 1.0", only: :test}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, {:phoenix_test, "~> 0.12", only: :test}, - {:fluffy, "~> 0.9.0-rc.6", only: :test}, + {:fluffy, "~> 0.9.0-rc.7", only: :test}, + {:playwright, "~> 1.65.0-rc.6", hex: :playwright_ex, only: :test}, {:slugify, "~> 1.3"}, {:remote_ip, "~> 1.1"}, {:envious, "~> 1.0"} diff --git a/mix.lock b/mix.lock index e7bcb44ee..6a39d95a9 100644 --- a/mix.lock +++ b/mix.lock @@ -47,7 +47,7 @@ "finch": {:hex, :finch, "0.25.0", "ce6203ff9464baf7d82e71b9568cf061ed640317e7e3449dac7601d220689d53", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.2.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9fd9a2c47a9033f4d70fad6e7d656948c08bc6652699de20e609a5917c0bb0a5"}, "fine": {:hex, :fine, "0.2.0", "71d9ff9fa69a4167cff1f6e9fd3350ab8e45d26b52f484c6d6514194b594df02", [:mix], [], "hexpm", "6f69a9e8dadbfd017b27f611b000362870683ae65f28aec904f36ec4c5058db5"}, "floki": {:hex, :floki, "0.38.5", "5786298f62ea266f9a8e88642753a8bc99925cd1ed7a7c8e420f6965ddbc7d1f", [:mix], [], "hexpm", "c8c5b04455f01b076cd489fee7dc26b49edf9851ef61146e743f4676114bf6b0"}, - "fluffy": {:hex, :fluffy, "0.9.0-rc.6", "13888b7971d50d5cb45a60aebd7d098a21b955d3591b230281bde00e0f9a1133", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:lazy_html, ">= 0.1.13 and < 1.0.0", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.10 and < 2.0.0-0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, ">= 4.6.6 and < 5.0.0-0", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 1.1.32 and < 2.0.0-0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:playwright, "~> 1.65.0-rc.5", [hex: :playwright_ex, repo: "hexpm", optional: false]}], "hexpm", "becf30d63bb18b319ee6ff32475634879aab6b7df9ec9e9c578733e8cebb6a49"}, + "fluffy": {:hex, :fluffy, "0.9.0-rc.7", "4e3baff1bb2b9829c02bfa0a2fbafba9608c34647947ea92b10c21b72a1626c1", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:lazy_html, ">= 0.1.13 and < 1.0.0", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.10 and < 2.0.0-0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, ">= 4.6.6 and < 5.0.0-0", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 1.1.32 and < 2.0.0-0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:playwright, "~> 1.65.0-rc.6", [hex: :playwright_ex, repo: "hexpm", optional: false]}], "hexpm", "0e8a1ac51578e595a9de2a8fb774fc9f7534977363cd21ba4ab29adbf454c4ad"}, "gettext": {:hex, :gettext, "1.0.2", "5457e1fd3f4abe47b0e13ff85086aabae760497a3497909b8473e0acee57673b", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "eab805501886802071ad290714515c8c4a17196ea76e5afc9d06ca85fb1bfeb3"}, "glob_ex": {:hex, :glob_ex, "0.1.12", "7b2d9369c20e2697efcfd185d13d6e84c94cd3bfd2730fbde613141c2e015c00", [:mix], [], "hexpm", "2e2fac83f113514434c7eaf267b4c38af2f91766f1cab2c5db7053b7fc1ee0bb"}, "hammer": {:hex, :hammer, "7.6.0", "6eb6239dc874d66cb289ee1816872f8c9366b8e21c6a1bac9120010a50c6db57", [:mix], [{:igniter, "~> 0.8", [hex: :igniter, repo: "hexpm", optional: true]}], "hexpm", "5777d22a2f96e53e489aa5a31aee73fe082da78464be52a688521772f96a934a"}, @@ -88,7 +88,7 @@ "phoenix_test": {:hex, :phoenix_test, "0.14.0", "3fef4f78a3438cc398a0884cc7370f9c9a0afdbd9d70b8bd362837cd61943ffe", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:lazy_html, "~> 0.1.7", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:mime, ">= 1.0.0", [hex: :mime, repo: "hexpm", optional: true]}, {:phoenix, ">= 1.7.10", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "0d090b0b6deb4193797f7bee8f19ecabdc4bb4000db51ccd140dded0b2d57be3"}, "phoenix_view": {:hex, :phoenix_view, "2.0.4", "b45c9d9cf15b3a1af5fb555c674b525391b6a1fe975f040fb4d913397b31abf4", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "4e992022ce14f31fe57335db27a28154afcc94e9983266835bb3040243eb620b"}, "picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"}, - "playwright": {:hex, :playwright_ex, "1.65.0-rc.5", "55f43c8b0f2c18a698712450a0769c4f9f9ef564be8ce92dfba58fadf3dbb172", [:mix], [], "hexpm", "84687be548278c3d7056614b5d4ad269c94d877534a006cc64bb45ff06829aee"}, + "playwright": {:hex, :playwright_ex, "1.65.0-rc.6", "791ea0c42906accab3a3a57a98bda9e1db1142fef4e8a8a72eeeb6624a92f8fb", [:mix], [], "hexpm", "a10a17d40fb16c93036eb95f824cc5e205bfb226755969704f6b1eeaa14ec282"}, "plug": {:hex, :plug, "1.20.4", "8fca521b31eb586dbb91968dd9fa95be6b60fb40f9ca77b005361e06836aed75", [: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", "96ee42c0b8b35bcb14e3e65afb85abe9bb7745a8576e8c602802bbb01e5acf72"}, "plug_crypto": {:hex, :plug_crypto, "2.2.1", "bd1d0358a2e2f5ffb818217e64c394f9d24ed191d862b7fa1bcce264ace2b8ea", [:mix], [], "hexpm", "4417ccbd8f85e627321cd07d2ab9c4b621f1fd883b9905af241f9b4b780b94b6"}, "postgrex": {:hex, :postgrex, "0.23.0", "f106e1429559f0db8799c250279ee5fa16e364a39380cd9523e725df3625b235", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "f001ab3fd56f5ef2b8b3cd4a512005614fcaeccca068ddb29e57d338a7f104ec"}, diff --git a/test/browser/steps/appearance_menu_steps.exs b/test/browser/steps/appearance_menu_steps.exs index 5aa43482b..34575d72c 100644 --- a/test/browser/steps/appearance_menu_steps.exs +++ b/test/browser/steps/appearance_menu_steps.exs @@ -10,7 +10,7 @@ defmodule BrowserAppearanceMenuSteps do step "I open the appearance menu with the keyboard", %{session: session} do session |> press(trigger(), "Enter") - |> assert(visible(open_menu())) + |> assert_has(open_menu()) :ok end @@ -26,7 +26,7 @@ defmodule BrowserAppearanceMenuSteps do step "the page uses the dark appearance and the menu is closed", %{session: session} do session |> assert(attribute(by_css("html"), "data-theme", "dark")) - |> refute(visible(open_menu())) + |> refute_has(open_menu()) :ok end @@ -38,7 +38,7 @@ defmodule BrowserAppearanceMenuSteps do step "the menu is closed and focus is back on its trigger", %{session: session} do session - |> refute(visible(open_menu())) + |> refute_has(open_menu()) |> assert(focused(trigger())) :ok @@ -55,13 +55,7 @@ defmodule BrowserAppearanceMenuSteps do defp tab_to_option(session, label, tries) do session = Keyboard.press(session, "Tab") - - focused = - Fluffy.Playwright.evaluate( - session, - "document.activeElement.querySelector('.theme-option-label')?.textContent" - ) - + focused = text_content(session, by_css(":focus .theme-option-label")) if focused == label, do: session, else: tab_to_option(session, label, tries - 1) end end diff --git a/test/browser/steps/calendar_day_sheet_steps.exs b/test/browser/steps/calendar_day_sheet_steps.exs index d009843fc..fd68ead26 100644 --- a/test/browser/steps/calendar_day_sheet_steps.exs +++ b/test/browser/steps/calendar_day_sheet_steps.exs @@ -67,7 +67,7 @@ defmodule BrowserCalendarDaySheetSteps do step "the day sheet is docked to the bottom edge and lists {string}", %{args: [title], session: session} do session - |> assert(visible(entry(title))) + |> assert_has(entry(title)) |> assert_browser(""" (() => { const sheet = document.querySelector('#calendar-day-panel'); @@ -86,7 +86,7 @@ defmodule BrowserCalendarDaySheetSteps do step "I open {string} from the sheet and go back", %{args: [title], session: session} do session |> click(entry(title)) - |> assert(visible(by_role(:heading, level: 1, name: title))) + |> assert_has(by_role(:heading, level: 1, name: title)) |> Fluffy.Playwright.go_back() :ok @@ -101,7 +101,7 @@ defmodule BrowserCalendarDaySheetSteps do text(by_role(day_panel(), :heading, level: 2), Calendar.strftime(context.day, "%B %-d")) ) |> assert(page_url(&(URI.decode_query(&1.query || "")["day"] == day))) - |> assert(visible(by_css("#month-calendar"))) + |> assert_has(by_css("#month-calendar")) |> assert_browser("Math.abs(scrollY - Number(sessionStorage.getItem('calendar-scroll'))) < 2") :ok diff --git a/test/browser/steps/calendar_timezone_steps.exs b/test/browser/steps/calendar_timezone_steps.exs index 65d1b2597..ffc40d4dc 100644 --- a/test/browser/steps/calendar_timezone_steps.exs +++ b/test/browser/steps/calendar_timezone_steps.exs @@ -57,11 +57,9 @@ defmodule BrowserCalendarSteps do session |> assert(text(by_css("#calendar-time-zone"), "America/New_York")) - |> assert( - visible( - by_css(day, "#calendar-entry-#{context.huddl.id} .cal-pill-time") - |> filter(has_text: "11:30 PM MDT") - ) + |> assert_has( + by_css(day, "#calendar-entry-#{context.huddl.id} .cal-pill-time") + |> filter(has_text: "11:30 PM MDT") ) :ok diff --git a/test/browser/steps/copy_huddl_steps.exs b/test/browser/steps/copy_huddl_steps.exs index a1066edbe..c78901c99 100644 --- a/test/browser/steps/copy_huddl_steps.exs +++ b/test/browser/steps/copy_huddl_steps.exs @@ -15,7 +15,7 @@ defmodule BrowserCopyHuddlSteps do session |> sign_in(owner) |> visit("/groups/#{group.slug}/huddlz/new?copy=#{huddl.id}") - |> assert(visible(by_role(:heading, level: 2, name: "Copied from"))) + |> assert_has(by_role(:heading, level: 2, name: "Copied from")) :ok end diff --git a/test/browser/steps/cover_crop_steps.exs b/test/browser/steps/cover_crop_steps.exs index 3e416ddfc..ad5947851 100644 --- a/test/browser/steps/cover_crop_steps.exs +++ b/test/browser/steps/cover_crop_steps.exs @@ -21,7 +21,7 @@ defmodule BrowserCoverCropSteps do session |> sign_in(owner) |> visit("/groups/new") - |> assert(visible(by_css("#group-cover-upload[data-state=idle]"))) + |> assert_has(by_css("#group-cover-upload[data-state=idle]")) :ok end @@ -101,7 +101,7 @@ defmodule BrowserCoverCropSteps do return Math.abs(pic.bottom - win.bottom) < 1; })() """) - |> assert(visible(by_role(:button, name: "Reset"))) + |> assert_has(by_role(:button, name: "Reset")) |> click(by_role(:button, name: "Use photo")) :ok @@ -113,8 +113,8 @@ defmodule BrowserCoverCropSteps do by_css("#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']") session - |> refute(visible(by_css("#group-cover-upload-crop[open]"))) - |> assert(visible(cover)) + |> refute_has(by_css("#group-cover-upload-crop[open]")) + |> assert_has(cover) thumbnail_path = get_attribute(session, cover, "src") diff --git a/test/browser/steps/cover_upload_progress_steps.exs b/test/browser/steps/cover_upload_progress_steps.exs index e26c31533..3bd16c9b2 100644 --- a/test/browser/steps/cover_upload_progress_steps.exs +++ b/test/browser/steps/cover_upload_progress_steps.exs @@ -28,7 +28,7 @@ defmodule BrowserCoverUploadSteps do session |> sign_in(owner) |> visit("/groups/new") - |> assert(visible(by_css("#group-cover-upload[data-state=idle]"))) + |> assert_has(by_css("#group-cover-upload[data-state=idle]")) |> assert_browser(""" (() => { const slot = document.querySelector('#group-cover-upload .cover-slot').getBoundingClientRect(); @@ -45,7 +45,7 @@ defmodule BrowserCoverUploadSteps do # The crop sheet opens first; the picture already fits, so use it as is. session |> set_input_files(by_label("Cover image", exact: true), "test/fixtures/test_image.jpg") - |> assert(visible(by_css("#group-cover-upload-crop[open]"))) + |> assert_has(by_css("#group-cover-upload-crop[open]")) |> click(by_role(:button, name: "Use photo")) :ok @@ -72,17 +72,15 @@ defmodule BrowserCoverUploadSteps do """) # Typing while the cover is prepared must work. |> fill(by_label("Group name", exact: true), "Typed while uploading") - |> assert(visible(by_css("#group-cover-upload[data-state=uploading]"))) + |> assert_has(by_css("#group-cover-upload[data-state=uploading]")) :ok end step "the slot settles on the prepared cover without moving", %{session: session} do session - |> assert( - visible( - by_css("#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']") - ) + |> assert_has( + by_css("#group-cover-upload[data-state=uploaded] .cover-slot img[src*='group_images']") ) |> assert_browser(""" (() => { diff --git a/test/browser/steps/discover_navigation_steps.exs b/test/browser/steps/discover_navigation_steps.exs index a5c0c0cd8..4f56b350b 100644 --- a/test/browser/steps/discover_navigation_steps.exs +++ b/test/browser/steps/discover_navigation_steps.exs @@ -31,7 +31,7 @@ defmodule BrowserDiscoverNavigationSteps do session |> sign_in(member) |> visit("/agenda") - |> assert(visible(by_role(:heading, level: 1, name: "Agenda"))) + |> assert_has(by_role(:heading, level: 1, name: "Agenda")) %{member: member} end @@ -44,8 +44,8 @@ defmodule BrowserDiscoverNavigationSteps do step "the discover results arrive without a page load", %{session: session} = context do session - |> assert(visible(by_role(:heading, level: 1, name: "Browse huddlz"))) - |> assert(visible(by_role(:heading, level: 3, name: context.huddl.title))) + |> assert_has(by_role(:heading, level: 1, name: "Browse huddlz")) + |> assert_has(by_role(:heading, level: 3, name: context.huddl.title)) |> assert(count(by_css(".grid-skeleton") |> filter(visible: true), 0)) |> assert_browser("window.__huddlzPage === 'kept'") diff --git a/test/browser/steps/email_confirmation_steps.exs b/test/browser/steps/email_confirmation_steps.exs index ecc26d6e8..e1bc28380 100644 --- a/test/browser/steps/email_confirmation_steps.exs +++ b/test/browser/steps/email_confirmation_steps.exs @@ -27,7 +27,7 @@ defmodule BrowserEmailConfirmationSteps do end step "a confirmation email is sent to my current address", %{session: session} = context do - assert(session, visible(alert("Confirmation sent to"))) + assert_has(session, alert("Confirmation sent to")) email = to_string(context.member.email) assert_email_sent(fn sent -> @@ -40,10 +40,9 @@ defmodule BrowserEmailConfirmationSteps do step "I can still save my display name", %{session: session} do session - |> assert(visible(by_css("body .phx-connected") |> first())) |> fill(by_label("Display name", exact: true), "Confirmation Reviewer") |> click(by_role(:button, name: "Save changes")) - |> assert(visible(alert("Display name updated successfully"))) + |> assert_has(alert("Display name updated successfully")) |> visit("/profile") |> assert(value(by_label("Display name", exact: true), "Confirmation Reviewer")) diff --git a/test/browser/steps/group_cover_steps.exs b/test/browser/steps/group_cover_steps.exs index 8b5aea0f3..95dcdc380 100644 --- a/test/browser/steps/group_cover_steps.exs +++ b/test/browser/steps/group_cover_steps.exs @@ -53,7 +53,7 @@ defmodule BrowserCoverSteps do step "I open that group in the browser", %{session: session} = context do session |> visit("/groups/#{context.group.slug}") - |> assert(visible(by_role(:heading, level: 1, name: to_string(context.group.name)))) + |> assert_has(by_role(:heading, level: 1, name: to_string(context.group.name))) :ok end @@ -109,12 +109,12 @@ defmodule BrowserCoverSteps do defp assert_cover(session, "missing") do session - |> refute(visible(cover_image())) + |> refute_has(cover_image()) |> assert_fallback() end defp assert_cover(session, state) do - assert(session, visible(cover_image())) + assert_has(session, cover_image()) decoded = Fluffy.Playwright.evaluate(session, """ @@ -163,7 +163,7 @@ defmodule BrowserCoverSteps do defp assert_fallback(session) do session - |> assert(visible(by_css("#group-detail-hero .group-cover-signal"))) + |> assert_has(by_css("#group-detail-hero .group-cover-signal")) |> assert_browser(""" (() => { const cover = document.querySelector('#group-detail-hero .group-cover'); diff --git a/test/browser/steps/huddl_photos_steps.exs b/test/browser/steps/huddl_photos_steps.exs index 6227740f7..3373126cd 100644 --- a/test/browser/steps/huddl_photos_steps.exs +++ b/test/browser/steps/huddl_photos_steps.exs @@ -38,10 +38,10 @@ defmodule BrowserPhotoSteps do step "I can upload the valid photo and understand why the other was skipped", %{session: session} do session - |> assert(visible(upload_error("Each photo must be 5 MB or smaller."))) + |> assert_has(upload_error("Each photo must be 5 MB or smaller.")) |> click(upload_button()) |> assert(count(tiles(), 1)) - |> assert(visible(by_css("#flash-info") |> filter(has_text: "Photos uploaded."))) + |> assert_has(by_css("#flash-info") |> filter(has_text: "Photos uploaded.")) |> assert_browser( "[...document.querySelectorAll('.photo-tile img')].every(i => i.complete && i.naturalWidth > 0)" ) @@ -59,9 +59,9 @@ defmodule BrowserPhotoSteps do step "I am told to choose a supported image instead of retrying it", %{session: session} do session - |> assert(visible(upload_error("corrupt_image.jpg: Choose a JPG, PNG, or WebP image."))) + |> assert_has(upload_error("corrupt_image.jpg: Choose a JPG, PNG, or WebP image.")) |> assert(count(tiles(), 0)) - |> refute(visible(by_css("#flash-error") |> filter(has_text: "Please try again."))) + |> refute_has(by_css("#flash-error") |> filter(has_text: "Please try again.")) :ok end @@ -85,9 +85,9 @@ defmodule BrowserPhotoSteps do step "the upload queue names each photo and its remove control", %{session: session} do session - |> assert(visible(by_css(".photo-upload-entry") |> filter(has_text: "test_image.jpg"))) - |> assert(visible(by_role(:button, name: "Remove test_image.jpg", exact: true))) - |> assert(visible(by_role(:button, name: "Remove icon-512.png", exact: true))) + |> assert_has(by_css(".photo-upload-entry") |> filter(has_text: "test_image.jpg")) + |> assert_has(by_role(:button, name: "Remove test_image.jpg", exact: true)) + |> assert_has(by_role(:button, name: "Remove icon-512.png", exact: true)) :ok end @@ -126,9 +126,7 @@ defmodule BrowserPhotoSteps do position = by_css("#photo-position") session - |> assert( - visible(by_role(by_css("#photo-lightbox"), :dialog) |> filter(has_text: "Sam Rivera")) - ) + |> assert_has(by_role(by_css("#photo-lightbox"), :dialog) |> filter(has_text: "Sam Rivera")) |> assert(text(position, "1 of 2")) |> Keyboard.press("ArrowRight") |> assert(text(position, "2 of 2")) @@ -192,8 +190,8 @@ defmodule BrowserPhotoSteps do dialog = by_role(by_css("#delete-photo-modal"), :dialog) session - |> assert(visible(by_css("#delete-photo-modal img"))) - |> assert(visible(dialog |> filter(has_text: "Sam Rivera"))) + |> assert_has(by_css("#delete-photo-modal img")) + |> assert_has(dialog |> filter(has_text: "Sam Rivera")) |> Keyboard.press("Enter") |> assert(count(dialog, 0)) |> assert(count(tiles(), 2)) diff --git a/test/browser/steps/keyboard_focus_steps.exs b/test/browser/steps/keyboard_focus_steps.exs index a4628a113..9ef2e5c67 100644 --- a/test/browser/steps/keyboard_focus_steps.exs +++ b/test/browser/steps/keyboard_focus_steps.exs @@ -43,7 +43,7 @@ defmodule BrowserKeyboardFocusSteps do step "{string} still has keyboard focus", %{args: [name], session: session} = context do # Let the save's reply land before looking. session - |> assert(visible(by_css(context.focus_form <> ":not(.phx-submit-loading)"))) + |> assert_has(by_css(context.focus_form <> ":not(.phx-submit-loading)")) |> assert_focused(name) :ok @@ -94,7 +94,7 @@ defmodule BrowserKeyboardFocusSteps do invitee = generate(user(role: :user)) email = to_string(invitee.email) save_with(context, "Email", email) - assert(context.session, visible(flash_info("Invitation sent to #{email}."))) + assert_has(context.session, flash_info("Invitation sent to #{email}.")) save_with(context, "Email", email) end @@ -110,7 +110,7 @@ defmodule BrowserKeyboardFocusSteps do step "I clear the group location and save", %{session: session} do session |> click(by_role(by_css("#group-location"), :button, name: "Clear")) - |> assert(visible(by_css("#group-location-input"))) + |> assert_has(by_css("#group-location-input")) |> press(by_css("#edit-group-form button[type=submit]"), "Enter") :ok @@ -136,10 +136,7 @@ defmodule BrowserKeyboardFocusSteps do session |> assert_focused(Huddlz.Legal.acceptance_text()) |> assert(attribute(focused_field(), "aria-invalid", "true")) - |> assert_browser(""" - (document.activeElement.getAttribute('aria-describedby') || '').split(/\\s+/).some(id => - document.getElementById(id)?.textContent.includes('accept')) - """) + |> assert(accessible_description(focused_field(), ~r/accept/)) :ok end @@ -235,7 +232,7 @@ defmodule BrowserKeyboardFocusSteps do context.session |> fill(search, "saint") - |> assert(visible(by_role(:option) |> first())) + |> assert_has(by_role(:option) |> first()) |> press(search, "ArrowDown") |> assert(attribute(by_css("#modal-address-autocomplete"), "data-has-highlight", "true")) |> press(search, "Enter") diff --git a/test/browser/steps/location_keyboard_steps.exs b/test/browser/steps/location_keyboard_steps.exs index fe92e5284..6a1abe99e 100644 --- a/test/browser/steps/location_keyboard_steps.exs +++ b/test/browser/steps/location_keyboard_steps.exs @@ -17,15 +17,12 @@ defmodule BrowserLocationKeyboardSteps do session |> sign_in(member) |> visit("/profile") - |> assert(visible(by_role(:heading, level: 1, name: "Profile"))) + |> assert_has(by_role(:heading, level: 1, name: "Profile")) - assert Fluffy.Playwright.evaluate(session, """ - (() => { - window.observedSubmissions = 0; - document.addEventListener('submit', () => window.observedSubmissions++, true); - return true; - })() - """) + Fluffy.Playwright.evaluate(session, """ + window.observedSubmissions = 0; + document.addEventListener('submit', () => window.observedSubmissions++, true); + """) ExUnit.Callbacks.on_exit(fn -> File.rm_rf!("priv/static/uploads/profile_pictures/#{member.id}") @@ -37,7 +34,7 @@ defmodule BrowserLocationKeyboardSteps do step "I type {string} into my home location", %{args: [query], session: session} do session |> Fluffy.Playwright.press_sequentially(home_location(), query) - |> assert(visible(by_role(:option) |> first())) + |> assert_has(by_role(:option) |> first()) :ok end @@ -57,8 +54,8 @@ defmodule BrowserLocationKeyboardSteps do step "my home location is {string}", %{args: [location], session: session} do session - |> assert(visible(by_test_id("location-selected") |> filter(has_text: location))) - |> assert(visible(by_role(:alert) |> filter(has_text: "Home location updated"))) + |> assert_has(by_test_id("location-selected") |> filter(has_text: location)) + |> assert_has(by_role(:alert) |> filter(has_text: "Home location updated")) :ok end diff --git a/test/browser/steps/member_menu_steps.exs b/test/browser/steps/member_menu_steps.exs index 520de3540..a3d8c9720 100644 --- a/test/browser/steps/member_menu_steps.exs +++ b/test/browser/steps/member_menu_steps.exs @@ -23,7 +23,7 @@ defmodule BrowserMemberMenuSteps do session |> sign_in(owner) |> visit("/organize/#{group.slug}/members") - |> assert(visible(by_role(:heading, level: 1, name: "Members"))) + |> assert_has(by_role(:heading, level: 1, name: "Members")) %{owner: owner, member: member, group: group} end @@ -31,7 +31,7 @@ defmodule BrowserMemberMenuSteps do step "I open the menu for {string} with the keyboard", %{args: [name], session: session} do session |> press(trigger(name), "Enter") - |> assert(visible(menu(name))) + |> assert_has(menu(name)) %{menu_name: name} end @@ -47,7 +47,7 @@ defmodule BrowserMemberMenuSteps do step "the member menu is closed and focus is back on its button", %{session: session, menu_name: name} do session - |> refute(visible(menu(name))) + |> refute_has(menu(name)) |> assert(focused(trigger(name))) :ok @@ -56,8 +56,8 @@ defmodule BrowserMemberMenuSteps do step "the promotion confirmation is open and the menu is closed", %{session: session, menu_name: name} do session - |> assert(visible(by_role(:dialog) |> filter(has_text: "Promote #{name}?"))) - |> refute(visible(menu(name))) + |> assert_has(by_role(:dialog) |> filter(has_text: "Promote #{name}?")) + |> refute_has(menu(name)) :ok end @@ -73,7 +73,7 @@ defmodule BrowserMemberMenuSteps do defp tab_to_item(session, label, tries) do session = Keyboard.press(session, "Tab") - focused = Fluffy.Playwright.evaluate(session, "document.activeElement.textContent.trim()") + focused = session |> text_content(by_css(":focus")) |> String.trim() if focused == label, do: session, else: tab_to_item(session, label, tries - 1) end end diff --git a/test/browser/steps/mobile_navigation_steps.exs b/test/browser/steps/mobile_navigation_steps.exs index 163f221f8..43b4bad4e 100644 --- a/test/browser/steps/mobile_navigation_steps.exs +++ b/test/browser/steps/mobile_navigation_steps.exs @@ -4,7 +4,6 @@ defmodule BrowserNavigationSteps do import Fluffy, except: [step: 3] import Fluffy.Locator - import Huddlz.Test.BrowserHelpers alias Fluffy.Playwright.Keyboard @@ -28,12 +27,7 @@ defmodule BrowserNavigationSteps do |> assert(focused(by_role(:link, name: "View profile"))) |> Keyboard.press("Tab") |> assert(focused(home)) - |> assert_browser(""" - (() => { - const drawer = document.querySelector('#mobile-navigation-drawer').getBoundingClientRect(); - return drawer.left >= 0 && drawer.right <= innerWidth; - })() - """) + |> assert(in_viewport(drawer(), ratio: 1)) :ok end @@ -65,8 +59,7 @@ defmodule BrowserNavigationSteps do step "Groups loads with the drawer closed and can reopen navigation", %{session: session} do session - |> assert(visible(by_role(:heading, level: 1, name: "Groups"))) - |> assert(visible(by_css(".phx-connected") |> first())) + |> assert_has(by_role(:heading, level: 1, name: "Groups")) |> assert(inert(drawer())) |> refute(inert(background())) |> press(trigger(), "Enter") diff --git a/test/browser/steps/mobile_rsvp_steps.exs b/test/browser/steps/mobile_rsvp_steps.exs index c1fed1af8..eaf584f38 100644 --- a/test/browser/steps/mobile_rsvp_steps.exs +++ b/test/browser/steps/mobile_rsvp_steps.exs @@ -77,10 +77,8 @@ defmodule BrowserMobileRsvpSteps do step "the dock shows I am attending and offers to cancel", %{session: session} do session - |> assert( - visible(by_css(dock(), ".rsvp-banner.cyan") |> filter(has_text: "You're attending")) - ) - |> assert(visible(by_role(dock(), :button, name: "Cancel RSVP"))) + |> assert_has(by_css(dock(), ".rsvp-banner.cyan") |> filter(has_text: "You're attending")) + |> assert_has(by_role(dock(), :button, name: "Cancel RSVP")) |> assert_browser(""" (() => { const dock = document.querySelector('.rsvp-state[data-dock]').getBoundingClientRect(); diff --git a/test/browser/steps/notification_preferences_steps.exs b/test/browser/steps/notification_preferences_steps.exs index 60dbee9ed..8d66900d8 100644 --- a/test/browser/steps/notification_preferences_steps.exs +++ b/test/browser/steps/notification_preferences_steps.exs @@ -13,7 +13,7 @@ defmodule BrowserNotificationPreferencesSteps do session |> sign_in(member) |> visit("/profile/notifications") - |> assert(visible(by_role(:heading, level: 1, name: "Notifications"))) + |> assert_has(by_role(:heading, level: 1, name: "Notifications")) %{member: member} end @@ -31,7 +31,7 @@ defmodule BrowserNotificationPreferencesSteps do end step "the row says the change could not be saved", %{session: session} do - assert(session, visible(by_role(:alert) |> filter(has_text: "Couldn't save"))) + assert_has(session, by_role(:alert) |> filter(has_text: "Couldn't save")) :ok end diff --git a/test/browser/steps/organizer_keyboard_steps.exs b/test/browser/steps/organizer_keyboard_steps.exs index 897cf4e30..1746504d4 100644 --- a/test/browser/steps/organizer_keyboard_steps.exs +++ b/test/browser/steps/organizer_keyboard_steps.exs @@ -36,10 +36,8 @@ defmodule BrowserOrganizerSteps do session |> assert(checked(virtual)) |> assert(attached(focus_visible(virtual))) - |> assert(visible(by_label("Online link", exact: true))) - |> assert_browser(""" - getComputedStyle(document.querySelector('#event-type-virtual').closest('.event-type-option')).outlineStyle !== 'none' - """) + |> assert_has(by_label("Online link", exact: true)) + |> refute(css(by_css(".event-type-option") |> filter(has: virtual), "outline-style", "none")) :ok end @@ -52,7 +50,7 @@ defmodule BrowserOrganizerSteps do |> assert(checked(recurring())) |> assert(attached(focus_visible(recurring()))) |> assert(attribute(recurring(), "aria-checked", "true")) - |> assert(visible(by_label("Frequency", exact: true))) + |> assert_has(by_label("Frequency", exact: true)) |> press(by_label("Max attendees", exact: true), "Tab") |> assert(focused(members_only())) |> Keyboard.press("Space") @@ -68,9 +66,7 @@ defmodule BrowserOrganizerSteps do |> assert(checked(members_only())) |> assert(attached(focus_visible(members_only()))) |> assert(attribute(members_only(), "aria-checked", "true")) - |> assert_browser(""" - getComputedStyle(document.querySelector('input[name="form[is_private]"] + .track')).boxShadow !== 'none' - """) + |> refute(css(by_css("input[name='form[is_private]'] + .track"), "box-shadow", "none")) :ok end diff --git a/test/browser/steps/overview_cards_steps.exs b/test/browser/steps/overview_cards_steps.exs index da02b5062..12a0c5472 100644 --- a/test/browser/steps/overview_cards_steps.exs +++ b/test/browser/steps/overview_cards_steps.exs @@ -38,7 +38,7 @@ defmodule BrowserOverviewCardsSteps do session |> sign_in(owner) |> visit("/organize/#{group.slug}") - |> assert(visible(by_css("#turnout-nudge") |> filter(has_text: "Elixir office hours"))) + |> assert_has(by_css("#turnout-nudge") |> filter(has_text: "Elixir office hours")) %{group: group} end @@ -53,7 +53,7 @@ defmodule BrowserOverviewCardsSteps do |> click(by_role(by_css("#turnout-nudge"), :button, name: "Add turnout")) |> fill(by_label("People in the room", exact: true), 6) |> click(by_role(:button, name: "Save turnout")) - |> assert(visible(by_css("#flash-info") |> filter(has_text: "Turnout saved"))) + |> assert_has(by_css("#flash-info") |> filter(has_text: "Turnout saved")) :ok end @@ -62,7 +62,7 @@ defmodule BrowserOverviewCardsSteps do %{session: session} do session |> assert(text(by_css("#kpi-showrate .value"), "50%")) - |> assert(visible(by_css("#spark-showrate:not([data-empty])"))) + |> assert_has(by_css("#spark-showrate:not([data-empty])")) |> assert_same_height() :ok diff --git a/test/browser/steps/profile_picture_steps.exs b/test/browser/steps/profile_picture_steps.exs index 5ceaa41fd..0a853bfcf 100644 --- a/test/browser/steps/profile_picture_steps.exs +++ b/test/browser/steps/profile_picture_steps.exs @@ -13,9 +13,9 @@ defmodule BrowserPictureSteps do # The crop sheet opens first; the picture is used as it is. session |> set_input_files(by_label("Upload a photo…", exact: true), "test/fixtures/test_image.jpg") - |> assert(visible(by_css("#avatar-upload-crop[open]"))) + |> assert_has(by_css("#avatar-upload-crop[open]")) |> click(by_role(:button, name: "Use photo")) - |> assert(visible(remove())) + |> assert_has(remove()) :ok end @@ -42,7 +42,7 @@ defmodule BrowserPictureSteps do step "I open the remove picture confirmation by clicking Remove", %{session: session} do session |> click(remove()) - |> assert(visible(dialog())) + |> assert_has(dialog()) :ok end @@ -71,9 +71,9 @@ defmodule BrowserPictureSteps do step "my profile picture is replaced by initials", %{session: session} do session |> assert(count(dialog(), 0)) - |> assert(visible(by_role(:alert) |> filter(has_text: "Profile picture removed"))) + |> assert_has(by_role(:alert) |> filter(has_text: "Profile picture removed")) |> assert(count(by_css("img.big-avatar"), 0)) - |> assert(visible(by_css("main .big-avatar") |> filter(has_text: "BM"))) + |> assert_has(by_css("main .big-avatar") |> filter(has_text: "BM")) :ok end @@ -103,7 +103,7 @@ defmodule BrowserPictureSteps do session |> assert(count(dialog(), 0)) |> assert(focused(remove())) - |> assert(visible(by_css("img.big-avatar"))) + |> assert_has(by_css("img.big-avatar")) :ok end diff --git a/test/browser/steps/report_review_steps.exs b/test/browser/steps/report_review_steps.exs index 7e250b7ed..6ae1b1c5c 100644 --- a/test/browser/steps/report_review_steps.exs +++ b/test/browser/steps/report_review_steps.exs @@ -46,8 +46,8 @@ defmodule BrowserReportReviewSteps do step "the reopened report is ready for review", %{session: session} do session - |> assert(visible(review_card() |> filter(has_text: "Repeated advertisements"))) - |> assert(visible(by_role(review_card(), :button, name: "Mark handled"))) + |> assert_has(review_card() |> filter(has_text: "Repeated advertisements")) + |> assert_has(by_role(review_card(), :button, name: "Mark handled")) |> assert(count(by_role(:button, name: "Suspend account"), 0)) |> assert(page_url(&(not Map.has_key?(URI.decode_query(&1.query || ""), "account_id")))) @@ -58,7 +58,7 @@ defmodule BrowserReportReviewSteps do session |> visit("/admin/users?scope=suspended") |> click(review()) - |> assert(visible(by_role(review_card(), :link, name: "1 open report"))) + |> assert_has(by_role(review_card(), :link, name: "1 open report")) :ok end diff --git a/test/browser/steps/share_links_steps.exs b/test/browser/steps/share_links_steps.exs index 93379748a..7be4e7a35 100644 --- a/test/browser/steps/share_links_steps.exs +++ b/test/browser/steps/share_links_steps.exs @@ -41,7 +41,7 @@ defmodule BrowserShareLinksSteps do step "the Share section confirms the address was copied", %{session: session} do session - |> assert(visible(share_actions() |> filter(has_text: "Copied!"))) + |> assert_has(share_actions() |> filter(has_text: "Copied!")) |> assert(focused(by_role(share_actions(), :button, name: "Copied!"))) :ok @@ -57,7 +57,7 @@ defmodule BrowserShareLinksSteps do step "the QR code dialog confirms the address was copied", %{session: session} do session - |> assert(visible(by_role(:dialog) |> filter(has_text: "Copied!"))) + |> assert_has(by_role(:dialog) |> filter(has_text: "Copied!")) |> assert(focused(by_role(by_role(:dialog), :button, name: "Copied!"))) :ok diff --git a/test/browser/steps/sidebar_scroll_steps.exs b/test/browser/steps/sidebar_scroll_steps.exs index 8be265464..178ba1eb7 100644 --- a/test/browser/steps/sidebar_scroll_steps.exs +++ b/test/browser/steps/sidebar_scroll_steps.exs @@ -25,7 +25,7 @@ defmodule BrowserSidebarScrollSteps do session |> sign_in(member) |> visit("/agenda") - |> assert(visible(by_css(".sb-org-row") |> filter(has_text: "Overflow group 14"))) + |> assert_has(by_css(".sb-org-row") |> filter(has_text: "Overflow group 14")) %{member: member} end @@ -62,7 +62,7 @@ defmodule BrowserSidebarScrollSteps do Enum.find(1..60, fn _n -> session |> Keyboard.press("Tab") - |> Fluffy.Playwright.evaluate("document.activeElement.id === 'sign-out-link'") + |> get_attribute(by_css(":focus"), "id") == "sign-out-link" end) assert(session, focused(by_css("#sign-out-link"))) @@ -111,7 +111,7 @@ defmodule BrowserSidebarScrollSteps do step "the page behind the sidebar has not moved and is still usable", %{session: session} do session - |> assert(visible(by_role(by_css("main"), :heading, level: 1, name: "Agenda"))) + |> assert_has(by_role(by_css("main"), :heading, level: 1, name: "Agenda")) |> assert_browser(""" window.scrollY === 0 && !document.querySelector('main').inert && document.querySelector('main').getBoundingClientRect().left > 0 @@ -124,18 +124,13 @@ defmodule BrowserSidebarScrollSteps do # partly below the fold has its centre off the page, where a wheel reaches # nothing. defp wheel_over(session, locator, delta_y) do - %{"x" => x, "y" => y} = - Fluffy.Playwright.evaluate(session, locator, """ - element => { - const r = element.getBoundingClientRect(); - const top = Math.max(r.top, 0); - const bottom = Math.min(r.bottom, window.innerHeight); - return {x: r.left + r.width / 2, y: (top + bottom) / 2}; - } - """) + box = Fluffy.Playwright.bounding_box(session, locator) + %{height: height} = Fluffy.Playwright.viewport_size(session) + top = max(box.y, 0) + bottom = min(box.y + box.height, height) session - |> Mouse.move(x, y) + |> Mouse.move(box.x + box.width / 2, (top + bottom) / 2) |> Mouse.wheel(0, delta_y) end end diff --git a/test/browser/steps/sign_in_return_steps.exs b/test/browser/steps/sign_in_return_steps.exs index a45912fdb..7aa402460 100644 --- a/test/browser/steps/sign_in_return_steps.exs +++ b/test/browser/steps/sign_in_return_steps.exs @@ -36,11 +36,10 @@ defmodule BrowserSignInReturnSteps do session |> click(by_role(:link, name: "Forgot your password?")) - |> assert(visible(by_role(:heading, level: 1, name: "Reset your password"))) - |> assert(visible(by_css(".phx-connected") |> first())) + |> assert_has(by_role(:heading, level: 1, name: "Reset your password")) |> fill(by_label("Email", exact: true), email) |> click(by_role(:button, name: "Send reset instructions")) - |> assert(visible(by_role(:heading, level: 2, name: "Check your email"))) + |> assert_has(by_role(:heading, level: 2, name: "Check your email")) token = receive do @@ -65,8 +64,8 @@ defmodule BrowserSignInReturnSteps do %{session: session} = context do session |> assert(page_url(&(&1.path == context.return_path))) - |> assert(visible(by_role(:heading, level: 1, name: context.return_huddl.title))) - |> assert(visible(by_role(:button, name: "RSVP"))) + |> assert_has(by_role(:heading, level: 1, name: context.return_huddl.title)) + |> assert_has(by_role(:button, name: "RSVP")) assert [] = Huddlz.Communities.check_user_rsvp!(context.return_huddl.id, diff --git a/test/browser/steps/social_schedule_steps.exs b/test/browser/steps/social_schedule_steps.exs index 5af030373..22f2c2e80 100644 --- a/test/browser/steps/social_schedule_steps.exs +++ b/test/browser/steps/social_schedule_steps.exs @@ -15,7 +15,7 @@ defmodule BrowserSocialScheduleSteps do session |> visit("/organize/#{group.slug}/social") |> click(edit()) - |> assert(visible(preview() |> filter(has_text: "Morning-of post preview"))) + |> assert_has(preview() |> filter(has_text: "Morning-of post preview")) # The sheet moves focus to its first control again two animation # frames after mounting; wait for it to finish opening before typing. |> assert(css(sheet(), "opacity", "1")) @@ -86,7 +86,7 @@ defmodule BrowserSocialScheduleSteps do session |> click(edit()) |> assert(checked(morning_of())) - |> assert(visible(preview() |> filter(has_text: "See you tonight!"))) + |> assert_has(preview() |> filter(has_text: "See you tonight!")) |> assert(css(sheet(), "opacity", "1")) |> press(opening_line(), "Tab") |> assert(focused(by_role(:button, name: "Remove", exact: true)))