github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/pkg/cmd/pr/shared/display_test.go (about) 1 package shared 2 3 import ( 4 "testing" 5 6 "github.com/ungtb10d/cli/v2/api" 7 "github.com/ungtb10d/cli/v2/pkg/iostreams" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_listHeader(t *testing.T) { 12 type args struct { 13 repoName string 14 itemName string 15 matchCount int 16 totalMatchCount int 17 hasFilters bool 18 } 19 tests := []struct { 20 name string 21 args args 22 want string 23 }{ 24 { 25 name: "one result", 26 args: args{ 27 repoName: "REPO", 28 itemName: "genie", 29 matchCount: 1, 30 totalMatchCount: 23, 31 hasFilters: false, 32 }, 33 want: "Showing 1 of 23 open genies in REPO", 34 }, 35 { 36 name: "one result after filters", 37 args: args{ 38 repoName: "REPO", 39 itemName: "tiny cup", 40 matchCount: 1, 41 totalMatchCount: 23, 42 hasFilters: true, 43 }, 44 want: "Showing 1 of 23 tiny cups in REPO that match your search", 45 }, 46 { 47 name: "one result in total", 48 args: args{ 49 repoName: "REPO", 50 itemName: "chip", 51 matchCount: 1, 52 totalMatchCount: 1, 53 hasFilters: false, 54 }, 55 want: "Showing 1 of 1 open chip in REPO", 56 }, 57 { 58 name: "one result in total after filters", 59 args: args{ 60 repoName: "REPO", 61 itemName: "spicy noodle", 62 matchCount: 1, 63 totalMatchCount: 1, 64 hasFilters: true, 65 }, 66 want: "Showing 1 of 1 spicy noodle in REPO that matches your search", 67 }, 68 { 69 name: "multiple results", 70 args: args{ 71 repoName: "REPO", 72 itemName: "plant", 73 matchCount: 4, 74 totalMatchCount: 23, 75 hasFilters: false, 76 }, 77 want: "Showing 4 of 23 open plants in REPO", 78 }, 79 { 80 name: "multiple results after filters", 81 args: args{ 82 repoName: "REPO", 83 itemName: "boomerang", 84 matchCount: 4, 85 totalMatchCount: 23, 86 hasFilters: true, 87 }, 88 want: "Showing 4 of 23 boomerangs in REPO that match your search", 89 }, 90 } 91 for _, tt := range tests { 92 t.Run(tt.name, func(t *testing.T) { 93 if got := ListHeader(tt.args.repoName, tt.args.itemName, tt.args.matchCount, tt.args.totalMatchCount, tt.args.hasFilters); got != tt.want { 94 t.Errorf("listHeader() = %v, want %v", got, tt.want) 95 } 96 }) 97 } 98 } 99 100 func TestPrCheckStatusSummaryWithColor(t *testing.T) { 101 testCases := []struct { 102 Name string 103 args api.PullRequestChecksStatus 104 want string 105 }{ 106 { 107 Name: "No Checks", 108 args: api.PullRequestChecksStatus{ 109 Total: 0, 110 Failing: 0, 111 Passing: 0, 112 Pending: 0, 113 }, 114 want: "No checks", 115 }, 116 { 117 Name: "All Passing", 118 args: api.PullRequestChecksStatus{ 119 Total: 3, 120 Failing: 0, 121 Passing: 3, 122 Pending: 0, 123 }, 124 want: "✓ Checks passing", 125 }, 126 { 127 Name: "Some pending", 128 args: api.PullRequestChecksStatus{ 129 Total: 3, 130 Failing: 0, 131 Passing: 1, 132 Pending: 2, 133 }, 134 want: "- Checks pending", 135 }, 136 { 137 Name: "Sll failing", 138 args: api.PullRequestChecksStatus{ 139 Total: 3, 140 Failing: 3, 141 Passing: 0, 142 Pending: 0, 143 }, 144 want: "× All checks failing", 145 }, 146 { 147 Name: "Some failing", 148 args: api.PullRequestChecksStatus{ 149 Total: 3, 150 Failing: 2, 151 Passing: 1, 152 Pending: 0, 153 }, 154 want: "× 2/3 checks failing", 155 }, 156 } 157 158 ios, _, _, _ := iostreams.Test() 159 ios.SetStdoutTTY(true) 160 ios.SetAlternateScreenBufferEnabled(true) 161 cs := ios.ColorScheme() 162 163 for _, testCase := range testCases { 164 out := PrCheckStatusSummaryWithColor(cs, testCase.args) 165 assert.Equal(t, testCase.want, out) 166 } 167 168 }