Add a test for viewing an issue without labels in CLI

This commit is contained in:
Toshiya Doi 2020-03-16 04:23:05 +09:00
parent 5a23113b5b
commit c8a72c3bcb
3 changed files with 57 additions and 2 deletions

View file

@ -261,13 +261,13 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error {
fmt.Fprintln(out, utils.Bold(issue.Title))
fmt.Fprintf(out, "%s", issueStateColorFunc(issue.State))
fmt.Fprint(out, utils.Gray(fmt.Sprintf(
" • %s opened %s • %s",
" • %s opened %s • %s",
issue.Author.Login,
utils.FuzzyAgo(ago),
utils.Pluralize(issue.Comments.TotalCount, "comment"),
)))
if coloredLabels != "" {
fmt.Fprintf(out, "%s", utils.Gray(coloredLabels))
fmt.Fprintf(out, utils.Gray(fmt.Sprintf(" • %s", coloredLabels)))
}
fmt.Fprintf(out, "\n")

View file

@ -309,6 +309,36 @@ func TestIssueView_preview(t *testing.T) {
}
}
func TestIssueView_previewNoLabel(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/issueView_previewNoLabel.json")
defer jsonFile.Close()
http.StubResponse(200, jsonFile)
output, err := RunCommand(issueViewCmd, "issue view -p 123")
if err != nil {
t.Errorf("error running command `issue view`: %v", err)
}
eq(t, output.Stderr(), "")
expectedLines := []*regexp.Regexp{
regexp.MustCompile(`ix of coins`),
regexp.MustCompile(`OPEN • marseilles opened about 292 years ago • 9 comments`),
regexp.MustCompile(`bold story`),
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
}
for _, r := range expectedLines {
if !r.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
}
func TestIssueView_previewClosedState(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()

View file

@ -0,0 +1,25 @@
{
"data": {
"repository": {
"hasIssuesEnabled": true,
"issue": {
"number": 123,
"body": "**bold story**",
"title": "ix of coins",
"state": "OPEN",
"created_at": "2011-01-26T19:01:12Z",
"author": {
"login": "marseilles"
},
"labels": {
"nodes": [
]
},
"comments": {
"totalCount": 9
},
"url": "https://github.com/OWNER/REPO/issues/123"
}
}
}
}