diff --git a/command/common.go b/command/common.go index 299ed030d..21726fc93 100644 --- a/command/common.go +++ b/command/common.go @@ -20,8 +20,8 @@ func getTitle(cmd *cobra.Command, cmdType string, matchCount int, totalMatchCoun } }) - title := "\n%s in %s\n\n" if totalMatchCount == 0 { + title := "\n%s in %s\n\n" msg := fmt.Sprintf("There are no open %ss", cmdType) if userSetFlagCounter > 0 { @@ -30,7 +30,7 @@ func getTitle(cmd *cobra.Command, cmdType string, matchCount int, totalMatchCoun return fmt.Sprintf(title, msg, ghrepo.FullName(baseRepo)) } - title = "\nShowing %d of %s in %s" + title := "\nShowing %d of %s in %s" if (!limitSet && userSetFlagCounter > 0) || (userSetFlagCounter > 1) { matchStr := "match" if totalMatchCount == 1 { diff --git a/command/issue_test.go b/command/issue_test.go index f803572e3..ab1b43c29 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -129,6 +129,149 @@ Showing 3 of 3 issues in OWNER/REPO } } +func TestIssueList_limit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(issueListCmd, "issue list -L 10") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 3 of 3 issues in OWNER/REPO + +`) +} + +func TestIssueList_smallLimit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(issueListCmd, "issue list -L 2") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 2 of 3 issues in OWNER/REPO + +`) +} + +func TestIssueList_multipleFilterWithLimit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(issueListCmd, "issue list -s open -l web -L 2") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 2 of 3 issues in OWNER/REPO that match your search + +`) +} + +func TestIssueList_multipleFilterWithoutLimit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(issueListCmd, "issue list -s open -l web") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 3 of 3 issues in OWNER/REPO that match your search + +`) +} + +func TestIssueList_singleFilter(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/issueList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(issueListCmd, "issue list -s open") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 3 of 3 issues in OWNER/REPO that match your search + +`) +} + +func TestIssueList_singleResultWithFilter(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + respBody := bytes.NewBufferString(`{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issues": { + "totalCount": 1, + "nodes": [ + { + "number": 1, + "title": "number won", + "url": "https://wow.com", + "labels": { + "nodes": [ + { + "name": "label" + } + ], + "totalCount": 1 + } + } + ] + } + } + } + }`) + http.StubResponse(200, respBody) + + output, err := RunCommand(issueListCmd, "issue list -s open") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 1 of 1 issue in OWNER/REPO that matches your search + +`) +} + func TestIssueList_withFlags(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() diff --git a/command/pr_test.go b/command/pr_test.go index 86be2d564..09bb9c852 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -181,6 +181,147 @@ Showing 3 of 3 pull requests in OWNER/REPO `) } +func TestPRList_limit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prListCmd, "pr list -L 10") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 3 of 3 pull requests in OWNER/REPO + +`) +} + +func TestPRList_smallLimit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prListCmd, "pr list -L 2") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 2 of 3 pull requests in OWNER/REPO + +`) +} + +func TestPRList_multipleFilterWithLimit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prListCmd, "pr list -s open -l one -L 2") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 2 of 3 pull requests in OWNER/REPO that match your search + +`) +} + +func TestPRList_multipleFilterWithoutLimit(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prListCmd, "pr list -s open -l one") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 3 of 3 pull requests in OWNER/REPO that match your search + +`) +} + +func TestPRList_singleFilter(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prList.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prListCmd, "pr list -s open") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 3 of 3 pull requests in OWNER/REPO that match your search + +`) +} + +func TestPRList_singleResultWithFilter(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + respBody := bytes.NewBufferString(`{ + "data": { + "repository": { + "pullRequests": { + "totalCount": 1, + "edges": [ + { + "node": { + "number": 32, + "title": "New feature", + "url": "https://github.com/monalisa/hello/pull/32", + "headRefName": "feature" + } + } + ], + "pageInfo": { + "hasNextPage": false, + "endCursor": "" + } + } + } + } + }`) + http.StubResponse(200, respBody) + + output, err := RunCommand(prListCmd, "pr list -s open -B develop") + if err != nil { + t.Fatal(err) + } + + eq(t, output.Stderr(), ` +Showing 1 of 1 pull request in OWNER/REPO that matches your search + +`) +} + func TestPRList_filtering(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP()