Add tests for utilities of PR/issue state format
This commit is contained in:
parent
46a632c8f6
commit
0cfa4be86a
5 changed files with 48 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/cli/cli/utils"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestIssueStatus(t *testing.T) {
|
||||
|
|
@ -585,3 +586,24 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
|
|||
eq(t, url, "https://github.com/OWNER/REPO/issues/new?title=mytitle&body=mybody")
|
||||
eq(t, output.String(), "Opening github.com/OWNER/REPO/issues/new in your browser.\n")
|
||||
}
|
||||
|
||||
func TestIssueStateTitleWithColor(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
state string
|
||||
want string
|
||||
}{
|
||||
|
||||
"Open state": {state: "OPEN", want: "Open"},
|
||||
"Closed state": {state: "CLOSED", want: "Closed"},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got := issueStateTitleWithColor(tc.state)
|
||||
diff := cmp.Diff(tc.want, got)
|
||||
if diff != "" {
|
||||
t.Fatalf(diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,9 +236,8 @@ func prStateTitleWithColor(pr api.PullRequest) string {
|
|||
func colorFuncForPR(pr api.PullRequest) func(string) string {
|
||||
if pr.State == "OPEN" && pr.IsDraft {
|
||||
return utils.Gray
|
||||
} else {
|
||||
return utils.ColorFuncForState(pr.State)
|
||||
}
|
||||
return utils.ColorFuncForState(pr.State)
|
||||
}
|
||||
|
||||
func prView(cmd *cobra.Command, args []string) error {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/cli/cli/utils"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/shlex"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
|
@ -780,3 +781,25 @@ func TestReplaceExcessiveWhitespace(t *testing.T) {
|
|||
eq(t, replaceExcessiveWhitespace("hello goodbye"), "hello goodbye")
|
||||
eq(t, replaceExcessiveWhitespace(" hello \n goodbye "), "hello goodbye")
|
||||
}
|
||||
|
||||
func TestPrStateTitleWithColor(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
state string
|
||||
want string
|
||||
}{
|
||||
|
||||
"Format OPEN state": {state: "OPEN", want: "Open"},
|
||||
"Format CLOSED state": {state: "CLOSED", want: "Closed"},
|
||||
"Format MERGED state": {state: "MERGED", want: "Merged"},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got := issueStateTitleWithColor(tc.state)
|
||||
diff := cmp.Diff(tc.want, got)
|
||||
if diff != "" {
|
||||
t.Fatalf(diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue