@carlonicora/nextjs-jsonapi 3.24.2 → 3.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AssistantMessageInterface-1Kbz8RVs.d.ts → AssistantMessageInterface-CubxuBIJ.d.ts} +1 -1
- package/dist/{AssistantMessageInterface-CoxJyuFM.d.mts → AssistantMessageInterface-sHjI2zPN.d.mts} +1 -1
- package/dist/{BlockNoteEditor-35D4R7HJ.js → BlockNoteEditor-4EIKMNY3.js} +31 -21
- package/dist/BlockNoteEditor-4EIKMNY3.js.map +1 -0
- package/dist/{BlockNoteEditor-65HR6ULV.mjs → BlockNoteEditor-AXYVDDXM.mjs} +16 -6
- package/dist/{BlockNoteEditor-65HR6ULV.mjs.map → BlockNoteEditor-AXYVDDXM.mjs.map} +1 -1
- package/dist/{BlockNoteViewer-QDXDVYEM.js → BlockNoteViewer-7BFNTN4E.js} +4 -4
- package/dist/{BlockNoteViewer-QDXDVYEM.js.map → BlockNoteViewer-7BFNTN4E.js.map} +1 -1
- package/dist/{BlockNoteViewer-KDKGUIG5.mjs → BlockNoteViewer-KRTAFTUX.mjs} +3 -3
- package/dist/{HandbookSectionInterface-OePKPbqN.d.ts → HandbookSectionInterface-Ck1wZJ81.d.ts} +1 -1
- package/dist/{HandbookSectionInterface-BYsmnPEz.d.mts → HandbookSectionInterface-DgYH--Ik.d.mts} +1 -1
- package/dist/JsonApiRequest-TE5WD3WS.js +26 -0
- package/dist/{JsonApiRequest-G625QAH5.js.map → JsonApiRequest-TE5WD3WS.js.map} +1 -1
- package/dist/{JsonApiRequest-RRMNV7YE.mjs → JsonApiRequest-UHOWNI3O.mjs} +2 -2
- package/dist/analytics.modules-CfczU12P.d.ts +25 -0
- package/dist/analytics.modules-pzGwMASI.d.mts +25 -0
- package/dist/{auth.interface-BC1jp_ni.d.ts → auth.interface-BzI4onI_.d.ts} +1 -1
- package/dist/{auth.interface-dR2-6gPM.d.mts → auth.interface-Df4vXbNz.d.mts} +1 -1
- package/dist/billing/index.js +402 -402
- package/dist/billing/index.mjs +4 -4
- package/dist/{chunk-YXRVPEEJ.js → chunk-26MQIJNB.js} +1 -1
- package/dist/{chunk-YXRVPEEJ.js.map → chunk-26MQIJNB.js.map} +1 -1
- package/dist/{chunk-T76WLDE5.mjs → chunk-37DMFVLN.mjs} +1 -1
- package/dist/{chunk-3AR4KA5D.js → chunk-4Z45NYPR.js} +13 -13
- package/dist/{chunk-3AR4KA5D.js.map → chunk-4Z45NYPR.js.map} +1 -1
- package/dist/chunk-7B4E42R5.mjs +280 -0
- package/dist/chunk-7B4E42R5.mjs.map +1 -0
- package/dist/{chunk-2XCUAHQT.js → chunk-ABVTYQIJ.js} +1563 -1336
- package/dist/chunk-ABVTYQIJ.js.map +1 -0
- package/dist/{chunk-U7QVISQS.js → chunk-CAKOFJZD.js} +450 -40
- package/dist/chunk-CAKOFJZD.js.map +1 -0
- package/dist/{chunk-IBVKPLHT.mjs → chunk-E3I4MT53.mjs} +422 -12
- package/dist/chunk-E3I4MT53.mjs.map +1 -0
- package/dist/chunk-GHFMKH3M.js +280 -0
- package/dist/chunk-GHFMKH3M.js.map +1 -0
- package/dist/chunk-GKDHYB2R.js +110 -0
- package/dist/chunk-GKDHYB2R.js.map +1 -0
- package/dist/{chunk-ZJI5ZZW5.mjs → chunk-Q6J2ICKO.mjs} +3 -3
- package/dist/{chunk-4O7R2Z2O.mjs → chunk-QWZAGQWJ.mjs} +2175 -1948
- package/dist/chunk-QWZAGQWJ.mjs.map +1 -0
- package/dist/chunk-U65JPKO3.mjs +110 -0
- package/dist/chunk-U65JPKO3.mjs.map +1 -0
- package/dist/client/index.d.mts +6 -5
- package/dist/client/index.d.ts +6 -5
- package/dist/client/index.js +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +4 -4
- package/dist/components/index.d.mts +33 -10
- package/dist/components/index.d.ts +33 -10
- package/dist/components/index.js +7 -5
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +6 -4
- package/dist/{config-B6UB7j69.d.ts → config-3N1LSrcC.d.ts} +1 -1
- package/dist/{config-Cd5xTEfZ.d.ts → config-AVtuvfM1.d.ts} +1 -1
- package/dist/{config-n-ZpPmOL.d.mts → config-BSKTYDoh.d.mts} +1 -1
- package/dist/{config-YyhFHxkU.d.mts → config-BmufyEj6.d.mts} +1 -1
- package/dist/contexts/index.d.mts +5 -4
- package/dist/contexts/index.d.ts +5 -4
- package/dist/contexts/index.js +5 -5
- package/dist/contexts/index.mjs +4 -4
- package/dist/core/index.d.mts +31 -14
- package/dist/core/index.d.ts +31 -14
- package/dist/core/index.js +9 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +8 -4
- package/dist/features/analytics/index.css +30 -0
- package/dist/features/analytics/index.css.map +1 -0
- package/dist/features/analytics/index.d.mts +508 -0
- package/dist/features/analytics/index.d.ts +508 -0
- package/dist/features/analytics/index.js +1166 -0
- package/dist/features/analytics/index.js.map +1 -0
- package/dist/features/analytics/index.mjs +1166 -0
- package/dist/features/analytics/index.mjs.map +1 -0
- package/dist/features/analytics/server.d.mts +28 -0
- package/dist/features/analytics/server.d.ts +28 -0
- package/dist/features/analytics/server.js +41 -0
- package/dist/features/analytics/server.js.map +1 -0
- package/dist/features/analytics/server.mjs +41 -0
- package/dist/features/analytics/server.mjs.map +1 -0
- package/dist/features/help/index.d.mts +2 -2
- package/dist/features/help/index.d.ts +2 -2
- package/dist/features/help/index.js +43 -43
- package/dist/features/help/index.js.map +1 -1
- package/dist/features/help/index.mjs +9 -9
- package/dist/features/help/index.mjs.map +1 -1
- package/dist/features/tokenusage/index.d.mts +2 -2
- package/dist/features/tokenusage/index.d.ts +2 -2
- package/dist/features/tokenusage/index.js +141 -223
- package/dist/features/tokenusage/index.js.map +1 -1
- package/dist/features/tokenusage/index.mjs +28 -110
- package/dist/features/tokenusage/index.mjs.map +1 -1
- package/dist/index.d.mts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -5
- package/dist/notification.interface-BNCvnVCW.d.ts +34 -0
- package/dist/notification.interface-P_pNfzZQ.d.mts +34 -0
- package/dist/{s3.service-Bqr-fQmi.d.ts → s3.service-CbUa6a-8.d.ts} +3 -2
- package/dist/{s3.service-Buiy1ncj.d.mts → s3.service-DAp8FbuG.d.mts} +3 -2
- package/dist/server/index.d.mts +5 -4
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +39 -279
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +20 -260
- package/dist/server/index.mjs.map +1 -1
- package/dist/{types-bsm8Fp55.d.ts → types-Cn153-mH.d.ts} +1 -1
- package/dist/{types-Bq_UA8Lg.d.mts → types-D0uLYV2P.d.mts} +1 -1
- package/dist/{usePageUrlGenerator-J_ECv-oQ.d.ts → usePageUrlGenerator-B-3FRKBD.d.ts} +1 -1
- package/dist/{usePageUrlGenerator-uKBjAKqC.d.mts → usePageUrlGenerator-CCJ_cdQy.d.mts} +1 -1
- package/dist/{useSocket-BcH7l7B8.d.mts → useSocket-B9gTbuCj.d.mts} +1 -1
- package/dist/{useSocket-DCZd_eJk.d.ts → useSocket-BHVIyigI.d.ts} +1 -1
- package/dist/{notification.interface-MnRt1Tjm.d.mts → user.interface-CSaGWFbg.d.mts} +1 -31
- package/dist/{notification.interface-CjzV_KII.d.ts → user.interface-CrmwJLYW.d.ts} +1 -31
- package/package.json +11 -1
- package/src/client/index.ts +2 -0
- package/src/components/containers/PageContainer.tsx +1 -1
- package/src/components/containers/RoundPageContainer.tsx +60 -16
- package/src/components/containers/RoundPageContainerTitle.tsx +75 -35
- package/src/components/editors/BlockNoteEditor.tsx +13 -1
- package/src/components/forms/EntityMultiSelector.tsx +4 -4
- package/src/components/forms/EntitySelector.tsx +4 -4
- package/src/components/forms/FormBlockNote.tsx +21 -1
- package/src/components/forms/FormCheckbox.tsx +6 -2
- package/src/components/forms/__tests__/useEditorDialog.test.ts +47 -0
- package/src/components/forms/useEditorDialog.ts +22 -0
- package/src/components/navigations/Breadcrumb.tsx +45 -16
- package/src/components/navigations/Header.tsx +16 -3
- package/src/components/navigations/MobileNavigationBar.tsx +12 -0
- package/src/components/navigations/__tests__/MobileNavigationBar.spec.tsx +17 -0
- package/src/components/tables/ContentListTable.tsx +52 -32
- package/src/core/index.ts +4 -0
- package/src/core/registry/ModuleRegistry.ts +7 -0
- package/src/features/__tests__/i18n-keys.contract.spec.ts +1 -0
- package/src/features/analytics/__tests__/server-entry.spec.tsx +64 -0
- package/src/features/analytics/analytics.modules.ts +30 -0
- package/src/features/analytics/components/AnalyticsAdminContainer.tsx +97 -0
- package/src/features/analytics/components/AnalyticsAdminFilterBar.tsx +120 -0
- package/src/features/analytics/components/AnalyticsAdminPageContainer.tsx +25 -0
- package/src/features/analytics/components/AnalyticsAdminTiles.tsx +191 -0
- package/src/features/analytics/components/AnalyticsBreakdownTable.tsx +105 -0
- package/src/features/analytics/components/AnalyticsJourneyContainer.tsx +246 -0
- package/src/features/analytics/components/AnalyticsJourneyPageContainer.tsx +14 -0
- package/src/features/analytics/components/AnalyticsSessionsTable.tsx +107 -0
- package/src/features/analytics/components/AnalyticsTimelineChart.tsx +175 -0
- package/src/features/analytics/components/AnalyticsTracker.tsx +112 -0
- package/src/features/analytics/components/__tests__/AnalyticsAdminTiles.spec.tsx +39 -0
- package/src/features/analytics/components/__tests__/AnalyticsBreakdownTable.spec.tsx +39 -0
- package/src/features/analytics/components/__tests__/AnalyticsJourneyContainer.spec.tsx +124 -0
- package/src/features/analytics/components/__tests__/AnalyticsPageContainers.spec.tsx +117 -0
- package/src/features/analytics/components/__tests__/AnalyticsSessionsTable.spec.tsx +121 -0
- package/src/features/analytics/components/__tests__/AnalyticsTimelineChart.spec.tsx +35 -0
- package/src/features/analytics/components/__tests__/AnalyticsTracker.spec.tsx +248 -0
- package/src/features/analytics/components/server/AnalyticsAdminPage.tsx +28 -0
- package/src/features/analytics/components/server/AnalyticsJourneyPage.tsx +25 -0
- package/src/features/analytics/contexts/AnalyticsAdminContext.tsx +273 -0
- package/src/features/analytics/contexts/__tests__/AnalyticsAdminContext.spec.tsx +140 -0
- package/src/features/analytics/data/AnalyticsAdminService.ts +91 -0
- package/src/features/analytics/data/AnalyticsService.ts +23 -0
- package/src/features/analytics/data/__tests__/AnalyticsAdminService.spec.ts +117 -0
- package/src/features/analytics/data/__tests__/AnalyticsService.spec.ts +56 -0
- package/src/features/analytics/data/__tests__/models.spec.ts +300 -0
- package/src/features/analytics/data/analytics-breakdown.interface.ts +9 -0
- package/src/features/analytics/data/analytics-breakdown.ts +65 -0
- package/src/features/analytics/data/analytics-event.interface.ts +7 -0
- package/src/features/analytics/data/analytics-event.ts +63 -0
- package/src/features/analytics/data/analytics-page-view.interface.ts +9 -0
- package/src/features/analytics/data/analytics-page-view.ts +57 -0
- package/src/features/analytics/data/analytics-session.interface.ts +23 -0
- package/src/features/analytics/data/analytics-session.ts +144 -0
- package/src/features/analytics/data/analytics-summary.interface.ts +11 -0
- package/src/features/analytics/data/analytics-summary.ts +79 -0
- package/src/features/analytics/data/analytics-timeline.interface.ts +10 -0
- package/src/features/analytics/data/analytics-timeline.ts +67 -0
- package/src/features/analytics/data/analytics.types.ts +97 -0
- package/src/features/analytics/data/index.ts +15 -0
- package/src/features/analytics/i18n-keys.ts +76 -0
- package/src/features/analytics/index.ts +31 -0
- package/src/features/analytics/lib/__tests__/utm.spec.ts +20 -0
- package/src/features/analytics/lib/__tests__/visitorCookie.spec.ts +63 -0
- package/src/features/analytics/lib/utm.ts +29 -0
- package/src/features/analytics/lib/visitorCookie.ts +32 -0
- package/src/features/analytics/server-entry.ts +8 -0
- package/src/features/assistant/components/parts/AssistantBlockNoteComposer.tsx +1 -1
- package/src/features/assistant/components/parts/AssistantComposer.tsx +1 -1
- package/src/features/assistant-message/components/MessageItem.tsx +2 -2
- package/src/features/assistant-message/components/parts/tabs/CitationsTab.tsx +23 -5
- package/src/features/auth/components/containers/AuthContainer.tsx +8 -1
- package/src/features/company/components/details/CompanyContent.tsx +3 -1
- package/src/features/company/components/details/CompanyDetails.tsx +9 -1
- package/src/features/company/components/details/TokenStatusIndicator.tsx +42 -13
- package/src/features/help/components/HelpHeader.tsx +7 -5
- package/src/features/tokenusage/components/TokenUsageAdminFilterBar.tsx +9 -6
- package/src/features/tokenusage/lib/__tests__/formatters.spec.ts +21 -0
- package/src/features/tokenusage/lib/formatters.ts +5 -1
- package/src/features/waitlist/components/lists/WaitlistList.tsx +68 -121
- package/src/features/waitlist/data/WaitlistService.ts +2 -2
- package/src/features/waitlist/data/index.ts +1 -0
- package/src/features/waitlist/data/waitlist.fields.ts +8 -0
- package/src/features/waitlist/hooks/useWaitlistTableStructure.tsx +69 -30
- package/src/shadcnui/ui/button.tsx +1 -1
- package/src/shadcnui/ui/checkbox.tsx +1 -1
- package/src/shadcnui/ui/command.tsx +4 -4
- package/src/shadcnui/ui/dialog.tsx +2 -0
- package/src/shadcnui/ui/input.tsx +1 -1
- package/src/shadcnui/ui/popover.tsx +9 -0
- package/src/shadcnui/ui/select.tsx +1 -1
- package/src/shadcnui/ui/sheet.tsx +8 -1
- package/src/shadcnui/ui/table.tsx +2 -2
- package/src/shadcnui/ui/textarea.tsx +1 -1
- package/dist/BlockNoteEditor-35D4R7HJ.js.map +0 -1
- package/dist/JsonApiRequest-G625QAH5.js +0 -26
- package/dist/chunk-2XCUAHQT.js.map +0 -1
- package/dist/chunk-4O7R2Z2O.mjs.map +0 -1
- package/dist/chunk-IBVKPLHT.mjs.map +0 -1
- package/dist/chunk-U7QVISQS.js.map +0 -1
- /package/dist/{BlockNoteViewer-KDKGUIG5.mjs.map → BlockNoteViewer-KRTAFTUX.mjs.map} +0 -0
- /package/dist/{JsonApiRequest-RRMNV7YE.mjs.map → JsonApiRequest-UHOWNI3O.mjs.map} +0 -0
- /package/dist/{chunk-T76WLDE5.mjs.map → chunk-37DMFVLN.mjs.map} +0 -0
- /package/dist/{chunk-ZJI5ZZW5.mjs.map → chunk-Q6J2ICKO.mjs.map} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { AnalyticsAdminTiles } from "../AnalyticsAdminTiles";
|
|
4
|
+
|
|
5
|
+
const row = (section: string, window: string, values: Partial<Record<string, number>>) =>
|
|
6
|
+
({
|
|
7
|
+
id: `${section}|${window}`,
|
|
8
|
+
section,
|
|
9
|
+
window,
|
|
10
|
+
visitors: 0,
|
|
11
|
+
sessions: 0,
|
|
12
|
+
pageViews: 0,
|
|
13
|
+
pagesPerSession: 0,
|
|
14
|
+
consentShare: 0,
|
|
15
|
+
...values,
|
|
16
|
+
}) as any;
|
|
17
|
+
|
|
18
|
+
const summary = [
|
|
19
|
+
row("total", "current", { visitors: 120, sessions: 150, pageViews: 600, pagesPerSession: 4, consentShare: 0.25 }),
|
|
20
|
+
row("total", "previous", { visitors: 100 }),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
describe("AnalyticsAdminTiles", () => {
|
|
24
|
+
it("shows the current totals with the delta against the previous window", () => {
|
|
25
|
+
render(<AnalyticsAdminTiles summary={summary} />);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByTestId("analytics-tile-visitors")).toHaveTextContent("120");
|
|
28
|
+
expect(screen.getByTestId("analytics-tile-visitors-delta")).toHaveTextContent("+20%");
|
|
29
|
+
expect(screen.getByTestId("analytics-tile-consent-share")).toHaveTextContent("25%");
|
|
30
|
+
expect(screen.getByTestId("analytics-tile-pages-per-session")).toHaveTextContent("4.0");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("suppresses the delta rather than showing Infinity when the previous window is zero", () => {
|
|
34
|
+
render(<AnalyticsAdminTiles summary={summary} />);
|
|
35
|
+
|
|
36
|
+
// sessions previous is 0
|
|
37
|
+
expect(screen.getByTestId("analytics-tile-sessions-delta")).toHaveTextContent("—");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { AnalyticsBreakdownTable } from "../AnalyticsBreakdownTable";
|
|
4
|
+
|
|
5
|
+
const row = (dimension: string, key: string, visitors: number) =>
|
|
6
|
+
({ id: `${dimension}|${key}`, dimension, key, visitors, sessions: visitors, pageViews: visitors * 2 }) as any;
|
|
7
|
+
|
|
8
|
+
const breakdowns = {
|
|
9
|
+
source: [row("source", "(none)", 5), row("source", "linkedin", 30), row("source", "google", 12)],
|
|
10
|
+
medium: [],
|
|
11
|
+
campaign: [],
|
|
12
|
+
referrer: [],
|
|
13
|
+
route: [row("route", "/rolls/:id", 9)],
|
|
14
|
+
landing: [],
|
|
15
|
+
} as any;
|
|
16
|
+
|
|
17
|
+
describe("AnalyticsBreakdownTable", () => {
|
|
18
|
+
it("renders one tab per dimension", () => {
|
|
19
|
+
render(<AnalyticsBreakdownTable breakdowns={breakdowns} />);
|
|
20
|
+
|
|
21
|
+
expect(screen.getAllByRole("tab")).toHaveLength(6);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("sorts rows by visitors descending and renders the (none) key as-is", () => {
|
|
25
|
+
render(<AnalyticsBreakdownTable breakdowns={breakdowns} />);
|
|
26
|
+
|
|
27
|
+
const rows = screen.getAllByTestId(/^analytics-breakdown-row-/);
|
|
28
|
+
expect(rows.map((r) => within(r).getAllByRole("cell")[0].textContent)).toEqual(["linkedin", "google", "(none)"]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("shows the selected dimension's rows when its tab is clicked", () => {
|
|
32
|
+
render(<AnalyticsBreakdownTable breakdowns={breakdowns} />);
|
|
33
|
+
|
|
34
|
+
fireEvent.click(screen.getByRole("tab", { name: "analytics.admin.dimensions.route" }));
|
|
35
|
+
|
|
36
|
+
expect(screen.getByText("/rolls/:id")).toBeInTheDocument();
|
|
37
|
+
expect(screen.queryByText("linkedin")).not.toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { render, screen, waitFor, within } from "@testing-library/react";
|
|
2
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { configureI18n } from "../../../../i18n";
|
|
4
|
+
import { AnalyticsAdminService } from "../../data/AnalyticsAdminService";
|
|
5
|
+
import { AnalyticsJourneyContainer } from "../AnalyticsJourneyContainer";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../data/AnalyticsAdminService", () => ({
|
|
8
|
+
AnalyticsAdminService: {
|
|
9
|
+
getSession: vi.fn(),
|
|
10
|
+
getSessionPageViews: vi.fn(),
|
|
11
|
+
getSessions: vi.fn(),
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
// The real page chrome needs the whole app shell (header, sidebar, navigation
|
|
16
|
+
// contexts); the journey's own content is what is under test here.
|
|
17
|
+
vi.mock("../../../../components", async (importOriginal) => {
|
|
18
|
+
const actual = await importOriginal<typeof import("../../../../components")>();
|
|
19
|
+
return {
|
|
20
|
+
...actual,
|
|
21
|
+
RoundPageContainer: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
beforeAll(() => {
|
|
26
|
+
configureI18n({
|
|
27
|
+
useRouter: () => ({
|
|
28
|
+
push: vi.fn(),
|
|
29
|
+
replace: vi.fn(),
|
|
30
|
+
back: vi.fn(),
|
|
31
|
+
forward: vi.fn(),
|
|
32
|
+
refresh: vi.fn(),
|
|
33
|
+
prefetch: vi.fn(),
|
|
34
|
+
}),
|
|
35
|
+
useTranslations: () => (key: string) => key,
|
|
36
|
+
usePathname: () => "/",
|
|
37
|
+
Link: ({
|
|
38
|
+
href,
|
|
39
|
+
children,
|
|
40
|
+
prefetch: _prefetch,
|
|
41
|
+
...rest
|
|
42
|
+
}: {
|
|
43
|
+
href: string;
|
|
44
|
+
children: React.ReactNode;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}) => (
|
|
47
|
+
<a href={href} {...rest}>
|
|
48
|
+
{children}
|
|
49
|
+
</a>
|
|
50
|
+
),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const session = (id: string, startedAt: string) =>
|
|
55
|
+
({
|
|
56
|
+
id,
|
|
57
|
+
visitorId: "visitor-0000-0000-abc123",
|
|
58
|
+
consented: true,
|
|
59
|
+
startedAt: new Date(startedAt),
|
|
60
|
+
lastSeenAt: new Date(startedAt),
|
|
61
|
+
pageViews: 3,
|
|
62
|
+
section: "public",
|
|
63
|
+
landingRoute: "/pricing",
|
|
64
|
+
referrerHost: "linkedin.com",
|
|
65
|
+
utmSource: "linkedin",
|
|
66
|
+
utmMedium: "social",
|
|
67
|
+
utmCampaign: "launch",
|
|
68
|
+
deviceType: "desktop",
|
|
69
|
+
}) as any;
|
|
70
|
+
|
|
71
|
+
const pageView = (id: string, createdAt: string, path: string) =>
|
|
72
|
+
({ id, createdAt: new Date(createdAt), path, route: path, section: "public" }) as any;
|
|
73
|
+
|
|
74
|
+
describe("AnalyticsJourneyContainer", () => {
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
vi.clearAllMocks();
|
|
77
|
+
vi.mocked(AnalyticsAdminService.getSession).mockResolvedValue(session("s1", "2026-10-01T10:00:00.000Z"));
|
|
78
|
+
vi.mocked(AnalyticsAdminService.getSessionPageViews).mockResolvedValue([
|
|
79
|
+
pageView("p1", "2026-10-01T10:00:00.000Z", "/pricing"),
|
|
80
|
+
pageView("p2", "2026-10-01T10:02:00.000Z", "/features"),
|
|
81
|
+
pageView("p3", "2026-10-01T10:02:30.000Z", "/register"),
|
|
82
|
+
]);
|
|
83
|
+
vi.mocked(AnalyticsAdminService.getSessions).mockResolvedValue([
|
|
84
|
+
session("s1", "2026-10-01T10:00:00.000Z"),
|
|
85
|
+
session("s9", "2026-09-20T08:00:00.000Z"),
|
|
86
|
+
]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("renders the page views in order with the gap to the previous one", async () => {
|
|
90
|
+
render(<AnalyticsJourneyContainer sessionId="s1" />);
|
|
91
|
+
|
|
92
|
+
const rows = await screen.findAllByTestId(/^analytics-pageview-row-/);
|
|
93
|
+
expect(rows.map((row) => within(row).getAllByRole("cell")[2].textContent)).toEqual([
|
|
94
|
+
"/pricing",
|
|
95
|
+
"/features",
|
|
96
|
+
"/register",
|
|
97
|
+
]);
|
|
98
|
+
expect(within(rows[1]).getByText("2 min")).toBeInTheDocument();
|
|
99
|
+
expect(AnalyticsAdminService.getSessionPageViews).toHaveBeenCalledWith({ sessionId: "s1" });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("renders the attribution header", async () => {
|
|
103
|
+
render(<AnalyticsJourneyContainer sessionId="s1" />);
|
|
104
|
+
|
|
105
|
+
const header = await screen.findByTestId("analytics-journey-attribution");
|
|
106
|
+
expect(header).toHaveTextContent("linkedin");
|
|
107
|
+
expect(header).toHaveTextContent("analytics.admin.consented");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("lists the visitor's other sessions, excluding the current one", async () => {
|
|
111
|
+
render(<AnalyticsJourneyContainer sessionId="s1" />);
|
|
112
|
+
|
|
113
|
+
await waitFor(() =>
|
|
114
|
+
expect(AnalyticsAdminService.getSessions).toHaveBeenCalledWith(
|
|
115
|
+
expect.objectContaining({ visitorId: "visitor-0000-0000-abc123", section: "all" }),
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
expect(await screen.findByTestId("analytics-session-link-s9")).toHaveAttribute(
|
|
119
|
+
"href",
|
|
120
|
+
"/administration/analytics/sessions/s9",
|
|
121
|
+
);
|
|
122
|
+
expect(screen.queryByTestId("analytics-session-link-s1")).not.toBeInTheDocument();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { configureI18n } from "../../../../i18n";
|
|
4
|
+
import { AnalyticsAdminService } from "../../data/AnalyticsAdminService";
|
|
5
|
+
import { AnalyticsAdminPageContainer } from "../AnalyticsAdminPageContainer";
|
|
6
|
+
import { AnalyticsJourneyPageContainer } from "../AnalyticsJourneyPageContainer";
|
|
7
|
+
|
|
8
|
+
vi.mock("../../data/AnalyticsAdminService", () => ({
|
|
9
|
+
AnalyticsAdminService: {
|
|
10
|
+
getSummary: vi.fn(),
|
|
11
|
+
getTimeline: vi.fn(),
|
|
12
|
+
getBreakdown: vi.fn(),
|
|
13
|
+
getSessions: vi.fn(),
|
|
14
|
+
getSession: vi.fn(),
|
|
15
|
+
getSessionPageViews: vi.fn(),
|
|
16
|
+
next: vi.fn(),
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
// The real page chrome needs the whole app shell (header, sidebar, navigation
|
|
21
|
+
// contexts); the page content is what is under test here.
|
|
22
|
+
vi.mock("../../../../components", async (importOriginal) => {
|
|
23
|
+
const actual = await importOriginal<typeof import("../../../../components")>();
|
|
24
|
+
return {
|
|
25
|
+
...actual,
|
|
26
|
+
RoundPageContainer: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
beforeAll(() => {
|
|
31
|
+
configureI18n({
|
|
32
|
+
useRouter: () => ({
|
|
33
|
+
push: vi.fn(),
|
|
34
|
+
replace: vi.fn(),
|
|
35
|
+
back: vi.fn(),
|
|
36
|
+
forward: vi.fn(),
|
|
37
|
+
refresh: vi.fn(),
|
|
38
|
+
prefetch: vi.fn(),
|
|
39
|
+
}),
|
|
40
|
+
useTranslations: () => (key: string) => key,
|
|
41
|
+
usePathname: () => "/",
|
|
42
|
+
Link: ({
|
|
43
|
+
href,
|
|
44
|
+
children,
|
|
45
|
+
prefetch: _prefetch,
|
|
46
|
+
...rest
|
|
47
|
+
}: {
|
|
48
|
+
href: string;
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}) => (
|
|
52
|
+
<a href={href} {...rest}>
|
|
53
|
+
{children}
|
|
54
|
+
</a>
|
|
55
|
+
),
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const session = (id: string, startedAt: string) =>
|
|
60
|
+
({
|
|
61
|
+
id,
|
|
62
|
+
visitorId: "visitor-0000-0000-abc123",
|
|
63
|
+
consented: true,
|
|
64
|
+
startedAt: new Date(startedAt),
|
|
65
|
+
lastSeenAt: new Date(startedAt),
|
|
66
|
+
pageViews: 3,
|
|
67
|
+
section: "public",
|
|
68
|
+
landingRoute: "/pricing",
|
|
69
|
+
referrerHost: "linkedin.com",
|
|
70
|
+
utmSource: "linkedin",
|
|
71
|
+
deviceType: "desktop",
|
|
72
|
+
}) as any;
|
|
73
|
+
|
|
74
|
+
describe("AnalyticsAdminPageContainer", () => {
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
vi.clearAllMocks();
|
|
77
|
+
vi.mocked(AnalyticsAdminService.getSummary).mockResolvedValue([]);
|
|
78
|
+
vi.mocked(AnalyticsAdminService.getTimeline).mockResolvedValue([]);
|
|
79
|
+
vi.mocked(AnalyticsAdminService.getBreakdown).mockResolvedValue([]);
|
|
80
|
+
vi.mocked(AnalyticsAdminService.getSessions).mockResolvedValue([session("s1", "2026-10-01T10:00:00.000Z")]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("loads the dashboard and links each session under the given sessionPageUrl", async () => {
|
|
84
|
+
render(<AnalyticsAdminPageContainer pageUrl="/admin/stats" sessionPageUrl="/admin/stats/sessions" />);
|
|
85
|
+
|
|
86
|
+
expect(await screen.findByTestId("analytics-session-link-s1")).toHaveAttribute("href", "/admin/stats/sessions/s1");
|
|
87
|
+
expect(AnalyticsAdminService.getSummary).toHaveBeenCalledTimes(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("falls back to the provider's default routes", async () => {
|
|
91
|
+
render(<AnalyticsAdminPageContainer />);
|
|
92
|
+
|
|
93
|
+
expect(await screen.findByTestId("analytics-session-link-s1")).toHaveAttribute(
|
|
94
|
+
"href",
|
|
95
|
+
"/administration/analytics/sessions/s1",
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("AnalyticsJourneyPageContainer", () => {
|
|
101
|
+
beforeEach(() => {
|
|
102
|
+
vi.clearAllMocks();
|
|
103
|
+
vi.mocked(AnalyticsAdminService.getSession).mockResolvedValue(session("s1", "2026-10-01T10:00:00.000Z"));
|
|
104
|
+
vi.mocked(AnalyticsAdminService.getSessionPageViews).mockResolvedValue([]);
|
|
105
|
+
vi.mocked(AnalyticsAdminService.getSessions).mockResolvedValue([
|
|
106
|
+
session("s1", "2026-10-01T10:00:00.000Z"),
|
|
107
|
+
session("s9", "2026-09-20T08:00:00.000Z"),
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("loads the given session and links the other sessions under pageUrl", async () => {
|
|
112
|
+
render(<AnalyticsJourneyPageContainer sessionId="s1" pageUrl="/admin/stats" />);
|
|
113
|
+
|
|
114
|
+
await waitFor(() => expect(AnalyticsAdminService.getSession).toHaveBeenCalledWith({ id: "s1" }));
|
|
115
|
+
expect(await screen.findByTestId("analytics-session-link-s9")).toHaveAttribute("href", "/admin/stats/sessions/s9");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { configureI18n } from "../../../../i18n";
|
|
4
|
+
import { AnalyticsSessionsTable } from "../AnalyticsSessionsTable";
|
|
5
|
+
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
// The package Link resolves its inner component at runtime and throws if i18n
|
|
8
|
+
// was never configured (src/i18n/config.ts).
|
|
9
|
+
configureI18n({
|
|
10
|
+
useRouter: () => ({
|
|
11
|
+
push: vi.fn(),
|
|
12
|
+
replace: vi.fn(),
|
|
13
|
+
back: vi.fn(),
|
|
14
|
+
forward: vi.fn(),
|
|
15
|
+
refresh: vi.fn(),
|
|
16
|
+
prefetch: vi.fn(),
|
|
17
|
+
}),
|
|
18
|
+
useTranslations: () => (key: string) => key,
|
|
19
|
+
usePathname: () => "/",
|
|
20
|
+
Link: ({
|
|
21
|
+
href,
|
|
22
|
+
children,
|
|
23
|
+
prefetch: _prefetch,
|
|
24
|
+
...rest
|
|
25
|
+
}: {
|
|
26
|
+
href: string;
|
|
27
|
+
children: React.ReactNode;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}) => (
|
|
30
|
+
<a href={href} {...rest}>
|
|
31
|
+
{children}
|
|
32
|
+
</a>
|
|
33
|
+
),
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const session = (id: string, extra: Record<string, unknown> = {}) =>
|
|
38
|
+
({
|
|
39
|
+
id,
|
|
40
|
+
visitorId: `visitor-0000-${id}-abc123`,
|
|
41
|
+
consented: false,
|
|
42
|
+
startedAt: new Date("2026-10-01T10:00:00.000Z"),
|
|
43
|
+
lastSeenAt: new Date("2026-10-01T10:05:00.000Z"),
|
|
44
|
+
pageViews: 3,
|
|
45
|
+
section: "public",
|
|
46
|
+
landingRoute: "/pricing",
|
|
47
|
+
utmSource: "linkedin",
|
|
48
|
+
utmMedium: "social",
|
|
49
|
+
deviceType: "desktop",
|
|
50
|
+
...extra,
|
|
51
|
+
}) as any;
|
|
52
|
+
|
|
53
|
+
const SESSION_PAGE_URL = "/administration/analytics/sessions";
|
|
54
|
+
|
|
55
|
+
describe("AnalyticsSessionsTable", () => {
|
|
56
|
+
it("renders the linked user's name and email", () => {
|
|
57
|
+
render(
|
|
58
|
+
<AnalyticsSessionsTable
|
|
59
|
+
rows={[session("s1", { user: { id: "u1", name: "Ada Lovelace", email: "ada@example.com" } })]}
|
|
60
|
+
sessionPageUrl={SESSION_PAGE_URL}
|
|
61
|
+
onLoadMore={vi.fn()}
|
|
62
|
+
hasMore={false}
|
|
63
|
+
/>,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(screen.getByText("Ada Lovelace")).toBeInTheDocument();
|
|
67
|
+
expect(screen.getByText("ada@example.com")).toBeInTheDocument();
|
|
68
|
+
expect(screen.queryByText("analytics.admin.anonymous")).not.toBeInTheDocument();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("renders an anonymous visitor with the last six characters of the visitor id", () => {
|
|
72
|
+
render(
|
|
73
|
+
<AnalyticsSessionsTable
|
|
74
|
+
rows={[session("s2")]}
|
|
75
|
+
sessionPageUrl={SESSION_PAGE_URL}
|
|
76
|
+
onLoadMore={vi.fn()}
|
|
77
|
+
hasMore={false}
|
|
78
|
+
/>,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(screen.getByText("analytics.admin.anonymous")).toBeInTheDocument();
|
|
82
|
+
expect(screen.getByText("abc123")).toBeInTheDocument();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("links each row to its journey page", () => {
|
|
86
|
+
render(
|
|
87
|
+
<AnalyticsSessionsTable
|
|
88
|
+
rows={[session("s3")]}
|
|
89
|
+
sessionPageUrl={SESSION_PAGE_URL}
|
|
90
|
+
onLoadMore={vi.fn()}
|
|
91
|
+
hasMore={false}
|
|
92
|
+
/>,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(screen.getByTestId("analytics-session-link-s3")).toHaveAttribute("href", `${SESSION_PAGE_URL}/s3`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("shows the load-more button only when more sessions exist", () => {
|
|
99
|
+
const onLoadMore = vi.fn();
|
|
100
|
+
const { rerender } = render(
|
|
101
|
+
<AnalyticsSessionsTable
|
|
102
|
+
rows={[session("s4")]}
|
|
103
|
+
sessionPageUrl={SESSION_PAGE_URL}
|
|
104
|
+
onLoadMore={onLoadMore}
|
|
105
|
+
hasMore={false}
|
|
106
|
+
/>,
|
|
107
|
+
);
|
|
108
|
+
expect(screen.queryByText("analytics.admin.load_more")).not.toBeInTheDocument();
|
|
109
|
+
|
|
110
|
+
rerender(
|
|
111
|
+
<AnalyticsSessionsTable
|
|
112
|
+
rows={[session("s4")]}
|
|
113
|
+
sessionPageUrl={SESSION_PAGE_URL}
|
|
114
|
+
onLoadMore={onLoadMore}
|
|
115
|
+
hasMore
|
|
116
|
+
/>,
|
|
117
|
+
);
|
|
118
|
+
fireEvent.click(screen.getByText("analytics.admin.load_more"));
|
|
119
|
+
expect(onLoadMore).toHaveBeenCalledTimes(1);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { AnalyticsTimelineChart } from "../AnalyticsTimelineChart";
|
|
4
|
+
|
|
5
|
+
const row = (bucket: string, section: string, visitors: number, pageViews: number) =>
|
|
6
|
+
({
|
|
7
|
+
id: `${bucket}|${section}`,
|
|
8
|
+
bucket: new Date(bucket),
|
|
9
|
+
section,
|
|
10
|
+
visitors,
|
|
11
|
+
sessions: visitors,
|
|
12
|
+
pageViews,
|
|
13
|
+
}) as any;
|
|
14
|
+
|
|
15
|
+
describe("AnalyticsTimelineChart", () => {
|
|
16
|
+
it("pivots flat rows into one entry per bucket with visitors and pageViews", () => {
|
|
17
|
+
render(
|
|
18
|
+
<AnalyticsTimelineChart
|
|
19
|
+
rows={[row("2026-10-01", "public", 3, 10), row("2026-10-01", "app", 2, 5), row("2026-10-02", "public", 4, 8)]}
|
|
20
|
+
/>,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const data = JSON.parse(screen.getByTestId("analytics-timeline-data").textContent!);
|
|
24
|
+
expect(data).toHaveLength(2);
|
|
25
|
+
expect(data[0]).toMatchObject({ bucket: "2026-10-01", visitors: 5, pageViews: 15 });
|
|
26
|
+
expect(data[1]).toMatchObject({ bucket: "2026-10-02", visitors: 4, pageViews: 8 });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("renders the empty state without a data node when there are no rows", () => {
|
|
30
|
+
render(<AnalyticsTimelineChart rows={[]} />);
|
|
31
|
+
|
|
32
|
+
expect(screen.queryByTestId("analytics-timeline-data")).not.toBeInTheDocument();
|
|
33
|
+
expect(screen.getByText("analytics.admin.no_data")).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
});
|