Admin analytics: heatmap per device, anteprima staff e analisi costi.

Separa heatmap mobile/desktop, opt-out analytics per operatori, dashboard costi con KPI e trend mensili.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-28 19:25:38 +02:00
co-authored by Cursor
parent e0e07e5316
commit 29c8afb94d
43 changed files with 1572 additions and 58 deletions
+31 -1
View File
@@ -35,10 +35,40 @@ RSpec.describe "Admin analytics", type: :request do
expect(response.body).to include("40")
end
it "mostra la heatmap di una pagina" do
it "mostra la heatmap di una pagina con tab dispositivo" do
get admin_analytics_page_path, params: { page_path: "/prezzi" }
expect(response).to have_http_status(:ok)
expect(response.body).to include("admin-heatmap")
expect(response.body).to include("/prezzi")
expect(response.body).to include("is-active")
expect(response.body).to include(I18n.t("admin.analytics.devices.desktop"))
end
it "mostra solo i punti del dispositivo selezionato" do
AnalyticsPageCell.create!(
day: Time.zone.today,
page_path: "/prezzi",
device: "mobile",
cell_x: 5,
cell_y: 8,
click_count: 9,
move_count: 0
)
get admin_analytics_page_path, params: { page_path: "/prezzi", device: "mobile", layer: "click" }
expect(response).to have_http_status(:ok)
expect(response.body).to include("x&quot;:5")
expect(response.body).to include("c&quot;:9")
expect(response.body).not_to include("x&quot;:10")
end
it "attiva e disattiva l'anteprima staff" do
post admin_analytics_preview_path, params: { return_to: "/" }
expect(response).to redirect_to("/")
expect(response.cookies[Analytics::Suppress::COOKIE_NAME]).to eq("1")
delete admin_analytics_preview_path
expect(response).to redirect_to(admin_analytics_path)
expect(response.cookies[Analytics::Suppress::COOKIE_NAME]).to be_nil
end
end
+44
View File
@@ -0,0 +1,44 @@
# frozen_string_literal: true
require "rails_helper"
RSpec.describe "Admin costs", type: :request do
let!(:admin) { AdminAccount.create!(username: "ops-costs", password: "Password123") }
let(:month) { Time.zone.today.beginning_of_month }
before do
post admin_login_path, params: { username: admin.username, password: "Password123" }
PlatformCostEntry.create!(month: month, label: "Piattaforma", amount_cents: 8_500)
end
it "mostra la dashboard costi" do
get admin_costs_path, params: { month: month.strftime("%Y-%m") }
expect(response).to have_http_status(:ok)
expect(response.body).to include(I18n.t("admin.costs.index.title"))
expect(response.body).to include("85.00")
end
it "crea, aggiorna ed elimina una voce di costo" do
post admin_cost_entries_path,
params: {
platform_cost_entry: {
month: month.strftime("%Y-%m"),
label: "Stream CPX",
amount_euros: "42.50",
notes: "overflow nodes"
}
}
expect(response).to redirect_to(admin_costs_path(month: month.strftime("%Y-%m")))
entry = PlatformCostEntry.find_by(label: "Stream CPX")
expect(entry.amount_cents).to eq(4_250)
patch admin_cost_entry_path(entry),
params: { platform_cost_entry: { month: month.strftime("%Y-%m"), label: "Stream CPX", amount_euros: "50" } }
expect(response).to redirect_to(admin_costs_path(month: month.strftime("%Y-%m")))
expect(entry.reload.amount_cents).to eq(5_000)
delete admin_cost_entry_path(entry)
expect(response).to redirect_to(admin_costs_path(month: month.strftime("%Y-%m")))
expect(PlatformCostEntry.find_by(id: entry.id)).to be_nil
end
end