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)