You've already forked caddy-opnsense-blocker
Adopt Tabulator for the requests log
This commit is contained in:
@@ -69,6 +69,9 @@ func TestHandlerServesOverviewAndManualActions(t *testing.T) {
|
||||
if eventPage.Page != 2 || !eventPage.HasPrev {
|
||||
t.Fatalf("unexpected event page payload: %+v", eventPage)
|
||||
}
|
||||
if eventPage.LastPage != 2 || eventPage.TotalItems != 251 || len(eventPage.Data) != len(eventPage.Items) {
|
||||
t.Fatalf("event page should expose tabulator pagination metadata: %+v", eventPage)
|
||||
}
|
||||
if app.lastEventOptions.Offset != 250 ||
|
||||
app.lastEventOptions.Source != "main" ||
|
||||
app.lastEventOptions.Method != "GET" ||
|
||||
@@ -166,7 +169,7 @@ func TestHandlerServesOverviewAndManualActions(t *testing.T) {
|
||||
t.Fatalf("unexpected requests log page status: %d", recorder.Code)
|
||||
}
|
||||
queryLogBody := recorder.Body.String()
|
||||
if !strings.Contains(queryLogBody, "Filters, sorting, and pagination") {
|
||||
if !strings.Contains(queryLogBody, "Filters, pagination, and columns") {
|
||||
t.Fatalf("requests log page should expose the collapsible controls panel")
|
||||
}
|
||||
if !strings.Contains(queryLogBody, `<select id="source-filter">`) || !strings.Contains(queryLogBody, `<option value="main">main</option>`) {
|
||||
@@ -187,20 +190,23 @@ func TestHandlerServesOverviewAndManualActions(t *testing.T) {
|
||||
if !strings.Contains(queryLogBody, `id="column-source"`) || !strings.Contains(queryLogBody, `id="column-reason"`) {
|
||||
t.Fatalf("requests log page should expose column visibility controls")
|
||||
}
|
||||
if !strings.Contains(queryLogBody, "Request") {
|
||||
t.Fatalf("requests log page should render the request table")
|
||||
if !strings.Contains(queryLogBody, `id="requests-table"`) {
|
||||
t.Fatalf("requests log page should render the tabulator mount point")
|
||||
}
|
||||
if !strings.Contains(queryLogBody, "Auto refresh") {
|
||||
t.Fatalf("requests log page should expose the auto refresh toggle")
|
||||
}
|
||||
if !strings.Contains(queryLogBody, "onclick=\"applySort('status')\"") {
|
||||
t.Fatalf("requests log page should expose clickable sortable columns")
|
||||
if !strings.Contains(queryLogBody, `/assets/tabulator/tabulator.min.js`) || !strings.Contains(queryLogBody, `/assets/tabulator/tabulator_midnight.min.css`) {
|
||||
t.Fatalf("requests log page should load local tabulator assets")
|
||||
}
|
||||
if !strings.Contains(queryLogBody, "Source") || !strings.Contains(queryLogBody, "Bots") || !strings.Contains(queryLogBody, "HTTP status") {
|
||||
t.Fatalf("requests log page should expose source, bot, and status filters")
|
||||
}
|
||||
if !strings.Contains(queryLogBody, "Previous") || !strings.Contains(queryLogBody, "Next") {
|
||||
t.Fatalf("requests log page should expose pagination controls")
|
||||
recorder = httptest.NewRecorder()
|
||||
request = httptest.NewRequest(http.MethodGet, "/assets/tabulator/tabulator.min.js", nil)
|
||||
handler.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK || recorder.Body.Len() == 0 {
|
||||
t.Fatalf("tabulator asset should be served locally: status=%d len=%d", recorder.Code, recorder.Body.Len())
|
||||
}
|
||||
|
||||
recorder = httptest.NewRecorder()
|
||||
@@ -239,6 +245,10 @@ type stubApp struct {
|
||||
lastEventOptions model.EventListOptions
|
||||
}
|
||||
|
||||
func (s *stubApp) CountEvents(context.Context, time.Time, model.EventListOptions) (int64, error) {
|
||||
return 251, nil
|
||||
}
|
||||
|
||||
func (s *stubApp) ListSourceNames() []string {
|
||||
return []string{"gitea", "main"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user