defmodule GitGudWeb.LabelsSectionTest do
@moduledoc """
The Labels section on issue and PR pages lists every label the repo
defines, dimmed when unattached — so a repo with none defined has
nothing to put under the heading.
"""
use GitGudWeb.ConnCase, async: false
import Phoenix.LiveViewTest
import GitGud.ForgeFixtures
alias GitGud.Repositories
defp repo_path(repo) do
Repositories.Storage.repo_handle(GitGud.Repo.preload(repo, [:owner, :organization]))
end
describe "issues" do
test "no heading when the repo defines no labels", %{conn: conn} do
{user, repo} = repository_fixture()
issue = issue_fixture(repo, user)
{:ok, _lv, html} =
live(
log_in_user(conn, user),
~p"/r/#{repo_path(repo)}/#{repo.name}/issues/#{issue.number}"
)
refute html =~ ">Labels<"
end
test "the heading returns once the repo has one", %{conn: conn} do
{user, repo} = repository_fixture()
issue = issue_fixture(repo, user)
_ = label_fixture(repo, %{"name" => "bug"})
{:ok, _lv, html} =
live(
log_in_user(conn, user),
~p"/r/#{repo_path(repo)}/#{repo.name}/issues/#{issue.number}"
)
assert html =~ ">Labels<"
assert html =~ "bug"
end
test "an unattached label still shows, so it can be attached", %{conn: conn} do
{user, repo} = repository_fixture()
issue = issue_fixture(repo, user)
_ = label_fixture(repo, %{"name" => "unattached"})
{:ok, lv, html} =
live(
log_in_user(conn, user),
~p"/r/#{repo_path(repo)}/#{repo.name}/issues/#{issue.number}"
)
assert html =~ "unattached"
assert has_element?(lv, "button[phx-click=toggle_label]")
end
end
describe "pull requests" do
test "no heading when the repo defines no labels", %{conn: conn} do
{user, repo} = repository_fixture()
pr = pr_with_branches(repo, user)
{:ok, _lv, html} =
live(log_in_user(conn, user), ~p"/r/#{repo_path(repo)}/#{repo.name}/pulls/#{pr.number}")
refute html =~ ">Labels<"
end
test "the heading returns once the repo has one", %{conn: conn} do
{user, repo} = repository_fixture()
pr = pr_with_branches(repo, user)
_ = label_fixture(repo, %{"name" => "needs-review"})
{:ok, _lv, html} =
live(log_in_user(conn, user), ~p"/r/#{repo_path(repo)}/#{repo.name}/pulls/#{pr.number}")
assert html =~ ">Labels<"
assert html =~ "needs-review"
end
end
end
neiam /gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Packages
⭐
Log in to mark this repository.
2.5 KiB · text
History
6280797