tarakan/test/tarakan_web/theme_boot_test.exs
Maxfield Luke af6077b9c3
All checks were successful
CI and deploy / Test (push) Successful in 4m52s
CI and deploy / Deploy production (push) Successful in 23s
Initial commit on Forgejo
Fresh repository history for elektrine/tarakan hosted at
https://git.elektrine.com/elektrine/tarakan.
2026-07-29 04:43:40 -04:00

22 lines
863 B
Elixir

defmodule TarakanWeb.ThemeBootTest do
use TarakanWeb.ConnCase, async: true
test "the theme script is blocking and precedes the deferred bundle", %{conn: conn} do
html = conn |> get(~p"/") |> html_response(200)
theme_at = :binary.match(html, "/assets/js/theme") |> elem(0)
app_at = :binary.match(html, "/assets/js/app") |> elem(0)
assert theme_at < app_at, "theme.js must load before app.js"
# The whole point: it must not be deferred, or it runs after first paint
# and the toggle flashes the wrong option again.
[theme_tag] = Regex.run(~r|<script[^>]*/assets/js/theme[^>]*>|, html)
refute theme_tag =~ "defer"
refute theme_tag =~ "type=\"module\""
# And the bundle that needs to stay deferred still is.
[app_tag] = Regex.run(~r|<script[^>]*/assets/js/app[^>]*>|, html)
assert app_tag =~ "defer"
end
end