File: display_test.go

package info (click to toggle)
glab 1.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,936 kB
  • sloc: sh: 295; makefile: 153; perl: 99; ruby: 68; javascript: 67
file content (219 lines) | stat: -rw-r--r-- 4,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package utils

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_Indent(t *testing.T) {
	testCases := []struct {
		name   string
		input  string
		indent string
		output string
	}{
		{
			name:   "4-spaces",
			input:  "Hello Glab",
			indent: "    ",
			output: "    Hello Glab",
		},
		{
			name:   "tab",
			input:  "Hello Glab",
			indent: "\t",
			output: "\tHello Glab",
		},
		{
			name:   "prefix",
			input:  "Hello Glab",
			indent: "INFO: ",
			output: "INFO: Hello Glab",
		},
		{
			name:   "nothing",
			input:  "Hello Glab",
			indent: "",
			output: "Hello Glab",
		},
		{
			name:   "empty-string",
			input:  "",
			indent: "",
			output: "",
		},
		{
			name:   "multi-line",
			input:  "Hello\nGlab",
			indent: "- ",
			output: "- Hello\n- Glab",
		},
	}
	for _, tC := range testCases {
		t.Run(tC.name, func(t *testing.T) {
			got := Indent(tC.input, tC.indent)
			assert.Equal(t, tC.output, got)
		})
	}
}

func Test_NewListTitle(t *testing.T) {
	testCases := []struct {
		name   string
		input  string
		output ListTitleOptions
	}{
		{
			name:  "simple",
			input: "simple",
			output: ListTitleOptions{
				Name:           "simple",
				ListActionType: "list",
				Page:           1,
			},
		},
		{
			name:  "whitespace/leading",
			input: "   leading",
			output: ListTitleOptions{
				Name:           "leading",
				ListActionType: "list",
				Page:           1,
			},
		},
		{
			name:  "whitespace/trailing",
			input: "trailing    ",
			output: ListTitleOptions{
				Name:           "trailing",
				ListActionType: "list",
				Page:           1,
			},
		},
		{
			name:  "whitespace/leading-and-trailing",
			input: "   leading-and-trailing     ",
			output: ListTitleOptions{
				Name:           "leading-and-trailing",
				ListActionType: "list",
				Page:           1,
			},
		},
	}
	for _, tC := range testCases {
		t.Run(tC.name, func(t *testing.T) {
			got := NewListTitle(tC.input)
			assert.Equal(t, tC.output.Name, got.Name)
			assert.Equal(t, tC.output.ListActionType, got.ListActionType)
			assert.Equal(t, tC.output.Page, got.Page)
		})
	}
}

func Test_pluralizeName(t *testing.T) {
	testCases := []struct {
		name   string
		input  string
		amount int
		output string
	}{
		{
			name:   "singular",
			input:  "People",
			amount: 1,
			output: "People",
		},
		{
			name:   "plural",
			input:  "Human",
			amount: 3,
			output: "Humans",
		},
	}
	for _, tC := range testCases {
		t.Run(tC.name, func(t *testing.T) {
			got := pluralizeName(tC.amount, tC.input)
			assert.Equal(t, tC.output, got)
		})
	}
}

func Test_Describe(t *testing.T) {
	opts := &ListTitleOptions{
		Name:             "test",
		Page:             0,
		CurrentPageTotal: 0,
		Total:            0,
		RepoName:         "glab",
		ListActionType:   "List",
		EmptyMessage:     "nothing here",
	}

	t.Run("empty-message/present", func(t *testing.T) {
		opts := *opts

		got := opts.Describe()
		assert.Equal(t, "nothing here", got)
	})
	t.Run("empty-message/absent", func(t *testing.T) {
		opts := *opts

		opts.EmptyMessage = ""

		got := opts.Describe()
		assert.Equal(t, "No tests available on glab.", got)
	})

	t.Run("currentPageTotal/single-total", func(t *testing.T) {
		opts := *opts

		opts.Total = 0
		opts.CurrentPageTotal = 1
		opts.Page = 1

		got := opts.Describe()
		assert.Equal(t, "Showing 1 test on glab. (Page 1)\n", got)
	})

	t.Run("currentPageTotal/single-page", func(t *testing.T) {
		opts := *opts

		opts.Total = 200
		opts.CurrentPageTotal = 1
		opts.Page = 1

		got := opts.Describe()
		assert.Equal(t, "Showing 1 of 200 tests on glab. (Page 1)\n", got)
	})
	t.Run("currentPageTotal/multi-page", func(t *testing.T) {
		opts := *opts

		opts.Total = 200
		opts.CurrentPageTotal = 1
		opts.Page = 5

		got := opts.Describe()
		assert.Equal(t, "Showing 1 of 200 tests on glab. (Page 5)\n", got)
	})

	t.Run("search/match", func(t *testing.T) {
		opts := *opts

		opts.ListActionType = "search"
		opts.CurrentPageTotal = 3
		opts.Page = 1

		got := opts.Describe()
		assert.Equal(t, "Showing 3 tests in glab that match your search. (Page 1)\n", got)
	})
	t.Run("search/no-match", func(t *testing.T) {
		opts := *opts

		opts.ListActionType = "search"
		opts.CurrentPageTotal = 0

		got := opts.Describe()
		assert.Equal(t, "No tests match your search in glab.\n", got)
	})
}