grep: add tests

This commit is contained in:
Shiny Nematoda 2024-05-07 15:15:05 +05:30
parent 46a5b13292
commit ab69c1a694
3 changed files with 38 additions and 1 deletions

View File

@ -11,7 +11,7 @@
{{if $description}}<span class="description">{{$description | RenderCodeBlock}}</span>{{else}}<span class="no-description text-italic">{{ctx.Locale.Tr "repo.no_desc"}}</span>{{end}}
{{if .Repository.Website}}<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>{{end}}
</div>
<form class="ignore-dirty" action="{{.RepoLink}}/search/{{if .CodeIndexerDisabled}}{{.BranchNameSubURL}}{{end}}" method="get">
<form class="ignore-dirty" action="{{.RepoLink}}/search/{{if .CodeIndexerDisabled}}{{.BranchNameSubURL}}{{end}}" method="get" data-test-tag="codesearch">
<div class="ui small action input">
<input name="q" value="{{.Keyword}}" placeholder="{{ctx.Locale.Tr "search.code_kind"}}">
{{template "shared/search/button"}}

View File

@ -48,6 +48,13 @@ func testSearchRepo(t *testing.T, indexer bool) {
testSearch(t, "/user2/repo1/search?q=Description&page=1", []string{"README.md"}, indexer)
req := NewRequest(t, "HEAD", "/user2/repo1/search/branch/master")
if indexer {
MakeRequest(t, req, http.StatusNotFound)
} else {
MakeRequest(t, req, http.StatusOK)
}
defer test.MockVariableValue(&setting.Indexer.IncludePatterns, setting.IndexerGlobFromString("**.txt"))()
defer test.MockVariableValue(&setting.Indexer.ExcludePatterns, setting.IndexerGlobFromString("**/y/**"))()

View File

@ -995,3 +995,33 @@ func TestViewRepoOpenWith(t *testing.T) {
testOpenWith([]string{"test://"})
})
}
func TestRepoCodeSearchForm(t *testing.T) {
defer tests.PrepareTestEnv(t)()
testSearchForm := func(t *testing.T, indexer bool) {
defer test.MockVariableValue(&setting.Indexer.RepoIndexerEnabled, indexer)()
req := NewRequest(t, "GET", "/user2/repo1/src/branch/master")
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
action, exists := htmlDoc.doc.Find("form[data-test-tag=codesearch]").Attr("action")
assert.True(t, exists)
branchSubURL := "/branch/master"
if indexer {
assert.NotContains(t, action, branchSubURL)
} else {
assert.Contains(t, action, branchSubURL)
}
}
t.Run("indexer disabled", func(t *testing.T) {
testSearchForm(t, false)
})
t.Run("indexer enabled", func(t *testing.T) {
testSearchForm(t, true)
})
}