discourse/spec/requests/admin/problem_checks_controller_spec.rb
Ted Johansson 623f2279b0
FEATURE: Add problem checks page to admin panel and allow ignoring problem checks (#39103)
## Background

Currently you can "dismiss" problem checks on the dashboard, but if the
problem persists it will show up again on the next reload, which is
confusing.

There was previously some discussion about adding a feature to "snooze"
problem checks, but I think even with that it remains a bit too opaque.
You'd need to spelunk around in the console to try and figure out what
is going on.

## What is this change?

This PR does a couple of things:

### 1. Replace Dismiss with Ignore

Hitting ignore will prevent the problem check from creating new admin
notices until it has been unignored from the new problem checks page.

**Screenshot**

<img width="395" height="61" alt="Screenshot 2026-04-05 at 4 37 39 PM"
src="https://github.com/user-attachments/assets/4816fd04-046b-441e-9471-c160dd3f82b9"
/>

### 2. Add a new problem check page

This page provides a list of problem checks with information on whether
they are passing or failing, and when they were last run. You can also
ignore or unignore (watch) problem checks from here.

**Screenshot**

<img width="600" height="200" alt="Screenshot 2026-04-05 at 4 26 37 PM"
src="https://github.com/user-attachments/assets/d8cb2b6a-3f56-409c-97f0-312cb1545654"
/>

### 3. Remove the problem check timestamp from the dashboard

This timestamp made sense under the previous model, where all checks
were run at once and the results cached. With the new model, there's a
mix of on-demand and scheduled checks, and having a single timestamp is
misleading at best. In practice it's always going to be just the
timestamp when you last loaded the dashboard.

**Before**

<img width="240" height="100" alt="Screenshot 2026-04-05 at 4 30 21 PM"
src="https://github.com/user-attachments/assets/1846e024-0042-476e-8b5d-41b6745af75f"
/>

**After**

<img width="210" height="95" alt="Screenshot 2026-04-05 at 4 29 19 PM"
src="https://github.com/user-attachments/assets/a39c87c1-c1e3-4621-8219-e3903ba2ada4"
/>
2026-04-23 08:28:33 +08:00

99 lines
2.4 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Admin::ProblemChecksController do
fab!(:admin)
fab!(:user)
fab!(:problem_check_tracker) do
Fabricate(
:problem_check_tracker,
identifier: "rails_env",
target: ProblemCheck::NO_TARGET,
blips: 0,
last_run_at: 1.hour.ago,
last_success_at: 1.hour.ago,
)
end
describe "#index" do
context "when logged in as admin" do
before { sign_in(admin) }
it "returns problem check trackers" do
get "/admin/problem_checks.json"
expect(response.status).to eq(200)
trackers = response.parsed_body
expect(trackers.map { |t| t["identifier"] }).to contain_exactly("rails_env")
end
end
context "when not logged in as admin" do
before { sign_in(user) }
it "returns a not found error" do
get "/admin/problem_checks.json"
expect(response.status).to eq(404)
end
end
end
describe "#ignore" do
context "when tracker exists" do
before { sign_in(admin) }
it "ignores the problem" do
put "/admin/problem_checks/#{problem_check_tracker.id}/ignore.json"
expect(response.status).to eq(204)
end
end
context "when tracker does not exist" do
before { sign_in(admin) }
it "returns a not found error" do
put "/admin/problem_checks/1337/ignore.json"
expect(response.status).to eq(404)
end
end
context "when not logged in as admin" do
before { sign_in(user) }
it "returns a not found error" do
put "/admin/problem_checks/#{problem_check_tracker.id}/ignore.json"
expect(response.status).to eq(404)
end
end
end
describe "#watch" do
context "when tracker exists" do
before { sign_in(admin) }
it "watches the problem" do
put "/admin/problem_checks/#{problem_check_tracker.id}/watch.json"
expect(response.status).to eq(204)
end
end
context "when tracker does not exist" do
before { sign_in(admin) }
it "returns a not found error" do
put "/admin/problem_checks/1337/watch.json"
expect(response.status).to eq(404)
end
end
context "when not logged in as admin" do
before { sign_in(user) }
it "returns a not found error" do
put "/admin/problem_checks/#{problem_check_tracker.id}/watch.json"
expect(response.status).to eq(404)
end
end
end
end