Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Dec 4, 2024
1 parent 2e8ec9d commit 00ca5e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion templates/repo/issue/sidebar/stopwatch_timetracker.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{if $.IsStopwatchRunning}}{{svg "octicon-stopwatch"}}{{end}}
</a>
<div class="menu">
<a class="item issue-stop-time show-modal" data-modal="#issue-time-set-estimate-modal">
<a class="item issue-set-time-estimate show-modal" data-modal="#issue-time-set-estimate-modal">
{{svg "octicon-pencil"}} {{ctx.Locale.Tr "repo.issues.time_estimate_set"}}
</a>
<div class="divider"></div>
Expand Down
52 changes: 27 additions & 25 deletions tests/integration/timetracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,31 @@ import (
"testing"
"time"

"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

func TestViewTimetrackingControls(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
testViewTimetrackingControls(t, session, "user2", "repo1", "1", true)
// user2/repo1
}

func TestNotViewTimetrackingControls(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user5")
testViewTimetrackingControls(t, session, "user2", "repo1", "1", false)
// user2/repo1
}
t.Run("Exist", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
session := loginUser(t, "user2")
testViewTimetrackingControls(t, session, "user2", "repo1", "1", true)
})

func TestViewTimetrackingControlsDisabled(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
testViewTimetrackingControls(t, session, "org3", "repo3", "1", false)
t.Run("Non-exist", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
session := loginUser(t, "user5")
testViewTimetrackingControls(t, session, "user2", "repo1", "1", false)
})

t.Run("Disabled", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
session := loginUser(t, "user2")
testViewTimetrackingControls(t, session, "org3", "repo3", "1", false)
})
}

func testViewTimetrackingControls(t *testing.T, session *TestSession, user, repo, issue string, canTrackTime bool) {
Expand All @@ -41,34 +42,35 @@ func testViewTimetrackingControls(t *testing.T, session *TestSession, user, repo

htmlDoc := NewHTMLParser(t, resp.Body)

htmlDoc.AssertElement(t, ".timetrack .issue-start-time", canTrackTime)
htmlDoc.AssertElement(t, ".timetrack .issue-add-time", canTrackTime)
htmlDoc.AssertElement(t, ".issue-start-time", canTrackTime)
htmlDoc.AssertElement(t, ".issue-add-time", canTrackTime)

req = NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", issue, "times", "stopwatch", "toggle"), map[string]string{
issueLink := path.Join(user, repo, "issues", issue)
req = NewRequestWithValues(t, "POST", path.Join(issueLink, "times", "stopwatch", "toggle"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
})
if canTrackTime {
resp = session.MakeRequest(t, req, http.StatusSeeOther)
resp = session.MakeRequest(t, req, http.StatusOK)

Check failure on line 53 in tests/integration/timetracking_test.go

View workflow job for this annotation

GitHub Actions / lint-backend

assigned to resp, but reassigned without using the value (wastedassign)

Check failure on line 53 in tests/integration/timetracking_test.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

assigned to resp, but reassigned without using the value (wastedassign)

Check failure on line 53 in tests/integration/timetracking_test.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

assigned to resp, but reassigned without using the value (wastedassign)

req = NewRequest(t, "GET", test.RedirectURL(resp))
req = NewRequest(t, "GET", issueLink)
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)

events := htmlDoc.doc.Find(".event > span.text")
assert.Contains(t, events.Last().Text(), "started working")

htmlDoc.AssertElement(t, ".timetrack .issue-stop-time", true)
htmlDoc.AssertElement(t, ".timetrack .issue-cancel-time", true)
htmlDoc.AssertElement(t, ".issue-stop-time", true)
htmlDoc.AssertElement(t, ".issue-cancel-time", true)

// Sleep for 1 second to not get wrong order for stopping timer
time.Sleep(time.Second)

req = NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", issue, "times", "stopwatch", "toggle"), map[string]string{
req = NewRequestWithValues(t, "POST", path.Join(issueLink, "times", "stopwatch", "toggle"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
})
resp = session.MakeRequest(t, req, http.StatusSeeOther)
resp = session.MakeRequest(t, req, http.StatusOK)

Check failure on line 71 in tests/integration/timetracking_test.go

View workflow job for this annotation

GitHub Actions / lint-backend

assigned to resp, but reassigned without using the value (wastedassign)

Check failure on line 71 in tests/integration/timetracking_test.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

assigned to resp, but reassigned without using the value (wastedassign)

Check failure on line 71 in tests/integration/timetracking_test.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

assigned to resp, but reassigned without using the value (wastedassign)

req = NewRequest(t, "GET", test.RedirectURL(resp))
req = NewRequest(t, "GET", issueLink)
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)

Expand Down

0 comments on commit 00ca5e3

Please sign in to comment.