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

Test tickets live #847

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions demo/lib/demo/ash_factory.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Demo.AshFactory do
@moduledoc false
use Smokestack

alias Demo.Helpdesk.Ticket

factory Ticket do
attribute :subject, &Faker.Lorem.sentence/0
attribute :body, &Faker.Lorem.paragraph/0
end
end
10 changes: 1 addition & 9 deletions demo/lib/demo/factory.ex → demo/lib/demo/ecto_factory.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
defmodule Demo.Factory do
defmodule Demo.EctoFactory do
@moduledoc false

use ExMachina.Ecto, repo: Demo.Repo

alias Demo.Address
alias Demo.Category
alias Demo.Helpdesk.Ticket
alias Demo.Post
alias Demo.Product
alias Demo.ShortLink
Expand Down Expand Up @@ -92,13 +91,6 @@ defmodule Demo.Factory do
}
end

def ticket_factory do
%Ticket{
subject: Faker.Lorem.sentence(),
body: Faker.Lorem.paragraph()
}
end

defp boolean do
Enum.random(0..1) == 1
end
Expand Down
1 change: 1 addition & 0 deletions demo/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defmodule Demo.MixProject do
{:mix_audit, "~> 2.0", only: [:dev, :test], runtime: false},
{:tailwind_formatter, "~> 0.4.0", only: [:dev, :test], runtime: false},
{:ex_machina, "~> 2.3"},
{:smokestack, "~> 0.9.2"},
{:faker, "~> 0.18"},
{:phoenix_test, "~> 0.5.0", only: :test, runtime: false},
{:sourceror, "~> 1.7", only: [:dev, :test]},
Expand Down
2 changes: 2 additions & 0 deletions demo/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"postgrex": {:hex, :postgrex, "0.20.0", "363ed03ab4757f6bc47942eff7720640795eb557e1935951c1626f0d303a3aed", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d36ef8b36f323d29505314f704e21a1a038e2dc387c6409ee0cd24144e187c0f"},
"reactor": {:hex, :reactor, "0.12.0", "6191b691219c710f7910c275a0ad8853c93f4df99cb1d867321649206231f2e5", [:mix], [{:igniter, "~> 0.4", [hex: :igniter, repo: "hexpm", optional: true]}, {:iterex, "~> 0.1", [hex: :iterex, repo: "hexpm", optional: false]}, {:libgraph, "~> 0.16", [hex: :libgraph, repo: "hexpm", optional: false]}, {:spark, "~> 2.0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.2", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f86335570bb360ef2a403679aa4e94b0f97b97410165d5ae35fb2c5cbf68ddcc"},
"recase": {:hex, :recase, "0.8.1", "ab98cd35857a86fa5ca99036f575241d71d77d9c2ab0c39aacf1c9b61f6f7d1d", [:mix], [], "hexpm", "9fd8d63e7e43bd9ea385b12364e305778b2bbd92537e95c4b2e26fc507d5e4c2"},
"sentry": {:hex, :sentry, "10.8.1", "aa45309785e1521416225adb16e0b4d8b957578804527f3c7babb6fefbc5e456", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0 or ~> 1.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "495b3cdadad90ba72eef973aa3dec39b3b8b2a362fe87e2f4ef32133ac3b4097"},
"smokestack": {:hex, :smokestack, "0.9.2", "630b5b27c4f9d37c1f75cd0ba9212307420f61aca51f8678f530a9730b17dccf", [:mix], [{:ash, "~> 3.0", [hex: :ash, repo: "hexpm", optional: false]}, {:recase, "~> 0.8", [hex: :recase, repo: "hexpm", optional: false]}, {:spark, "~> 2.1", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "5fdfde8e877c319fe1fe74047ff52263ef8f7860eae6ec2eceecb6c667d97c4d"},
"sobelow": {:hex, :sobelow, "0.13.0", "218afe9075904793f5c64b8837cc356e493d88fddde126a463839351870b8d1e", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cd6e9026b85fc35d7529da14f95e85a078d9dd1907a9097b3ba6ac7ebbe34a0d"},
"sourceror": {:hex, :sourceror, "1.7.1", "599d78f4cc2be7d55c9c4fd0a8d772fd0478e3a50e726697c20d13d02aa056d4", [:mix], [], "hexpm", "cd6f268fe29fa00afbc535e215158680a0662b357dc784646d7dff28ac65a0fc"},
"spark": {:hex, :spark, "2.2.43", "4ce84fcc9626f7759e9b9d698c95bdfcbbe9732184e1bc8f6ab9f9963bce2a6a", [:mix], [{:igniter, ">= 0.3.64 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}, {:sourceror, "~> 1.2", [hex: :sourceror, repo: "hexpm", optional: true]}], "hexpm", "bbd83de69f4436e6f075d632d41110f840ce3a12c34d5499c15e60cf7b45a67b"},
Expand Down
5 changes: 3 additions & 2 deletions demo/priv/repo/seeds.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Demo.Factory
import Demo.EctoFactory
import Demo.AshFactory

category_names = ["Tech", "Misc", "Crew", "News"]

Expand All @@ -22,7 +23,7 @@ insert_list(10, :product)

insert_list(10, :address)

insert_list(10, :ticket)
insert!(Demo.Helpdesk.Ticket, count: 10)

:code.priv_dir(:demo)
|> Path.join("repo/film_reviews.csv")
Expand Down
2 changes: 1 addition & 1 deletion demo/test/demo_web/live/category_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule DemoWeb.Live.CategoryLiveTest do
use DemoWeb.ConnCase, async: false

import Demo.Factory
import Demo.EctoFactory
import Phoenix.LiveViewTest
import Demo.Support.LiveResourceTests

Expand Down
2 changes: 1 addition & 1 deletion demo/test/demo_web/live/tag_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule DemoWeb.Live.TagLiveTest do
use DemoWeb.ConnCase, async: false

import Demo.Factory
import Demo.EctoFactory
import Phoenix.LiveViewTest
import Demo.Support.LiveResourceTests

Expand Down
44 changes: 44 additions & 0 deletions demo/test/demo_web/live/ticket_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule DemoWeb.TicketLiveTest do
use DemoWeb.ConnCase, async: false

import Demo.AshFactory
import Demo.Support.LiveResourceTests
import Phoenix.LiveViewTest

alias Demo.Helpdesk.Ticket

describe "tickets live resource index" do
test "is rendered", %{conn: conn} do
insert!(Ticket, count: 3)

conn
|> visit(~p"/admin/tickets")
|> assert_has("h1", text: "Tickets", exact: true)
|> assert_has("button[disabled]", text: "Delete", exact: true)
|> assert_has("div", text: "Items 1 to 3 (3 total)", exact: true)
|> assert_has("table tbody tr", count: 3)
end

test "basic functionality", %{conn: conn} do
tickets = insert!(Ticket, count: 3)

test_table_rows_count(conn, ~p"/admin/tickets", Enum.count(tickets))
test_delete_button_disabled_enabled(conn, ~p"/admin/tickets", tickets)
test_show_action_redirect(conn, ~p"/admin/tickets", tickets)
end
end

describe "tickets live resource show" do
test "is rendered", %{conn: conn} do
ticket = insert!(Ticket)

conn
|> visit(~p"/admin/tickets/#{ticket.id}/show")
|> assert_has("h1", text: "Ticket", exact: true)
|> assert_has("p", text: "Subject", exact: true)
|> assert_has("p", text: "Body", exact: true)
|> assert_has("p", text: ticket.subject, exact: true)
|> assert_has("p", text: ticket.body, exact: true)
end
end
end
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"mix_audit": {:hex, :mix_audit, "2.1.4", "0a23d5b07350cdd69001c13882a4f5fb9f90fbd4cbf2ebc190a2ee0d187ea3e9", [:make, :mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.11", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "fd807653cc8c1cada2911129c7eb9e985e3cc76ebf26f4dd628bb25bbcaa7099"},
"money": {:hex, :money, "1.13.1", "b437196bf698f85d2cad33ac3f65e1bc43a94673fddbf65605fe3a77922e208a", [:mix], [{:decimal, "~> 1.2 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:ecto, "~> 2.1 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.0 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "d9719b775652b6249fa80aeecc5e505a5eeeab73f4f30ecd3f696c6830281dc5"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
"number": {:hex, :number, "1.0.5", "d92136f9b9382aeb50145782f116112078b3465b7be58df1f85952b8bb399b0f", [:mix], [{:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "c0733a0a90773a66582b9e92a3f01290987f395c972cb7d685f51dd927cd5169"},
"owl": {:hex, :owl, "0.12.1", "d3146087315c4528ee32411495ba10ec88102597b638d4d1455cf9d245dfb57a", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "d7eb9746aa89c40c46b479d6c2a70b82b94993520e40f21d0b09654f23eebf35"},
"phoenix": {:hex, :phoenix, "1.7.19", "36617efe5afbd821099a8b994ff4618a340a5bfb25531a1802c4d4c634017a57", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "ba4dc14458278773f905f8ae6c2ec743d52c3a35b6b353733f64f02dfe096cd6"},
Expand Down
Loading