Show the last event as a relative time with a UTC tooltip (closes #567)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The "Last event" figure in the webhook page's Statistics block now shows how long ago the newest event arrived, as its two largest units of d, h, m and s with no spaces ("59s", "1m1s", "3d4h"; a zero second unit is left off). It is worked out when the page is served, and a time ahead of the server clock shows "0s". Its tooltip is the full time in UTC. With no event it still shows "none", without a tooltip. A unit test pins each unit boundary, and the headless-browser test checks the figure and its tooltip.
Model: opus-5-5
This commit was merged in pull request #568.
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