-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |