fix(ui): restore code search types (#9053)

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 <antonin@delpeuch.eu>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9053
Reviewed-by: Beowulf <beowulf@beocode.eu>
Reviewed-by: Antonin Delpeuch <wetneb@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Ellen Εμιλία Άννα Zscheile <fogti@noreply.codeberg.org>
This commit is contained in:
0ko 2025-08-29 18:56:54 +02:00
commit ab6ea6a743
4 changed files with 29 additions and 3 deletions

View file

@ -36,6 +36,7 @@ const (
RegExpGrepMode
)
// llu:TrKeysSuffix search.
var GrepSearchOptions = [3]string{"exact", "union", "regexp"}
type GrepOptions struct {

View file

@ -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

View file

@ -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…

View file

@ -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)