From 160efced12e1815e82f85c4acedbc47d2ce5a899 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 6 Aug 2024 17:09:01 +0200 Subject: [PATCH] [BUG] Ensure all filters are persistent in issue filters - Ensure that all filters are set in the issue filters links, thus becoming persistent. - Adds integration test - Resolves #4843 (cherry picked from commit 192177fc88169a394fd194f1046b7fe8e6210901) --- templates/repo/issue/filter_list.tmpl | 62 ++--- templates/shared/issuelist.tmpl | 2 +- templates/shared/label_filter.tmpl | 6 +- tests/integration/repo_test.go | 330 ++++++++++++++++++++++++++ 4 files changed, 365 insertions(+), 35 deletions(-) diff --git a/templates/repo/issue/filter_list.tmpl b/templates/repo/issue/filter_list.tmpl index f60389766e..09f87b582f 100644 --- a/templates/repo/issue/filter_list.tmpl +++ b/templates/repo/issue/filter_list.tmpl @@ -3,7 +3,7 @@ {{if not .Milestone}} - - - diff --git a/templates/shared/label_filter.tmpl b/templates/shared/label_filter.tmpl index 9daeb3f100..2269271aac 100644 --- a/templates/shared/label_filter.tmpl +++ b/templates/shared/label_filter.tmpl @@ -23,8 +23,8 @@ {{ctx.Locale.Tr "repo.issues.filter_label_exclude"}}
- {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} + {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} {{$exclusiveScope := .ExclusiveScope}} @@ -32,7 +32,7 @@
{{end}} {{$previousExclusiveScope = $exclusiveScope}} - + {{if .IsExcluded}} {{svg "octicon-circle-slash"}} {{else if .IsSelected}} diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 2637d9b4d8..a107722fd9 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -1047,3 +1047,333 @@ func TestFileHistoryPager(t *testing.T) { MakeRequest(t, req, http.StatusNotFound) }) } + +func TestRepoIssueFilterLinks(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + t.Run("No filters", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Keyword", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?q=search-on-this") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=search-on-this") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Fuzzy", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?fuzzy=true") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=true") + }) + assert.True(t, called) + }) + + t.Run("Sort", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?sort=oldest") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-sort a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=oldest") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Type", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?type=assigned") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-type a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=assigned") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("State", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?state=closed") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.issue-list-toolbar-left a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=closed") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Miilestone", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?milestone=1") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-milestone a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=1") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Milestone", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?milestone=1") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-milestone a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=1") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Project", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?project=1") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-project a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=1") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Assignee", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?assignee=1") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-assignee a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=1") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Poster", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?poster=1") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.list-header-poster a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=1") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Labels", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?labels=1") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']:not(.label-filter a)").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=1") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + }) + assert.True(t, called) + }) + + t.Run("Archived labels", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues?archived=true") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + called := false + htmlDoc.Find("#issue-filters a[href^='?']").Each(func(_ int, s *goquery.Selection) { + called = true + href, _ := s.Attr("href") + assert.Contains(t, href, "?q=&") + assert.Contains(t, href, "&type=") + assert.Contains(t, href, "&sort=") + assert.Contains(t, href, "&state=") + assert.Contains(t, href, "&labels=") + assert.Contains(t, href, "&milestone=") + assert.Contains(t, href, "&project=") + assert.Contains(t, href, "&assignee=") + assert.Contains(t, href, "&poster=") + assert.Contains(t, href, "&fuzzy=") + assert.Contains(t, href, "&archived=true") + }) + assert.True(t, called) + }) +}