Exemplo n.º 1
0
func TestVoteBox(t *testing.T) {
	score := c.NewScore(69)
	server := hm.NewMock(map[string]hm.Responder{
		"/v": hm.FuncResponder(func(c *hm.Context) hm.Response {
			var vote, lastVote int
			// get values from the query parameters
			fmt.Sscan(c.Request.URL.Query().Get("vote"), &vote)
			fmt.Sscan(c.Request.URL.Query().Get("lastvote"), &lastVote)

			score.UserVote(vote, lastVote)

			return hm.NewOKResponse(fmt.Sprint(score.Score))
		}),
	})

	fntest.NewDummyTestApp("/", server)

	votebox := &VoteBoxModel{}
	votebox.VoteUrl = "/v"
	votebox.Vote = score

	// Start testing
	server.Wait(func() { votebox.DoVote(1) }, 1)
	require.Equal(t, votebox.Vote.Score, 70)
	server.Wait(func() { votebox.DoVote(-1) }, 1)
	require.Equal(t, votebox.Vote.Score, 68)
	server.Wait(func() { votebox.DoVote(-1) }, 1)
	require.Equal(t, votebox.Vote.Score, 69)
}
Exemplo n.º 2
0
// AddComment submits the written comment
func (m *CommentsPageVM) AddComment() {
	comment := &c.Comment{
		Author:  "me",
		Content: m.NewComment,
		Time:    0,
		Vote:    c.NewScore(1),
	}

	go func() {
		// Http request
		m.httpClient.POST(
			fmt.Sprintf("/api/comment/add/%v", m.Post.Id),
			comment)

		// Add the comment to the displayed comment list afterwards
		m.Comments = append([]*c.Comment{comment}, m.Comments...)
		m.NewComment = ""
		app().Render()
	}()
}
Exemplo n.º 3
0
var (
	TestDb = []*c.Post{
		&c.Post{
			Id:     3,
			Author: "poster1",
			Title:  "title1",
			Labels: []string{"label1", "label2"},
			Time:   30,
			Link:   "http://dummy-link.com",
			Comments: []*c.Comment{
				&c.Comment{
					Id:      1,
					Author:  "commenter1",
					Content: "comment1",
					Time:    6,
					Vote:    c.NewScore(3),
				},
				&c.Comment{
					Id:      2,
					Author:  "commenter2",
					Content: "comment2",
					Time:    7,
					Vote:    c.NewScore(4),
				},
			},
			Vote: c.NewScore(96),
		},

		&c.Post{
			Id:      3,
			Author:  "poster2",