mirror of
https://github.com/go-gitea/gitea.git
synced 2024-05-11 05:55:29 +00:00
8d5f58d834
* Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <[email protected]> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <[email protected]> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <[email protected]> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <[email protected]> * Correcting spelling mistakes Signed-off-by: Jonas Franz <[email protected]> * Change error message to a short version Signed-off-by: Jonas Franz <[email protected]> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <[email protected]> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <[email protected]> * Fixed test + gofmt Signed-off-by: Jonas Franz <[email protected]> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <[email protected]> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <[email protected]> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <[email protected]> * Fix test Signed-off-by: Jonas Franz <[email protected]> * Change comment from SQL query to description Signed-off-by: Jonas Franz <[email protected]> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <[email protected]> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <[email protected]> * Check if timetracker is enabled Signed-off-by: Jonas Franz <[email protected]> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <[email protected]>
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIssueList_LoadRepositories(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
issueList := IssueList{
|
|
AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
|
|
AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
|
|
AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
|
|
}
|
|
|
|
repos, err := issueList.LoadRepositories()
|
|
assert.NoError(t, err)
|
|
assert.Len(t, repos, 2)
|
|
for _, issue := range issueList {
|
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
|
}
|
|
}
|
|
|
|
func TestIssueList_LoadAttributes(t *testing.T) {
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
setting.Service.EnableTimetracking = true
|
|
issueList := IssueList{
|
|
AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
|
|
AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
|
|
AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
|
|
}
|
|
|
|
assert.NoError(t, issueList.LoadAttributes())
|
|
for _, issue := range issueList {
|
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
|
for _, label := range issue.Labels {
|
|
assert.EqualValues(t, issue.RepoID, label.RepoID)
|
|
AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
|
}
|
|
if issue.PosterID > 0 {
|
|
assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
|
|
}
|
|
if issue.AssigneeID > 0 {
|
|
assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
|
|
}
|
|
if issue.MilestoneID > 0 {
|
|
assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
|
|
}
|
|
if issue.IsPull {
|
|
assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
|
|
}
|
|
for _, attachment := range issue.Attachments {
|
|
assert.EqualValues(t, issue.ID, attachment.IssueID)
|
|
}
|
|
for _, comment := range issue.Comments {
|
|
assert.EqualValues(t, issue.ID, comment.IssueID)
|
|
}
|
|
if issue.ID == int64(1) {
|
|
assert.Equal(t, int64(400), issue.TotalTrackedTime)
|
|
} else if issue.ID == int64(2) {
|
|
assert.Equal(t, int64(3662), issue.TotalTrackedTime)
|
|
}
|
|
}
|
|
}
|