@@ -233,3 +233,52 @@ func toAppModel(teaModel tea.Model, cmd tea.Cmd) (app.Model, tea.Cmd) {
233233
234234 return appModel , cmd
235235}
236+
237+ func TestAppViewFilterClear (t * testing.T ) {
238+ const termIncluded = "included"
239+
240+ const jsonFile = `
241+ {"time":"1970-01-01T00:00:00.00","level":"INFO","message": "` + termIncluded + `"}
242+ `
243+
244+ appModel := newTestModel (t , []byte (jsonFile ))
245+
246+ rendered := appModel .View ()
247+ assert .Contains (t , rendered , termIncluded )
248+
249+ // Open filter.
250+ appModel , _ = toAppModel (appModel .Update (tea.KeyMsg {
251+ Type : tea .KeyRunes ,
252+ Runes : []rune {'f' },
253+ }))
254+ assert .True (t , appModel .IsFilterShown (), appModel .View ())
255+
256+ // Filter to exclude everything.
257+ appModel , _ = toAppModel (appModel .Update (tea.KeyMsg {
258+ Type : tea .KeyRunes ,
259+ Runes : []rune (termIncluded + "_not_found" ),
260+ }))
261+ appModel , cmd := toAppModel (appModel .Update (tea.KeyMsg {
262+ Type : tea .KeyEnter ,
263+ }))
264+ assert .False (t , appModel .IsFilterShown (), appModel .View ())
265+
266+ appModel , _ = toAppModel (appModel .Update (cmd ()))
267+
268+ rendered = appModel .View ()
269+ assert .NotContains (t , rendered , termIncluded )
270+
271+ // Come back
272+ appModel , cmd = toAppModel (appModel .Update (tea.KeyMsg {
273+ Type : tea .KeyEsc ,
274+ }))
275+ assert .False (t , appModel .IsFilterShown (), appModel .View ())
276+
277+ appModel , _ = toAppModel (appModel .Update (cmd ()))
278+
279+ // Assert.
280+ if assert .False (t , appModel .IsFiltered ()) {
281+ rendered = appModel .View ()
282+ assert .Contains (t , rendered , termIncluded )
283+ }
284+ }
0 commit comments