fix(code search): various ui/ux improvements raised by user research (#4332)
various improvements from [user research](https://codeberg.org/forgejo/user-research/src/branch/main/interviews/2024-06/issues%28search%2Cfeatures%29%2Cselfhosting%2CCI%2Caccessibility%2Ccodesearch.md) - filenames are links to the respective files fixes: `fold menu: user clicked and expected to view file, instead the file collapsed` - refactor(searchfile.tmpl): ordered lists with lines grouped together instead of table fixes: `multiple matches per file are "merged", only visible in the code lines (no visual separation)` - feat: display fuzzy as "Either" when using git-grep which is much more accurate than "fuzzy" git-grep does not support fuzzy searching, in this context selecting fuzzy searching worked similar to an OR of white space separated keywords fixes: `typo doesn't bring results in fuzzy search` --- <details> <summary>Before</summary>  </details> <details> <summary>After</summary>  </details> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4332 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com> Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
parent
2d85d51879
commit
928f188689
7 changed files with 88 additions and 24 deletions
|
@ -20,11 +20,20 @@ import (
|
|||
)
|
||||
|
||||
func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
|
||||
filenameSelections := doc.Find(".repository.search").Find("details.repo-search-result").Find(".header").Find("span.file")
|
||||
result := make([]string, filenameSelections.Length())
|
||||
filenameSelections.Each(func(i int, selection *goquery.Selection) {
|
||||
result[i] = selection.Text()
|
||||
resultSelections := doc.
|
||||
Find(".repository.search").
|
||||
Find("details.repo-search-result")
|
||||
|
||||
result := make([]string, resultSelections.Length())
|
||||
resultSelections.Each(func(i int, selection *goquery.Selection) {
|
||||
assert.True(t, resultSelections.Find("div ol li").Length() > 0)
|
||||
result[i] = selection.
|
||||
Find(".header").
|
||||
Find("span.file a.file-link").
|
||||
First().
|
||||
Text()
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -77,7 +86,7 @@ func testSearchRepo(t *testing.T, indexer bool) {
|
|||
testSearch(t, "/user2/glob/search?q=file4&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file5&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||
} else {
|
||||
// fuzzy search: OR of all the keywords
|
||||
// fuzzy search: Union/OR of all the keywords
|
||||
// when indexer is disabled
|
||||
testSearch(t, "/user2/glob/search?q=file3+file1&page=1", []string{"a.txt", "x/b.txt"}, indexer)
|
||||
testSearch(t, "/user2/glob/search?q=file4&page=1", []string{}, indexer)
|
||||
|
@ -102,6 +111,23 @@ func testSearch(t *testing.T, url string, expected []string, indexer bool) {
|
|||
branchDropdown := container.Find(".js-branch-tag-selector")
|
||||
assert.EqualValues(t, indexer, len(branchDropdown.Nodes) == 0)
|
||||
|
||||
// if indexer is disabled "fuzzy" should be displayed as "union"
|
||||
expectedFuzzy := "Fuzzy"
|
||||
if !indexer {
|
||||
expectedFuzzy = "Union"
|
||||
}
|
||||
|
||||
fuzzyDropdown := container.Find(".ui.dropdown[data-test-tag=fuzzy-dropdown]")
|
||||
actualFuzzyText := fuzzyDropdown.Find(".menu .item[data-value=true]").First().Text()
|
||||
assert.EqualValues(t, expectedFuzzy, actualFuzzyText)
|
||||
|
||||
if fuzzyDropdown.
|
||||
Find("input[name=fuzzy][value=true]").
|
||||
Length() != 0 {
|
||||
actualFuzzyText = fuzzyDropdown.Find("div.text").First().Text()
|
||||
assert.EqualValues(t, expectedFuzzy, actualFuzzyText)
|
||||
}
|
||||
|
||||
filenames := resultFilenames(t, doc)
|
||||
assert.EqualValues(t, expected, filenames)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue