Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

jobs:
test-coordinator:
Expand Down
2 changes: 1 addition & 1 deletion console-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Client-side variables used by the app:
- `NEXT_PUBLIC_SOLANA_RPC_URL` - Solana RPC endpoint
- `NEXT_PUBLIC_GA_MEASUREMENT_ID` - optional public Google Analytics 4 measurement ID

Analytics stays disabled unless `NEXT_PUBLIC_GA_MEASUREMENT_ID` is set **and** consent is granted. When a measurement ID is configured, the app shows a small in-app prompt so users can allow or decline privacy-filtered usage analytics. Consent is persisted in `localStorage` under `darkbloom_ga_consent` (`granted` or `denied`), and a declined choice keeps analytics disabled until the user explicitly changes it later from Settings.
Analytics stays disabled unless `NEXT_PUBLIC_GA_MEASUREMENT_ID` is set **and** consent is granted. When a measurement ID is configured, the app shows a small in-app prompt so users can allow or decline privacy-filtered usage analytics. Consent is persisted in `localStorage` under `darkbloom_ga_consent` (`granted` or `denied`) and mirrored to a `.darkbloom.dev` cookie so the landing page and console share the same choice. A declined choice keeps analytics disabled until the user explicitly changes it later from Settings.

### Google Analytics setup

Expand Down
14 changes: 2 additions & 12 deletions console-ui/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ beforeEach(() => {
fetchMock = vi.fn();
vi.stubGlobal("fetch", fetchMock);

// Provide a minimal localStorage so getConfig() works
const store: Record<string, string> = {};
vi.stubGlobal("localStorage", {
getItem: (k: string) => store[k] ?? null,
setItem: (k: string, v: string) => {
store[k] = v;
},
removeItem: (k: string) => {
delete store[k];
},
});
localStorage.clear();
});

afterEach(() => {
Expand All @@ -66,7 +56,7 @@ describe("fetchBalance", () => {
const [url, opts] = fetchMock.mock.calls[0];
expect(url).toBe("/api/payments/balance");
expect(opts.headers["Content-Type"]).toBe("application/json");
expect(opts.headers["x-api-key"]).toBeDefined();
expect(opts.headers["x-api-key"]).toBeUndefined();
expect(result).toEqual(payload);
});

Expand Down
31 changes: 27 additions & 4 deletions console-ui/__tests__/google-analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ declare global {
}
}

function normalizeDataLayer() {
return (window.dataLayer ?? []).map((entry) => {
if (
typeof entry === "object" &&
entry !== null &&
"length" in entry
) {
return Array.from(entry as ArrayLike<unknown>);
}

return entry;
});
}

describe("google analytics helpers", () => {
beforeEach(() => {
vi.restoreAllMocks();
Expand All @@ -33,6 +47,7 @@ describe("google analytics helpers", () => {
window.dataLayer = [];
window.gtag = undefined;
localStorage.removeItem("darkbloom_ga_consent");
document.cookie = "darkbloom_ga_consent=; path=/; max-age=0";
window.history.replaceState({}, "", "/?token=secret&utm_source=search&gclid=abc123");
document.title = "Darkbloom";
});
Expand All @@ -54,6 +69,13 @@ describe("google analytics helpers", () => {
expect(window.__googleAnalyticsInitialized).toBe(false);
});

it("falls back to the shared consent cookie when local storage is unset", () => {
document.cookie = "darkbloom_ga_consent=granted; path=/; max-age=60";

expect(getGoogleAnalyticsConsentStatus()).toBe("granted");
expect(hasGoogleAnalyticsConsent()).toBe(true);
});

it("syncs runtime state when consent changes externally", () => {
grantGoogleAnalyticsConsent();
initializeGoogleAnalytics();
Expand Down Expand Up @@ -126,7 +148,8 @@ describe("google analytics helpers", () => {
initializeGoogleAnalytics();
trackRouteChange("/billing");

expect(window.dataLayer).toEqual([
expect(window.dataLayer?.[0]).not.toBeInstanceOf(Array);
expect(normalizeDataLayer()).toEqual([
["js", expect.any(Date)],
["config", "G-TEST123", { send_page_view: false }],
[
Expand Down Expand Up @@ -158,7 +181,7 @@ describe("google analytics helpers", () => {
trackRouteChange("/billing");
trackRouteChange("/settings");

expect(window.dataLayer).toEqual([
expect(normalizeDataLayer()).toEqual([
["js", expect.any(Date)],
["config", "G-TEST123", { send_page_view: false }],
[
Expand Down Expand Up @@ -204,7 +227,7 @@ describe("google analytics helpers", () => {
source: "login_page",
});

expect(window.dataLayer).toEqual([
expect(normalizeDataLayer()).toEqual([
["js", expect.any(Date)],
["config", "G-TEST123", { send_page_view: false }],
[
Expand Down Expand Up @@ -240,7 +263,7 @@ describe("google analytics helpers", () => {
model: "mlx-community/gemma-4-26b-a4b-it-8bit",
});

expect(window.dataLayer).toEqual([
expect(normalizeDataLayer()).toEqual([
["js", expect.any(Date)],
["config", "G-TEST123", { send_page_view: false }],
[
Expand Down
25 changes: 8 additions & 17 deletions console-ui/__tests__/pages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,7 @@ beforeEach(() => {
});
vi.stubGlobal("fetch", fetchMock);

const store: Record<string, string> = {};
vi.stubGlobal("localStorage", {
getItem: (k: string) => store[k] ?? null,
setItem: (k: string, v: string) => {
store[k] = v;
},
removeItem: (k: string) => {
delete store[k];
},
});
localStorage.clear();
});

afterEach(() => {
Expand All @@ -180,8 +171,9 @@ describe("BillingPage", () => {
// TopBar is mocked and should show "Billing"
expect(screen.getByTestId("topbar")).toHaveTextContent("Billing");

// Research preview banner — purchases disabled, Buy Credits button present
expect(screen.getByText("Available Credits")).toBeInTheDocument();
// Balance card — starts in loading state and exposes Buy Credits action.
expect(screen.getByText("Balance")).toBeInTheDocument();
expect(screen.getByText("Loading...")).toBeInTheDocument();
expect(screen.getByRole("button", { name: /Buy Credits/i })).toBeInTheDocument();

// Invite code section
Expand Down Expand Up @@ -240,17 +232,16 @@ describe("ProvidersPage", () => {
render(<ProvidersPage />);

await screen.findByRole("heading", { name: "Provider Dashboard" });
expect(screen.getByText(/Earnings, device health/)).toBeInTheDocument();
expect(screen.getByText("Your linked provider machines.")).toBeInTheDocument();
});

it("shows provider summary stats", async () => {
const ProvidersPage = (await import("@/app/providers/page")).default;
render(<ProvidersPage />);

await screen.findByText("Devices online");
expect(screen.getByText("Needs attention")).toBeInTheDocument();
expect(screen.getByText("Available earnings")).toBeInTheDocument();
expect(screen.getByText("Lifetime earnings")).toBeInTheDocument();
await screen.findByRole("heading", { name: "Provider Dashboard" });
expect(screen.getByText("We're rebuilding this page")).toBeInTheDocument();
expect(screen.getByText("Earnings page")).toBeInTheDocument();
});

it("shows onboarding actions when no devices are linked", async () => {
Expand Down
28 changes: 28 additions & 0 deletions console-ui/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
import "@testing-library/jest-dom/vitest";

let testStorage: Record<string, string> = {};

const localStorageMock = {
getItem: (key: string) => testStorage[key] ?? null,
setItem: (key: string, value: string) => {
testStorage[key] = String(value);
},
removeItem: (key: string) => {
delete testStorage[key];
},
clear: () => {
testStorage = {};
},
key: (index: number) => Object.keys(testStorage)[index] ?? null,
get length() {
return Object.keys(testStorage).length;
},
} as Storage;

Object.defineProperty(window, "localStorage", {
value: localStorageMock,
configurable: true,
});
Object.defineProperty(globalThis, "localStorage", {
value: localStorageMock,
configurable: true,
});
11 changes: 1 addition & 10 deletions console-ui/__tests__/stripe-payouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@ beforeEach(() => {
fetchMock = vi.fn();
vi.stubGlobal("fetch", fetchMock);

const store: Record<string, string> = {};
vi.stubGlobal("localStorage", {
getItem: (k: string) => store[k] ?? null,
setItem: (k: string, v: string) => {
store[k] = v;
},
removeItem: (k: string) => {
delete store[k];
},
});
localStorage.clear();
});

afterEach(() => {
Expand Down
Loading
Loading