-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix phx-remove and phx-click-loading in sticky LVs (#3659)
- Loading branch information
Showing
7 changed files
with
148 additions
and
12 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
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,56 @@ | ||
defmodule Phoenix.LiveViewTest.E2E.Issue3656Live do | ||
# https://github.com/phoenixframework/phoenix_live_view/issues/3656 | ||
|
||
use Phoenix.LiveView | ||
|
||
alias Phoenix.LiveView.JS | ||
|
||
def mount(_params, _session, socket) do | ||
{:ok, socket} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<style> | ||
* { font-size: 1.1em } | ||
nav { margin-top: 1em } | ||
nav a { padding: 8px 16px; border: 1px solid black; text-decoration: none } | ||
nav a:visited { color: inherit } | ||
nav a.active { border: 3px solid green } | ||
nav a.phx-click-loading { animation: pulsate 2s infinite } | ||
@keyframes pulsate { | ||
0% { | ||
background-color: white; | ||
} | ||
50% { | ||
background-color: red; | ||
} | ||
100% { | ||
background-color: white; | ||
} | ||
} | ||
</style> | ||
{live_render(@socket, Phoenix.LiveViewTest.E2E.Issue3656Live.Sticky, | ||
id: "sticky", | ||
sticky: true | ||
)} | ||
""" | ||
end | ||
end | ||
|
||
defmodule Phoenix.LiveViewTest.E2E.Issue3656Live.Sticky do | ||
use Phoenix.LiveView | ||
|
||
def mount(:not_mounted_at_router, _session, socket) do | ||
{:ok, socket, layout: false} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<nav> | ||
<.link navigate="/issues/3656?navigated=true">Link 1</.link> | ||
</nav> | ||
""" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Phoenix.LiveViewTest.E2E.Issue3658Live do | ||
# https://github.com/phoenixframework/phoenix_live_view/issues/3658 | ||
|
||
use Phoenix.LiveView | ||
|
||
alias Phoenix.LiveView.JS | ||
|
||
def mount(_params, _session, socket) do | ||
{:ok, socket} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<.link navigate="/issues/3658?navigated=true">Link 1</.link> | ||
{live_render(@socket, Phoenix.LiveViewTest.E2E.Issue3658Live.Sticky, | ||
id: "sticky", | ||
sticky: true | ||
)} | ||
""" | ||
end | ||
end | ||
|
||
defmodule Phoenix.LiveViewTest.E2E.Issue3658Live.Sticky do | ||
use Phoenix.LiveView | ||
|
||
def mount(:not_mounted_at_router, _session, socket) do | ||
{:ok, socket, layout: false} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<div> | ||
<div id="foo" phx-remove={Phoenix.LiveView.JS.dispatch("my-event")}>Hi</div> | ||
</div> | ||
""" | ||
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,21 @@ | ||
const {test, expect} = require("../../test-fixtures") | ||
const {syncLV, attributeMutations} = require("../../utils") | ||
|
||
// https://github.com/phoenixframework/phoenix_live_view/issues/3656 | ||
test("phx-click-loading is removed from links in sticky LiveViews", async ({page}) => { | ||
await page.goto("/issues/3656") | ||
await syncLV(page) | ||
|
||
let changes = attributeMutations(page, "nav a") | ||
|
||
const link = page.getByRole("link", {name: "Link 1"}) | ||
await link.click() | ||
|
||
await syncLV(page) | ||
await expect(link).not.toHaveClass("phx-click-loading") | ||
|
||
expect(await changes()).toEqual(expect.arrayContaining([ | ||
{attr: "class", oldValue: null, newValue: "phx-click-loading"}, | ||
{attr: "class", oldValue: "phx-click-loading", newValue: ""}, | ||
])) | ||
}) |
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,15 @@ | ||
const {test, expect} = require("../../test-fixtures") | ||
const {syncLV} = require("../../utils") | ||
|
||
// https://github.com/phoenixframework/phoenix_live_view/issues/3658 | ||
test("phx-remove elements inside sticky LiveViews are not removed when navigating", async ({page}) => { | ||
await page.goto("/issues/3658") | ||
await syncLV(page) | ||
|
||
await expect(page.locator("#foo")).toBeVisible() | ||
await page.getByRole("link", {name: "Link 1"}).click() | ||
|
||
await syncLV(page) | ||
// the bug would remove the element | ||
await expect(page.locator("#foo")).toBeVisible() | ||
}) |