Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Phoenix Liveview #709

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions cypress/e2e/acceptance.cy.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
describe('Acceptance Test', function () {
describe('Acceptance Test', function() {
// REGULAR ROUTE

it('Can visit the users page', function () {
it('Can visit the users page', function() {
cy.visit('http://localhost:5000/users')
})

it('Can hide the names column', function () {
it('Can hide the names column', function() {
cy.contains('Bob')
cy.get('[phx-value-column=name]').should('have.length', 2)
cy.get('[phx-value-column=name]').first().click()
cy.get('[phx-value-column=name]').should('not.exist')
cy.contains('Bob').should('not.exist')
})

it('Can show the names column again', function () {
it('Can show the names column again', function() {
cy.contains('Bob').should('not.exist');
cy.contains('Show Name').should('not.exist')
cy.contains('Show Field Buttons').first().click()
cy.contains('Show Name').first().click()
cy.contains('Bob')
})

it('Can visit page 2', function () {
it('Can visit page 2', function() {
cy.contains('Bob')
cy.contains('Sioban').should('not.exist')
cy.get('nav.exz-pagination-nav').contains('2').first().click()
cy.contains('Sioban')
cy.contains('Bob').should('not.exist')
})

it('Can search for names', function () {
it('Can search for names', function() {
cy.visit('http://localhost:5000/users')
cy.contains('Sioban').should('not.exist')
cy.get('input#search_search').type('siob')
Expand All @@ -42,27 +40,25 @@ describe('Acceptance Test', function () {

// LIVE SESSION

it('Live Session: Can visit the users page', function () {
it('Live Session: Can visit the users page', function() {
cy.visit('http://localhost:5000/live_session_users')
})

it('Live Session: Can hide the names column', function () {
it('Live Session: Can hide the names column', function() {
cy.contains('Bob')
cy.get('[phx-value-column=name]').should('have.length', 2)
cy.get('[phx-value-column=name]').first().click()
cy.get('[phx-value-column=name]').should('not.exist')
cy.contains('Bob').should('not.exist')
})

it('Live Session: Can show the names column again', function () {
it('Live Session: Can show the names column again', function() {
cy.contains('Bob').should('not.exist');
cy.contains('Show Name').should('not.exist')
cy.contains('Show Field Buttons').first().click()
cy.contains('Show Name').first().click()
cy.contains('Bob')
})

it('Live Session: Can visit page 2', function () {
it('Live Session: Can visit page 2', function() {
cy.contains('Bob')
cy.contains('Sioban').should('not.exist')
cy.get('nav.exz-pagination-nav').contains('2').first().click()
Expand All @@ -72,14 +68,14 @@ describe('Acceptance Test', function () {

// MISC

it('Doesnt see the action column when there are no action buttons', function () {
it('Doesnt see the action column when there are no action buttons', function() {
cy.visit('http://localhost:5000/posts/no_action_buttons')
cy.contains('Posts')
cy.contains('Show Field Buttons')
cy.contains('Actions').should('not.exist')
})

it('Cannot see hide functionality when it is disabled', function () {
it('Cannot see hide functionality when it is disabled', function() {
cy.visit('http://localhost:5000/posts/disable_hide')
cy.contains('Posts')
cy.contains('Actions')
Expand All @@ -88,21 +84,21 @@ describe('Acceptance Test', function () {
cy.contains('Hide').should('not.exist')
})

it('Cannot see pagination when it is disabled', function () {
it('Cannot see pagination when it is disabled', function() {
cy.visit('http://localhost:5000/posts/no_pagination')
cy.contains('Posts')
cy.contains('Actions')
cy.contains('Show Field Buttons')
cy.contains('Nex').should('not.exist')
})

it('Can use custom formatter', function () {
it('Can use custom formatter', function() {
cy.visit('http://localhost:5000/users/formatted')
cy.contains('<<< Bob >>>')
cy.contains('!!!boB!!!')
})

it('Can use custom text', function () {
it('Can use custom text', function() {
cy.visit('http://localhost:5000/beitrage')
cy.contains('Beiträge auflisten')
cy.contains('Ausblenden')
Expand All @@ -113,7 +109,7 @@ describe('Acceptance Test', function () {
cy.contains('Aktionen')
})

it('Can search across multiple columns', function () {
it('Can search across multiple columns', function() {
cy.get('input#search_search').type('1 CONTENT')
cy.contains('Post number 1')
cy.contains('Post number 2').should('not.exist')
Expand Down
5 changes: 3 additions & 2 deletions lib/exzeitable/database.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ defmodule Exzeitable.Database do
query
end

defp modify_query(query, %Params{query_modifier: {mod, fun}} = params) when is_atom(mod) and is_atom(fun) do
apply(mod, fun, [query, params])
defp modify_query(query, %Params{query_modifier: {mod, fun}} = params)
when is_atom(mod) and is_atom(fun) do
apply(mod, fun, [query, params])
end

defp modify_query(_query, %Params{query_modifier: invalid}) do
Expand Down
2 changes: 0 additions & 2 deletions lib/exzeitable/html/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ defmodule Exzeitable.HTML.Format do
|> format_field(fields[key].formatter)
end

# coveralls-ignore-stop

@doc "Will output the user supplied label or fall back on the atom"
@spec header(Params.t(), {atom, map}) :: String.t()
def header(_params, {_key, %{label: label}}) when is_binary(label), do: label
Expand Down
6 changes: 3 additions & 3 deletions lib/test_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ defmodule TestWeb do
def controller do
quote do
use Phoenix.Controller, namespace: TestWeb
use Gettext, backend: TestWeb.Gettext

import Plug.Conn
import TestWeb.Gettext
alias TestWeb.Router.Helpers, as: Routes
import Phoenix.LiveView.Controller
end
Expand All @@ -41,9 +41,9 @@ defmodule TestWeb do
import Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers
use Gettext, backend: TestWeb.Gettext

import TestWeb.ErrorHelpers
import TestWeb.Gettext
alias TestWeb.Router.Helpers, as: Routes

import Phoenix.LiveView.Helpers
Expand All @@ -62,7 +62,7 @@ defmodule TestWeb do
def channel do
quote do
use Phoenix.Channel
import TestWeb.Gettext
use Gettext, backend: TestWeb.Gettext
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/test_web/gettext.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ defmodule TestWeb.Gettext do

See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
"""
use Gettext, otp_app: :exzeitable
use Gettext.Backend, otp_app: :exzeitable
end
2 changes: 1 addition & 1 deletion lib/test_web/live_tables/beitrage_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ defmodule TestWeb.BeitrageTable do
text: TestWeb.GermanText,
refresh: 5000

def render(assigns), do: ~H"<%= build_table(assigns) %>"
def render(assigns), do: ~H"{build_table(assigns)}"
end
2 changes: 1 addition & 1 deletion lib/test_web/live_tables/post_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule TestWeb.PostTable do
action_buttons: [:show, :edit, :custom_button],
refresh: 5000

def render(assigns), do: ~H"<%= build_table(assigns) %>"
def render(assigns), do: ~H"{build_table(assigns)}"

def custom_button(_socket, _entry, _csrf_token), do: "CUSTOM BUTTON"
end
2 changes: 1 addition & 1 deletion lib/test_web/live_tables/user_formatted_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule TestWeb.UserFormattedTable do
query: from(u in User),
per_page: 5

def render(assigns), do: ~H"<%= build_table(assigns) %>"
def render(assigns), do: ~H"{build_table(assigns)}"

def name_backwards(_socket, entry) do
entry
Expand Down
2 changes: 1 addition & 1 deletion lib/test_web/live_tables/user_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule TestWeb.UserTable do
query: from(u in User),
per_page: 5

def render(assigns), do: ~H"<%= build_table(assigns) %>"
def render(assigns), do: ~H"{build_table(assigns)}"

def name_backwards(_socket, entry) do
entry
Expand Down
4 changes: 2 additions & 2 deletions lib/test_web/templates/beitrage/edit.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Beitrag bearbeiten</h1>

<%= render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :update, @post))) %>
{render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :update, @post)))}

<span><%= link("Zurück", to: Routes.post_path(@conn, :index)) %></span>
<span>{link("Zurück", to: Routes.post_path(@conn, :index))}</span>
14 changes: 7 additions & 7 deletions lib/test_web/templates/beitrage/form.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
</div>
<% end %>

<%= label(f, :title) %>
<%= text_input(f, :title) %>
<%= error_tag(f, :title) %>
{label(f, :title)}
{text_input(f, :title)}
{error_tag(f, :title)}

<%= label(f, :content) %>
<%= text_input(f, :content) %>
<%= error_tag(f, :content) %>
{label(f, :content)}
{text_input(f, :content)}
{error_tag(f, :content)}

<div>
<%= submit("Sparen") %>
{submit("Sparen")}
</div>
<% end %>
2 changes: 1 addition & 1 deletion lib/test_web/templates/beitrage/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Beiträge auflisten</h1>
<%= TestWeb.BeitrageTable.live_table(@conn) %>
{TestWeb.BeitrageTable.live_table(@conn)}
4 changes: 2 additions & 2 deletions lib/test_web/templates/beitrage/new.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Neuer Beitrag</h1>

<%= render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :create))) %>
{render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :create)))}

<span><%= link("Zurück", to: Routes.post_path(@conn, :index)) %></span>
<span>{link("Zurück", to: Routes.post_path(@conn, :index))}</span>
8 changes: 4 additions & 4 deletions lib/test_web/templates/beitrage/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<ul>
<li>
<strong>Titel:</strong>
<%= @post.title %>
{@post.title}
</li>

<li>
<strong>Inhalt:</strong>
<%= @post.content %>
{@post.content}
</li>
</ul>

<span><%= link("Bearbeiten", to: Routes.post_path(@conn, :edit, @post)) %></span>
<span><%= link("Zurück", to: Routes.post_path(@conn, :index)) %></span>
<span>{link("Bearbeiten", to: Routes.post_path(@conn, :edit, @post))}</span>
<span>{link("Zurück", to: Routes.post_path(@conn, :index))}</span>
6 changes: 3 additions & 3 deletions lib/test_web/templates/layout/app.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<main class="container">
<p class="alert alert-info" role="alert"><%= Phoenix.Flash.get(@flash, :info) %></p>
<p class="alert alert-danger" role="alert"><%= Phoenix.Flash.get(@flash, :error) %></p>
<%= @inner_content %>
<p class="alert alert-info" role="alert">{Phoenix.Flash.get(@flash, :info)}</p>
<p class="alert alert-danger" role="alert">{Phoenix.Flash.get(@flash, :error)}</p>
{@inner_content}
</main>
4 changes: 2 additions & 2 deletions lib/test_web/templates/layout/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%= csrf_meta_tag() %>
{csrf_meta_tag()}
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")} />
<script
defer
Expand All @@ -18,6 +18,6 @@
<header>
<section class="container"></section>
</header>
<%= @inner_content %>
{@inner_content}
</body>
</html>
4 changes: 2 additions & 2 deletions lib/test_web/templates/page/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<p>Here are the examplary (exzei-)tables:</p>
<ul>
<li><span><%= link("Posts", to: Routes.post_path(@conn, :index)) %></span></li>
<li><span><%= link("Users", to: Routes.user_path(@conn, :index)) %></span></li>
<li><span>{link("Posts", to: Routes.post_path(@conn, :index))}</span></li>
<li><span>{link("Users", to: Routes.user_path(@conn, :index))}</span></li>
</ul>
2 changes: 1 addition & 1 deletion lib/test_web/templates/post/disable_hide.html.heex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Listing Posts</h1>
<%= TestWeb.PostTable.live_table(@conn, disable_hide: true) %>
{TestWeb.PostTable.live_table(@conn, disable_hide: true)}
4 changes: 2 additions & 2 deletions lib/test_web/templates/post/edit.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Edit Post</h1>

<%= render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :update, @post))) %>
{render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :update, @post)))}

<span><%= link("Back", to: Routes.post_path(@conn, :index)) %></span>
<span>{link("Back", to: Routes.post_path(@conn, :index))}</span>
14 changes: 7 additions & 7 deletions lib/test_web/templates/post/form.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
</div>
<% end %>

<%= label(f, :title) %>
<%= text_input(f, :title) %>
<%= error_tag(f, :title) %>
{label(f, :title)}
{text_input(f, :title)}
{error_tag(f, :title)}

<%= label(f, :content) %>
<%= text_input(f, :content) %>
<%= error_tag(f, :content) %>
{label(f, :content)}
{text_input(f, :content)}
{error_tag(f, :content)}

<div>
<%= submit("Save") %>
{submit("Save")}
</div>
<% end %>
2 changes: 1 addition & 1 deletion lib/test_web/templates/post/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Listing Posts</h1>
<%= TestWeb.PostTable.live_table(@conn) %>
{TestWeb.PostTable.live_table(@conn)}
4 changes: 2 additions & 2 deletions lib/test_web/templates/post/new.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>New Post</h1>

<%= render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :create))) %>
{render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :create)))}

<span><%= link("Back", to: Routes.post_path(@conn, :index)) %></span>
<span>{link("Back", to: Routes.post_path(@conn, :index))}</span>
2 changes: 1 addition & 1 deletion lib/test_web/templates/post/no_action_buttons.html.heex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Listing Posts</h1>
<%= TestWeb.PostTable.live_table(@conn, action_buttons: []) %>
{TestWeb.PostTable.live_table(@conn, action_buttons: [])}
2 changes: 1 addition & 1 deletion lib/test_web/templates/post/no_pagination.html.heex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Listing Posts</h1>
<%= TestWeb.PostTable.live_table(@conn, pagination: []) %>
{TestWeb.PostTable.live_table(@conn, pagination: [])}
8 changes: 4 additions & 4 deletions lib/test_web/templates/post/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<ul>
<li>
<strong>Title:</strong>
<%= @post.title %>
{@post.title}
</li>

<li>
<strong>Content:</strong>
<%= @post.content %>
{@post.content}
</li>
</ul>

<span><%= link("Edit", to: Routes.post_path(@conn, :edit, @post)) %></span>
<span><%= link("Back", to: Routes.post_path(@conn, :index)) %></span>
<span>{link("Edit", to: Routes.post_path(@conn, :edit, @post))}</span>
<span>{link("Back", to: Routes.post_path(@conn, :index))}</span>
4 changes: 2 additions & 2 deletions lib/test_web/templates/user/edit.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Edit User</h1>

<%= render("form.html", Map.put(assigns, :action, Routes.user_path(@conn, :update, @user))) %>
{render("form.html", Map.put(assigns, :action, Routes.user_path(@conn, :update, @user)))}

<span><%= link("Back", to: Routes.user_path(@conn, :index)) %></span>
<span>{link("Back", to: Routes.user_path(@conn, :index))}</span>
Loading
Loading