handler_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package feed
  2. import (
  3. "net/http"
  4. "testing"
  5. "github.com/cryptix/exp/multiModulePage/router"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestOverview(t *testing.T) {
  9. setup(t)
  10. defer teardown()
  11. a := assert.New(t)
  12. url, err := router.FeedApp(nil).Get(router.FeedOverview).URL()
  13. a.Nil(err)
  14. html, resp := testClient.GetHTML(url.String(), nil)
  15. a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code")
  16. a.Equal(html.Find("#welcome").Text(), "Welcome!")
  17. }
  18. func TestPost(t *testing.T) {
  19. setup(t)
  20. defer teardown()
  21. a := assert.New(t)
  22. url, err := router.FeedApp(nil).Get(router.FeedPost).URL("PostID", "1")
  23. a.Nil(err)
  24. html, resp := testClient.GetHTML(url.String(), nil)
  25. a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code")
  26. a.Equal(html.Find("h1").Text(), db[1].Name)
  27. }
  28. func TestURLTo(t *testing.T) {
  29. setup(t)
  30. defer teardown()
  31. a := assert.New(t)
  32. url, err := router.FeedApp(nil).Get(router.FeedPost).URL("PostID", "1")
  33. a.Nil(err)
  34. html, resp := testClient.GetHTML(url.String(), nil)
  35. a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code")
  36. a.Equal(html.Find("h1").Text(), db[1].Name)
  37. lnk, ok := html.Find("#overview").Attr("href")
  38. a.True(ok)
  39. a.Equal("/", lnk)
  40. lnk, ok = html.Find("#next").Attr("href")
  41. a.True(ok)
  42. a.Equal("/post/3", lnk)
  43. }