mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 13:25:36 +03:00
test(code-search): add for options dropdown
This commit is contained in:
parent
663e957d3d
commit
30d07c3ba3
1 changed files with 22 additions and 24 deletions
|
@ -79,25 +79,25 @@ func testSearchRepo(t *testing.T, indexer bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=loren&page=1&fuzzy=false", []string{"a.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=loren&page=1&mode=exact", []string{"a.txt"}, indexer)
|
||||||
|
|
||||||
if indexer {
|
if indexer {
|
||||||
// fuzzy search: matches both file3 (x/b.txt) and file1 (a.txt)
|
// fuzzy search: matches both file3 (x/b.txt) and file1 (a.txt)
|
||||||
// when indexer is enabled
|
// when indexer is enabled
|
||||||
testSearch(t, "/user2/glob/search?q=file3&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=file3&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file4&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=file4&mode=fuzzy&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)
|
testSearch(t, "/user2/glob/search?q=file5&mode=fuzzy&page=1", []string{"x/b.txt", "a.txt"}, indexer)
|
||||||
} else {
|
} else {
|
||||||
// fuzzy search: Union/OR of all the keywords
|
// fuzzy search: Union/OR of all the keywords
|
||||||
// when indexer is disabled
|
// 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=file3+file1&mode=union&page=1", []string{"a.txt", "x/b.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file4&page=1", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file4&mode=union&page=1", []string{}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file5&page=1", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file5&mode=union&page=1", []string{}, indexer)
|
||||||
}
|
}
|
||||||
|
|
||||||
testSearch(t, "/user2/glob/search?q=file3&page=1&fuzzy=false", []string{"x/b.txt"}, indexer)
|
testSearch(t, "/user2/glob/search?q=file3&page=1&mode=fuzzy", []string{"x/b.txt"}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file4&page=1&fuzzy=false", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file4&page=1&mode=fuzzy", []string{}, indexer)
|
||||||
testSearch(t, "/user2/glob/search?q=file5&page=1&fuzzy=false", []string{}, indexer)
|
testSearch(t, "/user2/glob/search?q=file5&page=1&mode=fuzzy", []string{}, indexer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSearch(t *testing.T, url string, expected []string, indexer bool) {
|
func testSearch(t *testing.T, url string, expected []string, indexer bool) {
|
||||||
|
@ -113,21 +113,19 @@ func testSearch(t *testing.T, url string, expected []string, indexer bool) {
|
||||||
branchDropdown := container.Find(".js-branch-tag-selector")
|
branchDropdown := container.Find(".js-branch-tag-selector")
|
||||||
assert.EqualValues(t, indexer, len(branchDropdown.Nodes) == 0)
|
assert.EqualValues(t, indexer, len(branchDropdown.Nodes) == 0)
|
||||||
|
|
||||||
// if indexer is disabled "fuzzy" should be displayed as "union"
|
dropdownOptions := container.
|
||||||
expectedFuzzy := "Fuzzy"
|
Find(".menu[data-test-tag=fuzzy-dropdown]").
|
||||||
if !indexer {
|
Find("input[type=radio][name=mode]").
|
||||||
expectedFuzzy = "Union"
|
Map(func(_ int, sel *goquery.Selection) string {
|
||||||
}
|
attr, exists := sel.Attr("value")
|
||||||
|
assert.True(t, exists)
|
||||||
|
return attr
|
||||||
|
})
|
||||||
|
|
||||||
fuzzyDropdown := container.Find(".ui.dropdown[data-test-tag=fuzzy-dropdown]")
|
if indexer {
|
||||||
actualFuzzyText := fuzzyDropdown.Find(".menu .item[data-value=true]").First().Text()
|
assert.EqualValues(t, []string{"exact", "fuzzy"}, dropdownOptions)
|
||||||
assert.EqualValues(t, expectedFuzzy, actualFuzzyText)
|
} else {
|
||||||
|
assert.EqualValues(t, []string{"exact", "union", "regexp"}, dropdownOptions)
|
||||||
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)
|
filenames := resultFilenames(t, doc)
|
||||||
|
|
Loading…
Reference in a new issue