@@ -172,3 +172,167 @@ func TestBuildResourcePage(t *testing.T) {
172172 }
173173 })
174174}
175+
176+ func TestViewStateKeyIncludesPageHandle (t * testing.T ) {
177+ app , _ := newApp (Option {})
178+ app .kind = ServiceKind
179+ app .cluster .ClusterArn = aws .String (clusterArn1 )
180+ cluster1Key := app .viewStateKey ()
181+
182+ app .cluster .ClusterArn = aws .String (clusterArn2 )
183+ cluster2Key := app .viewStateKey ()
184+
185+ if cluster1Key == cluster2Key {
186+ t .Errorf ("view state keys should differ between clusters, got %q" , cluster1Key )
187+ }
188+ }
189+
190+ func TestCanAutoRefreshSkipsWhileFilterInputActive (t * testing.T ) {
191+ app , _ := newApp (Option {})
192+ if ! app .canAutoRefresh () {
193+ t .Errorf ("canAutoRefresh should allow refresh by default" )
194+ }
195+
196+ app .filterInputActive = true
197+ if app .canAutoRefresh () {
198+ t .Errorf ("canAutoRefresh should skip while filter input is active" )
199+ }
200+
201+ app .filterInputActive = false
202+ app .isSuspended = true
203+ if app .canAutoRefresh () {
204+ t .Errorf ("canAutoRefresh should skip while app is suspended" )
205+ }
206+
207+ app .isSuspended = false
208+ app .secondaryKind = DescriptionKind
209+ if app .canAutoRefresh () {
210+ t .Errorf ("canAutoRefresh should skip while a secondary view is active" )
211+ }
212+ }
213+
214+ func TestShowAndHideFilterInputTogglesAutoRefreshGuard (t * testing.T ) {
215+ app , _ := newApp (Option {})
216+ v := newView (app , basicKeyInputs , nil )
217+ v .initFilterInput ()
218+
219+ err := v .showFilterInput ()
220+ if err != nil {
221+ t .Errorf ("Got: %v, Want: %v\n " , err , nil )
222+ }
223+ if ! app .filterInputActive {
224+ t .Errorf ("filterInputActive should be true after showing the filter input" )
225+ }
226+ if app .canAutoRefresh () {
227+ t .Errorf ("canAutoRefresh should skip while the filter input is shown" )
228+ }
229+
230+ v .hideFilterInput ()
231+ if app .filterInputActive {
232+ t .Errorf ("filterInputActive should be false after hiding the filter input" )
233+ }
234+ }
235+
236+ func TestFilterInputChangeSavesViewStateBeforeApply (t * testing.T ) {
237+ app , _ := newApp (Option {})
238+ app .kind = ClusterKind
239+ v := newView (app , basicKeyInputs , nil )
240+ v .initFilterInput ()
241+
242+ v .filterInput .SetText ("bravo" )
243+
244+ state , ok := app .viewStates [app .viewStateKey ()]
245+ if ! ok {
246+ t .Fatalf ("view state should be saved when filter text changes" )
247+ }
248+ if state .filterText != "bravo" {
249+ t .Errorf ("filterText Got: %q, Want: %q" , state .filterText , "bravo" )
250+ }
251+ if state .sortColumn != - 1 {
252+ t .Errorf ("sortColumn Got: %d, Want: %d" , state .sortColumn , - 1 )
253+ }
254+ }
255+
256+ func TestApplyFilterSavesNoSortState (t * testing.T ) {
257+ app , _ := newApp (Option {})
258+ app .kind = ClusterKind
259+ v := newView (app , basicKeyInputs , nil )
260+ v .headers = []string {"Name" }
261+ v .originalRowData = [][]string {
262+ {"alpha" },
263+ {"bravo" },
264+ }
265+ v .originalRowReferences = []Entity {
266+ {entityName : "alpha" },
267+ {entityName : "bravo" },
268+ }
269+ v .initFilterInput ()
270+ v .filterInput .SetText ("a" )
271+
272+ v .applyFilter ()
273+
274+ state , ok := app .viewStates [app .viewStateKey ()]
275+ if ! ok {
276+ t .Fatalf ("view state should be saved" )
277+ }
278+ if state .filterText != "a" {
279+ t .Errorf ("filterText Got: %q, Want: %q" , state .filterText , "a" )
280+ }
281+ if state .sortColumn != - 1 {
282+ t .Errorf ("sortColumn Got: %d, Want: %d" , state .sortColumn , - 1 )
283+ }
284+ if state .sortOrder != "desc" {
285+ t .Errorf ("sortOrder Got: %q, Want: %q" , state .sortOrder , "desc" )
286+ }
287+ }
288+
289+ func TestBuildResourcePageRestoresFilterOnlyStateWithoutSorting (t * testing.T ) {
290+ app , _ := newApp (Option {})
291+ app .kind = ClusterKind
292+ app .viewStates [app .viewStateKey ()] = viewState {
293+ sortColumn : - 1 ,
294+ sortOrder : "desc" ,
295+ filterText : "br" ,
296+ }
297+
298+ v := newView (app , basicKeyInputs , nil )
299+ v .originalRowReferences = []Entity {
300+ {entityName : "alpha" },
301+ {entityName : "bravo" },
302+ {entityName : "charlie" },
303+ }
304+ footer := tview .NewTextView ().SetDynamicColors (true )
305+ builder := & testResourceViewBuilder {
306+ v : v ,
307+ footer : footer ,
308+ title : "clusters" ,
309+ headers : []string {
310+ "Name" ,
311+ },
312+ rows : [][]string {
313+ {"alpha" },
314+ {"bravo" },
315+ {"charlie" },
316+ },
317+ }
318+
319+ err := buildResourcePage ([]string {"resource" }, app , nil , func () resourceViewBuilder {
320+ return builder
321+ })
322+ if err != nil {
323+ t .Errorf ("Got: %v, Want: %v\n " , err , nil )
324+ }
325+ if v .filterInput .GetText () != "br" {
326+ t .Errorf ("filter input Got: %q, Want: %q" , v .filterInput .GetText (), "br" )
327+ }
328+ if v .table .GetRowCount () != 2 {
329+ t .Errorf ("RowCount Got: %d, Want: %d" , v .table .GetRowCount (), 2 )
330+ }
331+ firstRow := v .table .GetCell (1 , 0 ).Text
332+ if firstRow != "bravo" {
333+ t .Errorf ("first row Got: %q, Want filtered row %q" , firstRow , "bravo" )
334+ }
335+ if v .sortColumn != - 1 {
336+ t .Errorf ("sortColumn Got: %d, Want: %d" , v .sortColumn , - 1 )
337+ }
338+ }
0 commit comments