add search to tag index
This commit is contained in:
@ -31,10 +31,28 @@ defmodule Cannery.TagsTest do
|
||||
[tag: tag_fixture(current_user), current_user: current_user]
|
||||
end
|
||||
|
||||
test "list_tags/0 returns all tags", %{tag: tag, current_user: current_user} do
|
||||
test "list_tags/1 returns all tags", %{tag: tag, current_user: current_user} do
|
||||
assert Tags.list_tags(current_user) == [tag]
|
||||
end
|
||||
|
||||
test "list_tags/2 returns relevant tags for a user", %{current_user: current_user} do
|
||||
tag_a = tag_fixture(%{"name" => "bullets"}, current_user)
|
||||
tag_b = tag_fixture(%{"name" => "hollows"}, current_user)
|
||||
|
||||
_shouldnt_return =
|
||||
%{
|
||||
"name" => "bullet",
|
||||
"desc" => "pews brass shell"
|
||||
}
|
||||
|> tag_fixture(user_fixture())
|
||||
|
||||
# name
|
||||
assert Tags.list_tags("bullet", current_user) == [tag_a]
|
||||
assert Tags.list_tags("bullets", current_user) == [tag_a]
|
||||
assert Tags.list_tags("hollow", current_user) == [tag_b]
|
||||
assert Tags.list_tags("hollows", current_user) == [tag_b]
|
||||
end
|
||||
|
||||
test "get_tag!/1 returns the tag with given id", %{tag: tag, current_user: current_user} do
|
||||
assert Tags.get_tag!(tag.id, current_user) == tag
|
||||
end
|
||||
|
@ -41,6 +41,32 @@ defmodule CanneryWeb.TagLiveTest do
|
||||
assert html =~ tag.bg_color
|
||||
end
|
||||
|
||||
test "can search for tag", %{conn: conn, tag: tag} do
|
||||
{:ok, index_live, html} = live(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
assert html =~ tag.name
|
||||
|
||||
assert index_live
|
||||
|> form("[data-qa=\"tag_search\"]",
|
||||
search: %{search_term: tag.name}
|
||||
)
|
||||
|> render_change() =~ tag.name
|
||||
|
||||
assert_patch(index_live, Routes.tag_index_path(conn, :search, tag.name))
|
||||
|
||||
refute index_live
|
||||
|> form("[data-qa=\"tag_search\"]", search: %{search_term: "something_else"})
|
||||
|> render_change() =~ tag.name
|
||||
|
||||
assert_patch(index_live, Routes.tag_index_path(conn, :search, "something_else"))
|
||||
|
||||
assert index_live
|
||||
|> form("[data-qa=\"tag_search\"]", search: %{search_term: ""})
|
||||
|> render_change() =~ tag.name
|
||||
|
||||
assert_patch(index_live, Routes.tag_index_path(conn, :index))
|
||||
end
|
||||
|
||||
test "saves new tag", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index))
|
||||
|
||||
|
Reference in New Issue
Block a user