Files
interzone/internal/ui/refresh_test.go
T
vvvomitandClaude Opus 5.5 9637d477c6 Faster Users changes, a live Dashboard
Users:
- A change shows on its row as soon as the server has made it, and the
  list is refreshed behind it without locking the screen. Before, a
  deactivation waited for the change and then for a full reload.
- The admin script asks for each person's rooms, sessions and email a
  few at a time instead of one by one (60 people at 20 ms a request:
  3.9 s → 0.7 s).
- With MAS, the admin list from mas-cli is fetched alongside the user
  list instead of after it. Plays get a file name of their own, as two
  of a kind can now run at once.

Dashboard:
- Refreshes itself every 5 seconds while it's open (30 after a failure),
  and checks the certificates every 5 minutes or on r.

Both:
- A screen's answer now reaches it even if another screen is showing
  when it arrives. Leaving the Dashboard mid-refresh used to leave it
  waiting forever, so it never refreshed again until interzone restarted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 05:11:56 +03:30

77 lines
2.5 KiB
Go

package ui
import (
"testing"
"time"
"interzone/internal/deploy"
)
// A dashboard left while it refreshes still gets its answer, so it doesn't
// wait for it forever.
func TestResultReachesItsScreen(t *testing.T) {
a := demoApp(t, 120, 36)
openDashboard(a)
ds := a.cur().(*dashboardScreen)
ds.loading = true
a.jump(a.index("Users"))
a.Update(statusMsg{server: ds.server, st: &deploy.ServerStatus{Taken: time.Now(), Hostname: "fresh"}, certs: true})
if ds.loading || ds.st.Hostname != "fresh" {
t.Fatalf("the dashboard missed its answer: loading %v, host %q", ds.loading, ds.st.Hostname)
}
}
func TestDashboardRefreshesItself(t *testing.T) {
a := demoApp(t, 120, 36)
openDashboard(a)
ds := a.cur().(*dashboardScreen)
certs := ds.st.Certs
if a.Update(statusMsg{server: ds.server, st: &deploy.ServerStatus{Taken: time.Now()}}); ds.gen != 1 {
t.Fatalf("no refresh scheduled after an answer (gen %d)", ds.gen)
}
if len(ds.st.Certs) != len(certs) {
t.Errorf("an answer without certificates dropped the last ones")
}
if _, cmd := a.Update(dashTickMsg{server: ds.server, gen: 0}); cmd != nil || ds.loading {
t.Errorf("an old tick refreshed")
}
if _, cmd := a.Update(dashTickMsg{server: ds.server, gen: 1}); cmd == nil || !ds.loading {
t.Errorf("the tick didn't refresh")
}
ds.loading = false
a.jump(a.index("Users"))
if a.Update(statusMsg{server: ds.server, st: &deploy.ServerStatus{Taken: time.Now()}}); ds.gen != 1 {
t.Errorf("refreshing while off screen")
}
}
// A change shows on the list straight away, and the list stays usable
// while it's refreshed behind it.
func TestUsersChangeShowsAtOnce(t *testing.T) {
a := demoApp(t, 120, 36)
openUsers(a)
us := a.cur().(*usersScreen)
a.Update(userOpMsg{op: &userOp{user: "@bob:example.org", body: map[string]any{"deactivated": true}}, info: "@bob:example.org deactivated"})
var bob deploy.MatrixUser
for _, u := range us.list.Users {
if u.ID == "@bob:example.org" {
bob = u
}
}
if !bob.Deactivated || bob.Rooms != 0 || bob.Devices != 0 {
t.Errorf("bob isn't shown deactivated: %+v", bob)
}
if us.busy || !us.syncing {
t.Errorf("busy %v, syncing %v; want the list usable and refreshing", us.busy, us.syncing)
}
n := len(us.list.Users)
a.Update(usersMsg{server: us.server, gen: us.gen - 1, list: &deploy.UserList{}})
if len(us.list.Users) != n {
t.Errorf("an older reload replaced the list")
}
a.Update(usersMsg{server: us.server, gen: us.gen, list: &deploy.UserList{Rooms: 1}})
if us.syncing || us.list.Rooms != 1 {
t.Errorf("the latest reload wasn't taken")
}
}