feat(web): console pages for monitors, incidents and notification channels
The dashboard lists monitors with status, latency and 24-hour uptime bars rendered as SVG on the server; monitor pages add 90-day uptime, latency and recent checks; an editor shows the settings of the selected check type. Closes #17 Closes #19 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
9a050ea712
commit
b831478143
18 files changed
+4268
-323
No files matched your search
@@ -0,0 +1,84 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// page fetches path and returns the final status, path and body.
|
||||
func (b *browser) page(path string) (int, string, string) {
|
||||
b.t.Helper()
|
||||
resp, err := b.hc.Get(b.base + path)
|
||||
if err != nil {
|
||||
b.t.Fatalf("GET %s failed: %v", path, err)
|
||||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return resp.StatusCode, resp.Request.URL.Path, string(body)
|
||||
}
|
||||
|
||||
func TestConsolePages(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
t.Cleanup(cancel)
|
||||
go e.api.RunScheduler(ctx)
|
||||
|
||||
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
}))
|
||||
defer target.Close()
|
||||
tok, region := e.platformChecker(t, uniq("eu-"))
|
||||
e.startChecker(t, tok)
|
||||
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("p")+".test", uniq("pages-"))
|
||||
st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{
|
||||
"name": "Checkout API", "type": "http", "target": target.URL, "interval_seconds": 60,
|
||||
"confirmations": 1, "regions": []string{region}, "config": map[string]any{"keyword": "ok"},
|
||||
})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create monitor = %d %v", st, body)
|
||||
}
|
||||
id := body["id"].(string)
|
||||
waitFor(t, 10*time.Second, "incident opened", func() bool {
|
||||
_, body := owner.do("GET", "/api/v1/org/incidents", nil)
|
||||
return len(body["incidents"].([]any)) == 1
|
||||
})
|
||||
owner.do("POST", "/api/v1/org/channels", map[string]any{"name": "Hook", "type": "webhook", "url": "https://hooks.example.test/x"})
|
||||
|
||||
pages := map[string][]string{
|
||||
"/": {"Checkout API", "<svg"},
|
||||
"/monitors/" + id: {"Checkout API", "unexpected status 502"},
|
||||
"/monitors/" + id + "/edit": {`value="Checkout API"`, `name="config.keyword"`, `value="ok"`},
|
||||
"/monitors/new": {`name="regions"`},
|
||||
"/incidents": {"Checkout API", "unexpected status 502"},
|
||||
"/settings/channels": {"hooks.example.test"},
|
||||
}
|
||||
for path, wants := range pages {
|
||||
st, final, html := owner.page(path)
|
||||
if st != http.StatusOK || final != path {
|
||||
t.Errorf("GET %s = %d at %s", path, st, final)
|
||||
continue
|
||||
}
|
||||
for _, w := range wants {
|
||||
if !strings.Contains(html, w) {
|
||||
t.Errorf("GET %s: page lacks %q", path, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewer := e.joinVia(t, owner.invite("v@"+uniq("v")+".test", owner.roleID("viewer")))
|
||||
for path, want := range map[string]string{"/monitors/new": "/", "/monitors/" + id + "/edit": "/", "/monitors/" + id: "/monitors/" + id} {
|
||||
if _, final, _ := viewer.page(path); final != want {
|
||||
t.Errorf("viewer GET %s ended at %s, want %s", path, final, want)
|
||||
}
|
||||
}
|
||||
if _, _, html := viewer.page("/"); strings.Contains(html, "/monitors/new") {
|
||||
t.Error("viewer dashboard offers creating monitors")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user