github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/pkg/cmd/pr/shared/display_test.go (about)

     1  package shared
     2  
     3  import "testing"
     4  
     5  func Test_listHeader(t *testing.T) {
     6  	type args struct {
     7  		repoName        string
     8  		itemName        string
     9  		matchCount      int
    10  		totalMatchCount int
    11  		hasFilters      bool
    12  	}
    13  	tests := []struct {
    14  		name string
    15  		args args
    16  		want string
    17  	}{
    18  		{
    19  			name: "no results",
    20  			args: args{
    21  				repoName:        "REPO",
    22  				itemName:        "table",
    23  				matchCount:      0,
    24  				totalMatchCount: 0,
    25  				hasFilters:      false,
    26  			},
    27  			want: "There are no open tables in REPO",
    28  		},
    29  		{
    30  			name: "no matches after filters",
    31  			args: args{
    32  				repoName:        "REPO",
    33  				itemName:        "Luftballon",
    34  				matchCount:      0,
    35  				totalMatchCount: 0,
    36  				hasFilters:      true,
    37  			},
    38  			want: "No Luftballons match your search in REPO",
    39  		},
    40  		{
    41  			name: "one result",
    42  			args: args{
    43  				repoName:        "REPO",
    44  				itemName:        "genie",
    45  				matchCount:      1,
    46  				totalMatchCount: 23,
    47  				hasFilters:      false,
    48  			},
    49  			want: "Showing 1 of 23 open genies in REPO",
    50  		},
    51  		{
    52  			name: "one result after filters",
    53  			args: args{
    54  				repoName:        "REPO",
    55  				itemName:        "tiny cup",
    56  				matchCount:      1,
    57  				totalMatchCount: 23,
    58  				hasFilters:      true,
    59  			},
    60  			want: "Showing 1 of 23 tiny cups in REPO that match your search",
    61  		},
    62  		{
    63  			name: "one result in total",
    64  			args: args{
    65  				repoName:        "REPO",
    66  				itemName:        "chip",
    67  				matchCount:      1,
    68  				totalMatchCount: 1,
    69  				hasFilters:      false,
    70  			},
    71  			want: "Showing 1 of 1 open chip in REPO",
    72  		},
    73  		{
    74  			name: "one result in total after filters",
    75  			args: args{
    76  				repoName:        "REPO",
    77  				itemName:        "spicy noodle",
    78  				matchCount:      1,
    79  				totalMatchCount: 1,
    80  				hasFilters:      true,
    81  			},
    82  			want: "Showing 1 of 1 spicy noodle in REPO that matches your search",
    83  		},
    84  		{
    85  			name: "multiple results",
    86  			args: args{
    87  				repoName:        "REPO",
    88  				itemName:        "plant",
    89  				matchCount:      4,
    90  				totalMatchCount: 23,
    91  				hasFilters:      false,
    92  			},
    93  			want: "Showing 4 of 23 open plants in REPO",
    94  		},
    95  		{
    96  			name: "multiple results after filters",
    97  			args: args{
    98  				repoName:        "REPO",
    99  				itemName:        "boomerang",
   100  				matchCount:      4,
   101  				totalMatchCount: 23,
   102  				hasFilters:      true,
   103  			},
   104  			want: "Showing 4 of 23 boomerangs in REPO that match your search",
   105  		},
   106  	}
   107  	for _, tt := range tests {
   108  		t.Run(tt.name, func(t *testing.T) {
   109  			if got := ListHeader(tt.args.repoName, tt.args.itemName, tt.args.matchCount, tt.args.totalMatchCount, tt.args.hasFilters); got != tt.want {
   110  				t.Errorf("listHeader() = %v, want %v", got, tt.want)
   111  			}
   112  		})
   113  	}
   114  }