2021-03-22 19:41:22 +13:00
|
|
|
defmodule AshAdmin.Test.AshAdminTest do
|
|
|
|
@moduledoc false
|
|
|
|
use ExUnit.Case, async: true
|
2024-05-16 06:10:36 +12:00
|
|
|
|
|
|
|
test "all resources are shown by default", _ do
|
|
|
|
defmodule Domain do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Domain,
|
|
|
|
extensions: [AshAdmin.Domain]
|
|
|
|
|
|
|
|
admin do
|
|
|
|
show? true
|
|
|
|
end
|
|
|
|
|
|
|
|
resources do
|
2024-05-18 11:23:57 +12:00
|
|
|
resource(AshAdmin.Test.Post)
|
|
|
|
resource(AshAdmin.Test.Comment)
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert AshAdmin.Domain.show_resources(Domain) === [
|
2024-05-18 11:23:57 +12:00
|
|
|
AshAdmin.Test.Post,
|
|
|
|
AshAdmin.Test.Comment
|
|
|
|
]
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
test "all resources are shown when :* option is selected", _ do
|
|
|
|
defmodule Domain do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Domain,
|
|
|
|
extensions: [AshAdmin.Domain]
|
|
|
|
|
|
|
|
admin do
|
|
|
|
show? true
|
|
|
|
show_resources :*
|
|
|
|
end
|
|
|
|
|
|
|
|
resources do
|
2024-05-18 11:23:57 +12:00
|
|
|
resource(AshAdmin.Test.Post)
|
|
|
|
resource(AshAdmin.Test.Comment)
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert AshAdmin.Domain.show_resources(Domain) === [
|
2024-05-18 11:23:57 +12:00
|
|
|
AshAdmin.Test.Post,
|
|
|
|
AshAdmin.Test.Comment
|
|
|
|
]
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
test "selected resources are shown", _ do
|
|
|
|
defmodule Domain do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Domain,
|
|
|
|
extensions: [AshAdmin.Domain]
|
|
|
|
|
|
|
|
admin do
|
|
|
|
show? true
|
|
|
|
show_resources AshAdmin.Test.Post
|
|
|
|
end
|
|
|
|
|
|
|
|
resources do
|
2024-05-18 11:23:57 +12:00
|
|
|
resource(AshAdmin.Test.Post)
|
|
|
|
resource(AshAdmin.Test.Comment)
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert AshAdmin.Domain.show_resources(Domain) === [
|
2024-05-18 11:23:57 +12:00
|
|
|
AshAdmin.Test.Post
|
|
|
|
]
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
test "if shown resrouces option not eixsting resource providede error", _ do
|
2024-05-18 11:23:57 +12:00
|
|
|
assert_raise(
|
|
|
|
Spark.Error.DslError,
|
|
|
|
"[AshAdmin.Test.AshAdminTest.Domain]\n admin -> show_resources:\n SomeRandom is not a valid resource in AshAdmin.Test.AshAdminTest.Domain",
|
|
|
|
fn ->
|
|
|
|
defmodule Domain do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Domain,
|
|
|
|
extensions: [AshAdmin.Domain]
|
2024-05-16 06:10:36 +12:00
|
|
|
|
2024-05-18 11:23:57 +12:00
|
|
|
admin do
|
|
|
|
show? true
|
|
|
|
show_resources [AshAdmin.Test.Post, SomeRandom]
|
|
|
|
end
|
2024-05-16 06:10:36 +12:00
|
|
|
|
2024-05-18 11:23:57 +12:00
|
|
|
resources do
|
|
|
|
resource(AshAdmin.Test.Post)
|
|
|
|
resource(AshAdmin.Test.Comment)
|
|
|
|
end
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
|
|
|
end
|
2024-05-18 11:23:57 +12:00
|
|
|
)
|
2024-05-16 06:10:36 +12:00
|
|
|
end
|
2021-03-22 19:41:22 +13:00
|
|
|
end
|