You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_search_test.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  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. }