From 8cd6932f9ebf585311dff7a55a211dc4a234c27f Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Mon, 16 Mar 2020 04:12:26 +0900 Subject: [PATCH] Add a test for the closed issue preview --- command/issue_test.go | 30 +++++++++++++++++++ .../issueView_previewClosedState.json | 28 +++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/fixtures/issueView_previewClosedState.json diff --git a/command/issue_test.go b/command/issue_test.go index c18457623..845f2aca9 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -309,6 +309,36 @@ func TestIssueView_preview(t *testing.T) { } } +func TestIssueView_previewClosedState(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueView_previewClosedState.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(`CLOSED • marseilles opened about 292 years ago • 9 comments • tarot`), + 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_previewWithEmptyBody(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() diff --git a/test/fixtures/issueView_previewClosedState.json b/test/fixtures/issueView_previewClosedState.json new file mode 100644 index 000000000..978927125 --- /dev/null +++ b/test/fixtures/issueView_previewClosedState.json @@ -0,0 +1,28 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "CLOSED", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + { + "name": "tarot" + } + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +}