okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
5e287ce
main
1package tui 2 3import ( 4"albedo/cli/internal/daemon" 5"albedo/cli/internal/testwire" 6"encoding/json" 7"net/http" 8"slices" 9"testing" 10 11 tea"charm.land/bubbletea/v2" 12) 13 14// settleApp runs cmd and feeds every message it produces back into app, as the 15// program would, leaving out the preview timers. 16func settleApp (app * AppModel ,cmd tea.Cmd ) { 17queue := []tea.Cmd {cmd } 18for len (queue )> 0 { 19next := queue [0 ] 20queue = queue [1 :] 21if next == nil { 22continue 23 } 24switch msg := next ().(type ) { 25case tea.BatchMsg : 26queue = append (queue ,msg ... ) 27case nil ,sessionPreviewTickMsg ,sessionsLoadedMsg : 28default : 29updated ,more := app .Update (msg ) 30* app = * updated .(* AppModel ) 31queue = append (queue ,more ) 32 } 33 } 34} 35 36// A session list requested before an archive answers after it; the picker 37// must not bring the archived row back from that older listing. 38func TestArchiveOutlivesAnOlderSessionListing (t * testing.T ) { 39conn := commandTestConnection (t ,func (w http.ResponseWriter ,r * http.Request ) { 40session := testwire .Session ("s1" ,testwire .GenerationA ,0 ) 41resource := session ["configuration_resource" ].(map [string ]any ) 42switch r .Method { 43case "GET" : 44w .Header ().Set ("ETag" ,resource ["etag" ].(string )) 45_ = json .NewEncoder (w ).Encode (resource ["value" ]) 46case "PATCH" : 47session ["preferences" ].(map [string ]any )["archived" ]= true 48resource ["value" ].(map [string ]any )["preferences" ].(map [string ]any )["archived" ]= true 49_ = json .NewEncoder (w ).Encode (map [string ]any {"resource" :resource ,"session" :session ,"move" :nil }) 50 } 51 }) 52app := NewAppModel (conn ,Bootstrap {},nil ,"" ,false ,nil ) 53app .State = AppStateSessionPicker 54listed := []daemon.Session {{ID :"s1" ,Title :"one" ,Workspace :"/work" }} 55updated ,_ := app .Update (sessionsLoadedMsg {Gen :app .SessionGen ,Sessions :listed }) 56app = updated .(* AppModel ) 57// Reopening the list asks for a listing that answers after the archive. 58app .openSessions () 59older := sessionsLoadedMsg {Gen :app .SessionGen ,Sessions :slices .Clone (listed )} 60 61updated ,cmd := app .Update (tea.KeyPressMsg {Code :'a' ,Mod :tea .ModCtrl }) 62app = updated .(* AppModel ) 63settleApp (app ,cmd ) 64if ! app .SessionPicker .archivedIDs ["s1" ] { 65t .Fatalf ("ctrl+a did not archive the row: %q" ,app .SessionPicker .notice ) 66 } 67updated ,cmd = app .Update (older ) 68app = updated .(* AppModel ) 69settleApp (app ,cmd ) 70if ! app .SessionPicker .archivedIDs ["s1" ] { 71t .Fatal ("an older listing brought the archived session back" ) 72 } 73}