Show the last event as a relative time with a UTC tooltip (closes #567)
check / check (push) Waiting to run
check / check (push) Waiting to run
The Statistics block's "Last event" figure now shows how long ago the
newest event arrived, as its two largest units ("59s", "1m1s", "3d4h"),
worked out when the page is served. Its tooltip is the full time in
UTC. With no event it still shows "none", without a tooltip.
Model: opus-5-5
This commit is contained in:
@@ -61,7 +61,8 @@ const (
|
||||
// event log in a headless browser, served by the real router and so
|
||||
// under the real Content-Security-Policy, and checks that the pages'
|
||||
// Alpine.js directives, the copy control and the delete prompts work,
|
||||
// and that a target's row shows its delivery counts.
|
||||
// that a target's row shows its delivery counts, and that the
|
||||
// Statistics block shows how long ago the last event arrived.
|
||||
func TestAlpineRunsUnderTheSecurityPolicy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -97,6 +98,7 @@ func TestAlpineRunsUnderTheSecurityPolicy(t *testing.T) {
|
||||
checkCopy(ctx, t, page)
|
||||
checkEntrypointEdit(ctx, t, page, page+"/events")
|
||||
checkRecentEvents(ctx, t, page)
|
||||
checkStatsLastEvent(ctx, t, env, webhook.ID, page)
|
||||
checkArchiveChoice(ctx, t, srv.URL+"/hooks/new", page)
|
||||
checkNewWebhookTargets(ctx, t, env, srv.URL+"/hooks/new")
|
||||
checkRefusedNewWebhook(ctx, t, srv.URL+"/hooks/new")
|
||||
@@ -831,6 +833,41 @@ func checkRecentEvents(ctx context.Context, t *testing.T, url string) {
|
||||
"the event's own page does not show its body")
|
||||
}
|
||||
|
||||
// checkStatsLastEvent records that the last event of the webhook
|
||||
// webhookID arrived 3 days, 4 hours and 30 minutes ago, loads its page,
|
||||
// and checks that the Statistics block shows the last event as "3d4h"
|
||||
// with the full time in UTC as its tooltip.
|
||||
func checkStatsLastEvent(
|
||||
ctx context.Context, t *testing.T, env *testEnv, webhookID, url string,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
webhookDB, err := env.dbMgr.GetDB(webhookID)
|
||||
require.NoError(t, err)
|
||||
|
||||
ago := 3*24*time.Hour + 4*time.Hour + 30*time.Minute
|
||||
arrived := time.Now().Add(-ago)
|
||||
require.NoError(t, database.AddEventTotals(webhookDB,
|
||||
database.EventTotals{LastEventAt: &arrived}))
|
||||
|
||||
figure := `//span[text()="Last event"]` +
|
||||
`/following-sibling::span[text()="3d4h"]`
|
||||
|
||||
var (
|
||||
title string
|
||||
found bool
|
||||
)
|
||||
|
||||
require.NoError(t, chromedp.Run(ctx, loadPage(url)))
|
||||
require.True(t, shown(ctx, figure),
|
||||
`the Statistics block does not show the last event as "3d4h"`)
|
||||
require.NoError(t, chromedp.Run(ctx, chromedp.AttributeValue(
|
||||
figure, "title", &title, &found, chromedp.BySearch,
|
||||
)))
|
||||
assert.Equal(t, arrived.UTC().Format(time.DateTime)+" UTC", title,
|
||||
"the last event's tooltip is not the full time in UTC")
|
||||
}
|
||||
|
||||
// checkEventLog loads the event log and checks that of its events only
|
||||
// the newest, eventID, starts expanded: its row says so and its caret is
|
||||
// turned up, and the log's last event, lastEventID, starts collapsed. In
|
||||
|
||||
Reference in New Issue
Block a user