mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-25 07:06:00 +08:00
936665bf85
Redesign the time tracker side bar, and add "time estimate" support (in "1d 2m" format) Closes #23112 --------- Co-authored-by: stuzer05 <stuzer05@gmail.com> Co-authored-by: Yarden Shoham <hrsi88@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
// Copyright 2024 Gitea. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTimeStr(t *testing.T) {
|
|
t.Run("Parse", func(t *testing.T) {
|
|
// Test TimeEstimateParse
|
|
tests := []struct {
|
|
input string
|
|
output int64
|
|
err bool
|
|
}{
|
|
{"1h", 3600, false},
|
|
{"1m", 60, false},
|
|
{"1s", 1, false},
|
|
{"1h 1m 1s", 3600 + 60 + 1, false},
|
|
{"1d1x", 0, true},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.input, func(t *testing.T) {
|
|
output, err := TimeEstimateParse(test.input)
|
|
if test.err {
|
|
assert.NotNil(t, err)
|
|
} else {
|
|
assert.Nil(t, err)
|
|
}
|
|
assert.Equal(t, test.output, output)
|
|
})
|
|
}
|
|
})
|
|
t.Run("String", func(t *testing.T) {
|
|
tests := []struct {
|
|
input int64
|
|
output string
|
|
}{
|
|
{3600, "1h"},
|
|
{60, "1m"},
|
|
{1, "1s"},
|
|
{3600 + 1, "1h 1s"},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.output, func(t *testing.T) {
|
|
output := TimeEstimateString(test.input)
|
|
assert.Equal(t, test.output, output)
|
|
})
|
|
}
|
|
})
|
|
}
|