2021-03-03 17:35:03 -05:00
|
|
|
defmodule HeroiconsTest do
|
|
|
|
use ExUnit.Case, async: true
|
2021-03-06 16:53:46 -05:00
|
|
|
|
2021-11-12 12:03:42 -05:00
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
|
2021-03-10 13:51:07 -05:00
|
|
|
test "generated function" do
|
2022-09-02 13:21:32 -04:00
|
|
|
result = Phoenix.HTML.safe_to_string(Heroicons.Outline.academic_cap())
|
|
|
|
assert result =~ ~s(<svg )
|
|
|
|
assert result =~ ~s(aria-hidden="true")
|
|
|
|
assert result =~ ~s(fill="none")
|
|
|
|
assert result =~ ~s(stroke="currentColor")
|
|
|
|
assert result =~ ~s(stroke-width="1.5")
|
|
|
|
assert result =~ ~s(viewBox="0 0 24 24")
|
2021-03-06 16:53:46 -05:00
|
|
|
|
2021-03-10 14:30:12 -05:00
|
|
|
assert Heroicons.Outline.academic_cap(class: "h-6 w-6 text-gray-500")
|
|
|
|
|> Phoenix.HTML.safe_to_string() =~
|
2021-03-06 16:53:46 -05:00
|
|
|
~s(class="h-6 w-6 text-gray-500")
|
2021-03-10 14:30:12 -05:00
|
|
|
|
|
|
|
assert Heroicons.Outline.academic_cap(class: "<> \" ")
|
|
|
|
|> Phoenix.HTML.safe_to_string() =~
|
2021-03-19 12:30:56 -04:00
|
|
|
~s(class="<> " ")
|
|
|
|
|
|
|
|
assert Heroicons.Outline.academic_cap(foo: "bar")
|
|
|
|
|> Phoenix.HTML.safe_to_string() =~
|
|
|
|
~s(foo="bar")
|
|
|
|
|
|
|
|
assert Heroicons.Outline.academic_cap(multiword_key: "foo")
|
|
|
|
|> Phoenix.HTML.safe_to_string() =~
|
|
|
|
~s(multiword-key="foo")
|
2021-04-19 15:21:09 -04:00
|
|
|
|
|
|
|
assert Heroicons.Outline.academic_cap(viewBox: "0 0 12 12")
|
|
|
|
|> Phoenix.HTML.safe_to_string() =~
|
2021-11-12 12:03:42 -05:00
|
|
|
~s(viewBox="0 0 12 12")
|
|
|
|
end
|
2021-04-19 15:21:09 -04:00
|
|
|
|
2021-11-12 12:03:42 -05:00
|
|
|
test "generated components" do
|
2022-09-02 13:21:32 -04:00
|
|
|
outline = render_component(&Heroicons.Outline.academic_cap/1, assigns())
|
|
|
|
assert outline =~ ~s(<svg )
|
|
|
|
assert outline =~ ~s(aria-hidden="true")
|
|
|
|
assert outline =~ ~s(fill="none")
|
|
|
|
assert outline =~ ~s(stroke="currentColor")
|
|
|
|
assert outline =~ ~s(stroke-width="1.5")
|
|
|
|
assert outline =~ ~s(viewBox="0 0 24 24")
|
|
|
|
|
|
|
|
solid = render_component(&Heroicons.Solid.academic_cap/1, assigns())
|
|
|
|
assert solid =~ ~s(<svg )
|
|
|
|
assert solid =~ ~s(aria-hidden="true")
|
|
|
|
assert solid =~ ~s(fill="currentColor")
|
|
|
|
assert solid =~ ~s(viewBox="0 0 24 24")
|
2022-08-31 16:41:05 -04:00
|
|
|
|
|
|
|
assert render_component(
|
|
|
|
&Heroicons.Outline.academic_cap/1,
|
|
|
|
assigns(class: "h-6 w-6 text-gray-500")
|
|
|
|
) =~
|
|
|
|
~s(class="h-6 w-6 text-gray-500")
|
2022-08-30 09:46:24 -04:00
|
|
|
|
2022-09-02 13:21:32 -04:00
|
|
|
mini = render_component(&Heroicons.Mini.academic_cap/1, assigns())
|
|
|
|
assert solid =~ ~s(<svg )
|
|
|
|
assert solid =~ ~s(aria-hidden="true")
|
|
|
|
assert solid =~ ~s(fill="currentColor")
|
|
|
|
assert solid =~ ~s(viewBox="0 0 24 24")
|
2021-03-06 16:53:46 -05:00
|
|
|
end
|
2021-03-10 13:51:07 -05:00
|
|
|
|
|
|
|
test "generated docs" do
|
2021-03-10 14:30:12 -05:00
|
|
|
{:docs_v1, _annotation, _beam_language, _format, _module_doc, _metadata, docs} =
|
|
|
|
Code.fetch_docs(Heroicons.Outline)
|
2021-03-10 13:51:07 -05:00
|
|
|
|
2021-03-10 14:30:12 -05:00
|
|
|
doc =
|
|
|
|
Enum.find_value(docs, fn
|
|
|
|
{{:function, :academic_cap, 1}, _annotation, _signature, doc, _metadata} -> doc
|
|
|
|
_ -> nil
|
|
|
|
end)
|
2021-03-10 13:51:07 -05:00
|
|
|
|
|
|
|
assert doc["en"] == """
|
2022-08-31 16:41:05 -04:00
|
|
|
 {: width=24px}
|
2021-03-10 13:51:07 -05:00
|
|
|
|
2021-03-10 14:30:12 -05:00
|
|
|
## Examples
|
2021-11-12 12:03:42 -05:00
|
|
|
|
|
|
|
Use as a `Phoenix.Component`
|
|
|
|
|
|
|
|
<.academic_cap />
|
|
|
|
<.academic_cap class="h-6 w-6 text-gray-500" />
|
|
|
|
|
2022-02-15 23:44:39 -05:00
|
|
|
or as a function
|
2021-11-12 12:03:42 -05:00
|
|
|
|
|
|
|
<%= academic_cap() %>
|
|
|
|
<%= academic_cap(class: "h-6 w-6 text-gray-500") %>
|
2021-03-10 14:30:12 -05:00
|
|
|
"""
|
2021-03-10 13:51:07 -05:00
|
|
|
end
|
2021-11-12 12:03:42 -05:00
|
|
|
|
|
|
|
defp assigns(assgns \\ []) do
|
|
|
|
Map.new(assgns)
|
|
|
|
|> Map.put_new(:__changed__, %{})
|
|
|
|
end
|
2021-03-03 17:35:03 -05:00
|
|
|
end
|