Skip to content

Commit

Permalink
add e2e for #3529
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Jan 10, 2025
1 parent 43fbeb7 commit 94b2df3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/e2e/support/issues/issue_3529.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule Phoenix.LiveViewTest.E2E.Issue3529Live do
# https://github.com/phoenixframework/phoenix_live_view/issues/3529

use Phoenix.LiveView

alias Phoenix.LiveView.JS

def mount(_params, _session, socket) do
{:ok, assign(socket, :mounted, DateTime.utc_now())}
end

def handle_params(_params, _uri, socket) do
{:noreply, assign(socket, :next, :rand.uniform())}
end

def render(assigns) do
~H"""
<h1>Mounted at {@mounted}</h1>
<.link navigate={"/issues/3529?param=#{@next}"}>Navigate</.link>
<.link patch={"/issues/3529?param=#{@next}"}>Patch</.link>
"""
end
end
1 change: 1 addition & 0 deletions test/e2e/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ defmodule Phoenix.LiveViewTest.E2E.Router do
live "/3448", Issue3448Live
live "/3496/a", Issue3496.ALive
live "/3496/b", Issue3496.BLive
live "/3529", Issue3529Live
end
end

Expand Down
45 changes: 45 additions & 0 deletions test/e2e/tests/issues/3529.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const {test, expect} = require("../../test-fixtures")
const {syncLV} = require("../../utils")

const pageText = async (page) => await page.evaluate(() => document.querySelector("h1").innerText)

// https://github.com/phoenixframework/phoenix_live_view/issues/3529
// https://github.com/phoenixframework/phoenix_live_view/pull/3625
test("forward and backward navigation is handled properly (replaceRootHistory)", async ({page}) => {
await page.goto("/issues/3529")
await syncLV(page)

let text = await pageText(page)
await page.getByRole("link", {name: "Navigate"}).click()
await syncLV(page)

// navigate remounts and changes the text
expect(await pageText(page)).not.toBe(text)
text = await pageText(page)

await page.getByRole("link", {name: "Patch"}).click()
await syncLV(page)
// patch does not remount
expect(await pageText(page)).toBe(text)

// now we go back (should be patch again)
await page.goBack()
await syncLV(page)
expect(await pageText(page)).toBe(text)

// and then we back to the initial page and use back/foward
// this should be a navigate -> remount!
await page.goBack()
await syncLV(page)
expect(await pageText(page)).not.toBe(text)

// navigate
await page.goForward()
await syncLV(page)
text = await pageText(page)

// now back again (navigate)
await page.goBack()
await syncLV(page)
expect(await pageText(page)).not.toBe(text)
})

0 comments on commit 94b2df3

Please sign in to comment.