chore: add initial test

This commit is contained in:
Zach Daniel 2022-05-25 12:17:52 -04:00
parent c9c0a8cb4f
commit 464592430d
10 changed files with 125 additions and 9 deletions

View file

@ -7,12 +7,6 @@ Application.put_env(:ash_admin, Demo.Repo, url: "ecto://#{pg_url}/#{pg_database}
config :phoenix, :json_library, Jason
config :ash_admin, ecto_repos: [Demo.Repo]
config :ash_admin,
ash_apis: [
Demo.Accounts.Api,
Demo.Tickets.Api
]
config :surface, :components, [
{Surface.Components.Form.ErrorTag, default_class: "invalid-feedback"}
]
@ -30,7 +24,13 @@ config :ash_admin, DemoWeb.Endpoint,
config :logger, level: :debug
config :phoenix, :serve_endpoints, true
if Mix.env() == :dev do
if config_env() == :dev do
config :ash_admin,
ash_apis: [
Demo.Accounts.Api,
Demo.Tickets.Api
]
config :git_ops,
mix_project: AshAdmin.MixProject,
changelog_file: "CHANGELOG.md",
@ -43,3 +43,19 @@ if Mix.env() == :dev do
manage_readme_version: "README.md",
version_tag_prefix: "v"
end
if config_env() == :test do
config :ash_admin, AshAdmin.Test.Endpoint,
url: [host: "localhost"],
debug_errors: true,
secret_key_base: "Hu4qQN3iKzTV4fJxhorPQlA/osH9fAMtbtjVS58PFgfw3ja5Z18Q/WSNR9wP4OfW",
live_view: [signing_salt: "hMegieSe"],
pubsub_server: AshAdmin.Test.PubSub
config :ash, :disable_async?, true
config :ash_admin,
ash_apis: [
AshAdmin.Test.Api
]
end

View file

@ -33,10 +33,14 @@ defmodule AshAdmin.MixProject do
]
end
defp elixirc_paths(env) when env in [:dev, :test] do
defp elixirc_paths(:dev) do
["lib", "dev"]
end
defp elixirc_paths(:test) do
["lib", "test/support"]
end
defp elixirc_paths(:prod) do
["lib"]
end
@ -103,7 +107,8 @@ defmodule AshAdmin.MixProject do
{:credo, ">= 0.0.0", only: [:dev, :test], runtime: false},
{:dialyxir, ">= 0.0.0", only: [:dev, :test], runtime: false},
{:sobelow, ">= 0.0.0", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.14", only: [:dev, :test]}
{:excoveralls, "~> 0.14", only: [:dev, :test]},
{:floki, ">= 0.30.0", only: :test}
]
end
end

View file

@ -24,10 +24,12 @@
"ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"},
"excoveralls": {:hex, :excoveralls, "0.14.5", "5c685449596e962c779adc8f4fb0b4de3a5b291c6121097572a3aa5400c386d3", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9b4a9bf10e9a6e48b94159e13b4b8a1b05400f17ac16cc363ed8734f26e1f4e"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.32.1", "dfe3b8db3b793939c264e6f785bca01753d17318d144bd44b407fb3493acaa87", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "d4b91c713e4a784a3f7b1e3cc016eefc619f6b1c3898464222867cafd3c681a3"},
"gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"},
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},
"git_ops": {:hex, :git_ops, "2.4.5", "185a724dfde3745edd22f7571d59c47a835cf54ded67e9ccbc951920b7eec4c2", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e323a5b01ad53bc8c19c3a444be3e61ed7803ecd2e95530446ae9327d0143ecc"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},

20
test/page_live_test.exs Normal file
View file

@ -0,0 +1,20 @@
defmodule AshAdmin.Test.PageLiveTest do
use ExUnit.Case, async: false
import Plug.Conn
import Phoenix.ConnTest
import Phoenix.LiveViewTest
@endpoint AshAdmin.Test.Endpoint
setup do
%{conn: build_conn()}
end
test "it renders the schema by default", %{conn: conn} do
{:ok, _view, html} = live(conn, "/Api/Post")
assert html =~ "Attributes"
assert html =~ "body"
assert html =~ "String"
end
end

12
test/support/api.ex Normal file
View file

@ -0,0 +1,12 @@
defmodule AshAdmin.Test.Api do
use Ash.Api,
extensions: [AshAdmin.Api]
admin do
show? true
end
resources do
registry(AshAdmin.Test.Registry)
end
end

18
test/support/endpoint.ex Normal file
View file

@ -0,0 +1,18 @@
defmodule AshAdmin.Test.Endpoint do
use Phoenix.Endpoint, otp_app: :ash_admin
socket("/live", Phoenix.LiveView.Socket)
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
plug(Phoenix.LiveReloader)
plug(Phoenix.CodeReloader)
plug(Plug.Session,
store: :cookie,
key: "_live_view_key",
signing_salt: "/VEDsdfsffMnp5"
)
plug(Plug.RequestId)
plug(AshAdmin.Test.Router)
end

7
test/support/registry.ex Normal file
View file

@ -0,0 +1,7 @@
defmodule AshAdmin.Test.Registry do
use Ash.Registry
entries do
entry(AshAdmin.Test.Post)
end
end

View file

@ -0,0 +1,12 @@
defmodule AshAdmin.Test.Post do
use Ash.Resource,
data_layer: Ash.DataLayer.Ets
attributes do
uuid_primary_key(:id)
attribute :body, :string do
allow_nil?(false)
end
end
end

15
test/support/router.ex Normal file
View file

@ -0,0 +1,15 @@
defmodule AshAdmin.Test.Router do
use Phoenix.Router
pipeline :browser do
plug(:fetch_session)
plug(:fetch_query_params)
end
scope "/" do
pipe_through(:browser)
import AshAdmin.Router
ash_admin("/")
end
end

View file

@ -1,2 +1,11 @@
ExUnit.start()
Logger.configure(level: :debug)
Application.ensure_all_started(:os_mon)
children = [
AshAdmin.Test.Endpoint,
{Phoenix.PubSub, [name: AshAdmin.Test.PubSub, adapter: Phoenix.PubSub.PG2]}
]
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)