From 8c697a0d99774e15cc1c9665df9a5668855d5265 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 3 Apr 2020 22:30:58 +0900 Subject: [PATCH] Test issue metadata in CLI preview --- command/issue_test.go | 58 ++++++--- test/fixtures/issueView_preview.json | 24 +++- test/fixtures/issueView_previewNoLabel.json | 25 ---- .../issueView_previewWithLotsOfMetadata.json | 112 ++++++++++++++++++ .../issueView_previewWithMetadata.json | 87 ++++++++++++++ 5 files changed, 260 insertions(+), 46 deletions(-) delete mode 100644 test/fixtures/issueView_previewNoLabel.json create mode 100644 test/fixtures/issueView_previewWithLotsOfMetadata.json create mode 100644 test/fixtures/issueView_previewWithMetadata.json diff --git a/command/issue_test.go b/command/issue_test.go index 099f80f17..e8f3642e4 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -292,26 +292,48 @@ func TestIssueView_Preview(t *testing.T) { fixture string expectedOutputs []string }{ - "Open issue": { + "Open issue without metadata": { ownerRepo: "master", command: "issue view 123", fixture: "../test/fixtures/issueView_preview.json", expectedOutputs: []string{ - "ix of coins", - "Open • marseilles opened about 292 years ago • 9 comments", - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `Participants: marseilles`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, - "Open issue with no label": { + "Open issue with metadata": { ownerRepo: "master", command: "issue view 123", - fixture: "../test/fixtures/issueView_previewNoLabel.json", + fixture: "../test/fixtures/issueView_previewWithMetadata.json", expectedOutputs: []string{ - "ix of coins", - "Open • marseilles opened about 292 years ago • 9 comments", - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `Assignees: marseilles, monaco`, + `Labels: one, two, three`, + `Projects: The GitHub CLI \(to do list\)`, + `Milestone: uluru`, + `Participants: marseilles, monaco, montpellier`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, + }, + }, + "Open issue with lots of metadata": { + ownerRepo: "master", + command: "issue view 123", + fixture: "../test/fixtures/issueView_previewWithLotsOfMetadata.json", + expectedOutputs: []string{ + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `Assignees: marseilles, monaco, montpellier, …`, + `Labels: one, two, three, …`, + `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), …`, + `Milestone: uluru`, + `Participants: marseilles, monaco, montpellier, …`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, "Open issue with empty body": { @@ -319,9 +341,9 @@ func TestIssueView_Preview(t *testing.T) { command: "issue view 123", fixture: "../test/fixtures/issueView_previewWithEmptyBody.json", expectedOutputs: []string{ - "ix of coins", - "Open • marseilles opened about 292 years ago • 9 comments", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Open • marseilles opened about 292 years ago • 9 comments`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, "Closed issue": { @@ -329,10 +351,10 @@ func TestIssueView_Preview(t *testing.T) { command: "issue view 123", fixture: "../test/fixtures/issueView_previewClosedState.json", expectedOutputs: []string{ - "ix of coins", - "Closed • marseilles opened about 292 years ago • 9 comments", - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + `ix of coins`, + `Closed • marseilles opened about 292 years ago • 9 comments`, + `bold story`, + `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, }, }, } diff --git a/test/fixtures/issueView_preview.json b/test/fixtures/issueView_preview.json index db971d849..646278f63 100644 --- a/test/fixtures/issueView_preview.json +++ b/test/fixtures/issueView_preview.json @@ -11,12 +11,30 @@ "author": { "login": "marseilles" }, + "assignees": { + "edges": [], + "totalcount": 0 + }, "labels": { - "nodes": [ + "nodes": [], + "totalcount": 0 + }, + "projectcards": { + "edges": [], + "totalcount": 0 + }, + "milestone": { + "title": "" + }, + "participants": { + "edges": [ { - "name": "tarot" + "node": { + "login": "marseilles" + } } - ] + ], + "totalcount": 1 }, "comments": { "totalCount": 9 diff --git a/test/fixtures/issueView_previewNoLabel.json b/test/fixtures/issueView_previewNoLabel.json deleted file mode 100644 index 1891100eb..000000000 --- a/test/fixtures/issueView_previewNoLabel.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "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" - } - } - } -} diff --git a/test/fixtures/issueView_previewWithLotsOfMetadata.json b/test/fixtures/issueView_previewWithLotsOfMetadata.json new file mode 100644 index 000000000..5635ddc35 --- /dev/null +++ b/test/fixtures/issueView_previewWithLotsOfMetadata.json @@ -0,0 +1,112 @@ +{ + "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" + }, + "assignees": { + "edges": [ + { "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + }, + { + "node": { + "login": "montpellier" + } + } + ], + "totalcount": 4 + }, + "labels": { + "nodes": [ + { + "name": "one" + }, + { + "name": "two" + }, + { + "name": "three" + } + ], + "totalcount": 4 + }, + "projectcards": { + "edges": [ + { + "node": { + "project": { + "name": "Project 1" + }, + "column": { + "name": "column A" + } + } + }, + { + "node": { + "project": { + "name": "Project 2" + }, + "column": { + "name": "column B" + } + } + }, + { + "node": { + "project": { + "name": "Project 3" + }, + "column": { + "name": "column C" + } + } + } + ], + "totalcount": 4 + }, + "milestone": { + "title": "uluru" + }, + "participants": { + "edges": [ + { + "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + }, + { + "node": { + "login": "montpellier" + } + } + ], + "totalcount": 4 + }, + "comments": { + "totalcount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} diff --git a/test/fixtures/issueView_previewWithMetadata.json b/test/fixtures/issueView_previewWithMetadata.json new file mode 100644 index 000000000..dfd38c225 --- /dev/null +++ b/test/fixtures/issueView_previewWithMetadata.json @@ -0,0 +1,87 @@ +{ + "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" + }, + "assignees": { + "edges": [ + { "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + } + ], + "totalcount": 2 + }, + "labels": { + "nodes": [ + { + "name": "one" + }, + { + "name": "two" + }, + { + "name": "three" + } + ], + "totalcount": 3 + }, + "projectcards": { + "edges": [ + { + "node": { + "project": { + "name": "The GitHub CLI" + }, + "column": { + "name": "to do list" + } + } + } + ], + "totalcount": 1 + }, + "milestone": { + "title": "uluru" + }, + "participants": { + "edges": [ + { + "node": { + "login": "marseilles" + } + }, + { + "node": { + "login": "monaco" + } + }, + { + "node": { + "login": "montpellier" + } + } + ], + "totalcount": 3 + }, + "comments": { + "totalcount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +}