Skip to content

Commit c8a72c3

Browse files
committed
Add a test for viewing an issue without labels in CLI
1 parent 5a23113 commit c8a72c3

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

command/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error {
261261
fmt.Fprintln(out, utils.Bold(issue.Title))
262262
fmt.Fprintf(out, "%s", issueStateColorFunc(issue.State))
263263
fmt.Fprint(out, utils.Gray(fmt.Sprintf(
264-
" • %s opened %s • %s",
264+
" • %s opened %s • %s",
265265
issue.Author.Login,
266266
utils.FuzzyAgo(ago),
267267
utils.Pluralize(issue.Comments.TotalCount, "comment"),
268268
)))
269269
if coloredLabels != "" {
270-
fmt.Fprintf(out, "%s", utils.Gray(coloredLabels))
270+
fmt.Fprintf(out, utils.Gray(fmt.Sprintf(" • %s", coloredLabels)))
271271
}
272272
fmt.Fprintf(out, "\n")
273273

command/issue_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,36 @@ func TestIssueView_preview(t *testing.T) {
309309
}
310310
}
311311

312+
func TestIssueView_previewNoLabel(t *testing.T) {
313+
initBlankContext("OWNER/REPO", "master")
314+
http := initFakeHTTP()
315+
http.StubRepoResponse("OWNER", "REPO")
316+
317+
jsonFile, _ := os.Open("../test/fixtures/issueView_previewNoLabel.json")
318+
defer jsonFile.Close()
319+
http.StubResponse(200, jsonFile)
320+
321+
output, err := RunCommand(issueViewCmd, "issue view -p 123")
322+
if err != nil {
323+
t.Errorf("error running command `issue view`: %v", err)
324+
}
325+
326+
eq(t, output.Stderr(), "")
327+
328+
expectedLines := []*regexp.Regexp{
329+
regexp.MustCompile(`ix of coins`),
330+
regexp.MustCompile(`OPEN • marseilles opened about 292 years ago • 9 comments`),
331+
regexp.MustCompile(`bold story`),
332+
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
333+
}
334+
for _, r := range expectedLines {
335+
if !r.MatchString(output.String()) {
336+
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
337+
return
338+
}
339+
}
340+
}
341+
312342
func TestIssueView_previewClosedState(t *testing.T) {
313343
initBlankContext("OWNER/REPO", "master")
314344
http := initFakeHTTP()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"hasIssuesEnabled": true,
5+
"issue": {
6+
"number": 123,
7+
"body": "**bold story**",
8+
"title": "ix of coins",
9+
"state": "OPEN",
10+
"created_at": "2011-01-26T19:01:12Z",
11+
"author": {
12+
"login": "marseilles"
13+
},
14+
"labels": {
15+
"nodes": [
16+
]
17+
},
18+
"comments": {
19+
"totalCount": 9
20+
},
21+
"url": "https://github.com/OWNER/REPO/issues/123"
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)