Skip to content

Commit

Permalink
test for all possible titles
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahzadUmair committed Mar 3, 2020
1 parent 945d4ff commit 77a6caa
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 2 deletions.
4 changes: 2 additions & 2 deletions command/common.go
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
143 changes: 143 additions & 0 deletions command/issue_test.go
Expand Up @@ -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()
Expand Down
141 changes: 141 additions & 0 deletions command/pr_test.go
Expand Up @@ -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()
Expand Down

0 comments on commit 77a6caa

Please sign in to comment.