Alerts: Matrix room can actually be chosen

The format field got the Matrix room label but not its choice, so the
screen offered only text and JSON and the Matrix fields never showed.
The script and its tests were fine; nothing tested the screen picking
it, which the new test does from the keyboard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vvvomitandClaude Opus 5.5 committed 2026-10-29 06:08:30 +03:30
1 parent 94d5ac8d8c
commit b7a32cf44e
2 files changed
+32 -1

No files matched your search

+1 -1
View File
@@ -59,7 +59,7 @@ func (s *alertsScreen) enter(c *config.Config) tea.Cmd {
"The server checks itself, even when this computer is off: failed services, the homeserver not answering, a certificate expiring within 14 days, a disk over 90% full, a mirror not answering. Once a day, new entries in the playbook's changelog too."),
textField("url", "Send them to", a.URL, example,
"An ntfy topic (subscribe to it in the ntfy app), or a webhook: a Hookshot room webhook, Slack, Discord or Mattermost. Anyone who knows an ntfy topic can read it, so make it long and random."),
choiceField("format", "Message format", []string{"text", "json"},
choiceField("format", "Message format", []string{"text", "json", "matrix"},
[]string{"Plain text (ntfy)", `JSON {"text": …} (webhooks)`, "Matrix room"}, format,
"A Matrix room gets them as formatted messages. An alert that the homeserver is down can't arrive through that same homeserver, so a room on another server, or ntfy, is safer."),
textField("hs", "Homeserver", hs, "https://matrix.example.org", "The homeserver of the account that posts the alerts."),
+31
View File
@@ -1,8 +1,11 @@
package ui
import (
"strings"
"testing"
tea "github.com/charmbracelet/bubbletea"
"interzone/internal/config"
)
@@ -26,3 +29,31 @@ func TestAlerts(t *testing.T) {
t.Errorf("saved %+v", a.cfg.Alerts)
}
}
// Matrix room is picked like the other formats, from the keyboard, and
// swaps the address for the room's fields.
func TestAlertsMatrixRoom(t *testing.T) {
a := demoApp(t, 120, 36)
a.jump(a.index("Alerts"))
s := a.cur().(*alertsScreen)
s.form.get("on").on = true
if !strings.Contains(s.view(120, 34), "Matrix room") {
t.Fatal("no Matrix room choice")
}
s.form.focusOn(2)
if s.form.fields[2].key != "format" {
t.Fatal("the format isn't the third field")
}
s.update(tea.KeyMsg{Type: tea.KeyRight})
s.update(tea.KeyMsg{Type: tea.KeyRight})
if s.form.value("format") != "matrix" || s.form.get("url").visible() || !s.form.get("token").visible() {
t.Fatalf("format %q, url shown %v, token shown %v", s.form.value("format"), s.form.get("url").visible(), s.form.get("token").visible())
}
s.form.get("room").input.SetValue("#alerts:example.org")
s.form.get("token").input.SetValue("syt_secret")
deliver(a, formDoneMsg{})
got := a.cfg.Alerts
if !got.Matrix || got.Homeserver != "https://matrix.example.org" || got.Room != "#alerts:example.org" || got.Token != "syt_secret" {
t.Errorf("saved %+v (%s)", got, s.err)
}
}