Go · 1899 bytes Raw Blame History
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2
3 package handlers
4
5 import (
6 "net/http/httptest"
7 "testing"
8 )
9
10 func TestGlobalIssueSearchTextDropsDashboardOperators(t *testing.T) {
11 t.Parallel()
12
13 got := globalIssueSearchText("is:issue state:open archived:false assignee:@me sort:updated-desc flaky deploy")
14 if got != "flaky deploy" {
15 t.Fatalf("globalIssueSearchText = %q, want %q", got, "flaky deploy")
16 }
17 }
18
19 func TestStateTabsDropStaleQueryStateOperators(t *testing.T) {
20 t.Parallel()
21
22 tabs := stateTabs("/issues/assigned", "is:issue state:closed archived:false bug", "closed", globalIssueCounts{
23 Total: 3,
24 Open: 1,
25 Closed: 2,
26 })
27 if got := tabs[0].Href; got != "/issues/assigned?q=is%3Aissue+archived%3Afalse+bug" {
28 t.Fatalf("open state href = %q", got)
29 }
30 if got := tabs[1].Href; got != "/issues/assigned?q=is%3Aissue+archived%3Afalse+bug&state=closed" {
31 t.Fatalf("closed state href = %q", got)
32 }
33 }
34
35 func TestGlobalStateFromRequestHonorsQueryOperators(t *testing.T) {
36 t.Parallel()
37
38 req := httptest.NewRequest("GET", "/issues/assigned?state=open", nil)
39 if got := globalStateFromRequest(req, "is:issue state:closed archived:false"); got != "closed" {
40 t.Fatalf("globalStateFromRequest state:closed = %q, want closed", got)
41 }
42
43 req = httptest.NewRequest("GET", "/issues/assigned?state=all", nil)
44 if got := globalStateFromRequest(req, ""); got != "all" {
45 t.Fatalf("globalStateFromRequest query param = %q, want all", got)
46 }
47 }
48
49 func TestDashboardHrefOmitsEmptyQuery(t *testing.T) {
50 t.Parallel()
51
52 if got := dashboardHref("/pulls", queryValues("", "open", "created")); got != "/pulls" {
53 t.Fatalf("dashboardHref default values = %q, want /pulls", got)
54 }
55 if got := dashboardHref("/pulls", queryValues("state:closed bug", "closed", "assigned")); got != "/pulls?q=state%3Aclosed+bug&state=closed&view=assigned" {
56 t.Fatalf("dashboardHref populated values = %q", got)
57 }
58 }
59