From ab6ea6a743e0dc9aa2e4c19201fb42533858a843 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Fri, 29 Aug 2025 18:56:54 +0200 Subject: [PATCH] fix(ui): restore code search types (#9053) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix regression of https://codeberg.org/forgejo/forgejo/pulls/8736 Preview Before: https://codeberg.org/attachments/d46743e7-beb3-404e-a103-ea8068760171 After: https://codeberg.org/attachments/0d9dcdb7-7b4f-4bbc-8776-67fd364e26a9 Reported-by: Antonin Delpeuch Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9053 Reviewed-by: Beowulf Reviewed-by: Antonin Delpeuch Reviewed-by: Gusted Reviewed-by: Ellen Εμιλία Άννα Zscheile --- modules/git/grep.go | 1 + modules/indexer/code/search.go | 1 + options/locale/locale_en-US.ini | 6 ++++++ tests/integration/repo_search_test.go | 24 +++++++++++++++++++++--- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/modules/git/grep.go b/modules/git/grep.go index 3703b13660..b5471b8f6c 100644 --- a/modules/git/grep.go +++ b/modules/git/grep.go @@ -36,6 +36,7 @@ const ( RegExpGrepMode ) +// llu:TrKeysSuffix search. var GrepSearchOptions = [3]string{"exact", "union", "regexp"} type GrepOptions struct { diff --git a/modules/indexer/code/search.go b/modules/indexer/code/search.go index 499b9117c4..66c9497dab 100644 --- a/modules/indexer/code/search.go +++ b/modules/indexer/code/search.go @@ -35,6 +35,7 @@ type SearchResultLanguages = internal.SearchResultLanguages type SearchOptions = internal.SearchOptions +// llu:TrKeysSuffix search. var CodeSearchOptions = [2]string{"exact", "union"} type SearchMode = internal.CodeSearchMode diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index dbb1c73c11..1cd5c5c640 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -167,6 +167,12 @@ user_kind = Search users… org_kind = Search orgs… team_kind = Search teams… code_kind = Search code… +union = Union +union_tooltip = Include results that match any of the whitespace separated keywords +exact = Exact +exact_tooltip = Include only results that match the exact search term +regexp = RegExp +regexp_tooltip = Interpret the search term as a regular expression code_search_unavailable = Code search is currently not available. Please contact the site administrator. package_kind = Search packages… project_kind = Search projects… diff --git a/tests/integration/repo_search_test.go b/tests/integration/repo_search_test.go index b145d9f427..874970fe56 100644 --- a/tests/integration/repo_search_test.go +++ b/tests/integration/repo_search_test.go @@ -1,11 +1,14 @@ // Copyright 2017 The Gitea Authors. All rights reserved. +// Copyright 2024-2025 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package integration import ( + "fmt" "net/http" "net/url" + "strings" "testing" "forgejo.org/models/db" @@ -13,6 +16,7 @@ import ( code_indexer "forgejo.org/modules/indexer/code" "forgejo.org/modules/setting" "forgejo.org/modules/test" + "forgejo.org/modules/translation" "forgejo.org/routers" "forgejo.org/tests" @@ -112,11 +116,12 @@ func testSearch(t *testing.T, rawURL string, expected []string, indexer bool) { return attr }) + expectedTypes := []string{"exact", "union", "regexp"} if indexer { - assert.Equal(t, []string{"exact", "union"}, dropdownOptions) - } else { - assert.Equal(t, []string{"exact", "union", "regexp"}, dropdownOptions) + expectedTypes = []string{"exact", "union"} } + assert.Equal(t, expectedTypes, dropdownOptions) + testDropdownOptions(t, container, expectedTypes, translation.NewLocale("en-US")) filenames := resultFilenames(t, doc) assert.ElementsMatch(t, expected, filenames) @@ -124,6 +129,19 @@ func testSearch(t *testing.T, rawURL string, expected []string, indexer bool) { testSearchPagination(t, rawURL, doc) } +// testDropdownOptions verifies additional properties of dropdown options +func testDropdownOptions(t *testing.T, container *goquery.Selection, options []string, locale translation.Locale) { + for _, option := range options { + label := container.Find(fmt.Sprintf("label.item:has(input[value='%s'])", option)) + name := strings.TrimSpace(label.Text()) + assert.Equal(t, name, locale.TrString(fmt.Sprintf("search.%s", option))) + + tooltip, exists := label.Attr("data-tooltip-content") + assert.True(t, exists) + assert.Equal(t, tooltip, locale.TrString(fmt.Sprintf("search.%s_tooltip", option))) + } +} + // Tests that the variables set in the url persist for all the paginated links func testSearchPagination(t *testing.T, rawURL string, doc *HTMLDoc) { original, err := queryFromStr(rawURL)