Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

repo_search_test.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "testing"
  8. "github.com/PuerkitoBio/goquery"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
  12. resultsSelection := doc.doc.Find(".repository.search")
  13. assert.EqualValues(t, 1, resultsSelection.Length(),
  14. "Invalid template (repo search template has changed?)")
  15. filenameSelections := resultsSelection.Find(".repo-search-result").Find(".header").Find("span.file")
  16. result := make([]string, filenameSelections.Length())
  17. filenameSelections.Each(func(i int, selection *goquery.Selection) {
  18. result[i] = selection.Text()
  19. })
  20. return result
  21. }
  22. func TestSearchRepo(t *testing.T) {
  23. prepareTestEnv(t)
  24. req := NewRequestf(t, "GET", "/user2/repo1/search?q=Description&page=1")
  25. resp := MakeRequest(t, req, http.StatusOK)
  26. filenames := resultFilenames(t, NewHTMLParser(t, resp.Body))
  27. assert.EqualValues(t, []string{"README.md"}, filenames)
  28. }