@wopr-network/platform-ui-core 1.27.7 → 1.27.9
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/next.config.ts +1 -2
- package/package.json +17 -17
- package/src/__tests__/account-switcher.test.tsx +21 -20
- package/src/__tests__/activity-page.test.tsx +2 -6
- package/src/__tests__/add-payment-method-dialog.test.tsx +9 -32
- package/src/__tests__/admin-api.test.ts +1 -6
- package/src/__tests__/admin-gpu-api.test.ts +1 -3
- package/src/__tests__/admin-marketplace-api.test.ts +1 -4
- package/src/__tests__/admin-middleware.test.ts +76 -83
- package/src/__tests__/affiliate-dashboard.test.tsx +3 -3
- package/src/__tests__/api-401-redirect.test.ts +46 -9
- package/src/__tests__/api-client.test.ts +3 -5
- package/src/__tests__/api-config.test.ts +22 -42
- package/src/__tests__/api-fleet-resources.test.ts +1 -2
- package/src/__tests__/api-fleet-trpc.test.ts +2 -8
- package/src/__tests__/api-null-guards.test.ts +3 -1
- package/src/__tests__/audit-log-table-pagination.test.tsx +2 -6
- package/src/__tests__/auth-password-reset.test.tsx +7 -21
- package/src/__tests__/auth-redirect.test.tsx +8 -2
- package/src/__tests__/auth.test.tsx +25 -23
- package/src/__tests__/auto-topup-card.test.tsx +4 -12
- package/src/__tests__/backups-tab.test.tsx +3 -4
- package/src/__tests__/billing-layout-nav-hidden.test.tsx +5 -37
- package/src/__tests__/billing-payment-org-invoices.test.tsx +2 -18
- package/src/__tests__/billing.test.tsx +8 -39
- package/src/__tests__/bot-settings/resources-tab.test.tsx +1 -3
- package/src/__tests__/bot-settings/storage-tab.test.tsx +1 -3
- package/src/__tests__/bot-settings/vps-upgrade-card.test.tsx +1 -3
- package/src/__tests__/bot-settings-restart.test.tsx +1 -3
- package/src/__tests__/bot-settings.test.tsx +2 -6
- package/src/__tests__/brand.test.ts +6 -26
- package/src/__tests__/buy-credits-panel.test.tsx +1 -3
- package/src/__tests__/buy-crypto-credits-panel.test.tsx +101 -119
- package/src/__tests__/capability-conflicts.test.ts +2 -8
- package/src/__tests__/capability-resolver.test.tsx +2 -12
- package/src/__tests__/channel-wizard.test.tsx +4 -17
- package/src/__tests__/chat/chat-panel.test.tsx +1 -4
- package/src/__tests__/chat-store.test.ts +5 -15
- package/src/__tests__/command-center.test.tsx +10 -12
- package/src/__tests__/compliance-retention-edit.test.tsx +3 -6
- package/src/__tests__/confirmation-tracker.test.tsx +3 -18
- package/src/__tests__/coupon-input.test.tsx +1 -3
- package/src/__tests__/create-instance.test.tsx +1 -3
- package/src/__tests__/credit-balance.test.tsx +4 -12
- package/src/__tests__/credits.test.tsx +32 -85
- package/src/__tests__/email-verification-banner.test.tsx +2 -6
- package/src/__tests__/error-boundaries.test.tsx +0 -1
- package/src/__tests__/fetch-pricing.test.ts +2 -1
- package/src/__tests__/field-oauth.test.tsx +2 -6
- package/src/__tests__/fixtures/mock-manifests-data.js +1 -3
- package/src/__tests__/fixtures/mock-manifests.ts +2 -4
- package/src/__tests__/fleet-health-timestamp.test.tsx +1 -8
- package/src/__tests__/fleet-health-update.test.tsx +1 -8
- package/src/__tests__/gpu-dashboard.test.tsx +2 -6
- package/src/__tests__/instance-detail.test.tsx +3 -9
- package/src/__tests__/instance-list.test.tsx +1 -5
- package/src/__tests__/layout-snapshots.test.tsx +64 -11
- package/src/__tests__/marketplace-admin.test.tsx +2 -6
- package/src/__tests__/marketplace.test.tsx +11 -35
- package/src/__tests__/merge-api-rates.test.ts +1 -6
- package/src/__tests__/middleware.test.ts +32 -219
- package/src/__tests__/next-config-headers.test.ts +1 -3
- package/src/__tests__/notifications.test.tsx +4 -11
- package/src/__tests__/oauth-buttons.test.tsx +36 -59
- package/src/__tests__/oauth-error-mapping.test.tsx +2 -6
- package/src/__tests__/observability.test.tsx +23 -36
- package/src/__tests__/onboarding-page.test.tsx +4 -6
- package/src/__tests__/org-billing-api.test.tsx +1 -6
- package/src/__tests__/plugin-install-flow.test.tsx +28 -58
- package/src/__tests__/plugin-registry.test.tsx +3 -11
- package/src/__tests__/plugin-tool-sync.test.ts +1 -3
- package/src/__tests__/plugins-catalog-error.test.tsx +2 -6
- package/src/__tests__/plugins-toggle-race.test.tsx +3 -5
- package/src/__tests__/portfolio-chart.test.tsx +2 -6
- package/src/__tests__/promotion-form.test.tsx +2 -6
- package/src/__tests__/promotions-list.test.tsx +1 -3
- package/src/__tests__/provider-key-api.test.ts +2 -1
- package/src/__tests__/resend-verification-button.test.tsx +8 -24
- package/src/__tests__/secrets-audit-pagination.test.tsx +1 -3
- package/src/__tests__/settings.test.tsx +11 -21
- package/src/__tests__/setup-checklist.test.tsx +3 -9
- package/src/__tests__/setup.ts +25 -6
- package/src/__tests__/snapshot-api.test.ts +2 -1
- package/src/__tests__/step-superpowers.test.tsx +1 -3
- package/src/__tests__/tenant-context.test.tsx +1 -6
- package/src/__tests__/tenant-keys-api.test.ts +3 -4
- package/src/__tests__/tenant-table-pagination.test.tsx +2 -6
- package/src/__tests__/terminal-log-cleanup.test.tsx +0 -1
- package/src/__tests__/transaction-history.test.tsx +190 -238
- package/src/__tests__/trpc-types.test.ts +2 -6
- package/src/__tests__/use-chat.test.ts +1 -3
- package/src/__tests__/use-plugin-setup-chat-stale-closure.test.ts +1 -4
- package/src/__tests__/use-sidecar-bridge.test.tsx +105 -0
- package/src/__tests__/use-webmcp.test.ts +1 -3
- package/src/__tests__/validate-elevenlabs-key.test.ts +2 -1
- package/src/__tests__/verify-page.test.tsx +4 -13
- package/src/__tests__/verify-redirect.test.tsx +2 -6
- package/src/app/(auth)/error.tsx +1 -7
- package/src/app/(auth)/forgot-password/page.tsx +4 -18
- package/src/app/(auth)/login/page.tsx +5 -22
- package/src/app/(auth)/reset-password/page.tsx +2 -12
- package/src/app/(auth)/signup/page.tsx +10 -44
- package/src/app/(auth)/verify/page.tsx +47 -0
- package/src/app/(dashboard)/billing/credits/page.tsx +14 -67
- package/src/app/(dashboard)/billing/error.tsx +2 -10
- package/src/app/(dashboard)/billing/layout.tsx +12 -62
- package/src/app/(dashboard)/billing/payment/page.tsx +17 -68
- package/src/app/(dashboard)/billing/plans/page.tsx +3 -9
- package/src/app/(dashboard)/billing/usage/hosted/page.tsx +8 -25
- package/src/app/(dashboard)/billing/usage/page.tsx +63 -103
- package/src/app/(dashboard)/changesets/[id]/changeset-detail-client.tsx +9 -27
- package/src/app/(dashboard)/changesets/[id]/error.tsx +2 -6
- package/src/app/(dashboard)/changesets/error.tsx +1 -7
- package/src/app/(dashboard)/chat/page.tsx +2 -6
- package/src/app/(dashboard)/dashboard/network/page.tsx +5 -19
- package/src/app/(dashboard)/error.tsx +1 -7
- package/src/app/(dashboard)/layout.tsx +15 -36
- package/src/app/(dashboard)/marketplace/[plugin]/page.tsx +14 -51
- package/src/app/(dashboard)/marketplace/error.tsx +1 -7
- package/src/app/(dashboard)/marketplace/page.tsx +6 -27
- package/src/app/(dashboard)/not-found.tsx +2 -5
- package/src/app/(dashboard)/onboarding/page.tsx +5 -22
- package/src/app/(dashboard)/settings/account/page.tsx +1 -6
- package/src/app/(dashboard)/settings/activity/page.tsx +8 -34
- package/src/app/(dashboard)/settings/api-keys/page.tsx +15 -60
- package/src/app/(dashboard)/settings/brain/page.tsx +9 -31
- package/src/app/(dashboard)/settings/error.tsx +2 -10
- package/src/app/(dashboard)/settings/notifications/page.tsx +2 -6
- package/src/app/(dashboard)/settings/org/page.tsx +13 -56
- package/src/app/(dashboard)/settings/page.tsx +1 -0
- package/src/app/(dashboard)/settings/profile/page.tsx +126 -73
- package/src/app/(dashboard)/settings/providers/page.tsx +21 -78
- package/src/app/(dashboard)/settings/secrets/page.tsx +13 -58
- package/src/app/(dashboard)/settings/security/page.tsx +31 -111
- package/src/app/admin/email-templates/email-templates-client.tsx +15 -58
- package/src/app/admin/error.tsx +1 -7
- package/src/app/admin/fleet-updates/error.tsx +1 -7
- package/src/app/admin/fleet-updates/fleet-updates-client.tsx +10 -50
- package/src/app/admin/layout.tsx +4 -0
- package/src/app/admin/payment-methods/page.tsx +9 -38
- package/src/app/admin/products/error.tsx +2 -7
- package/src/app/admin/products/page.tsx +1 -4
- package/src/app/admin/promotions/[id]/page.tsx +9 -38
- package/src/app/admin/promotions/page.tsx +9 -36
- package/src/app/admin/rate-overrides/page.tsx +9 -45
- package/src/app/auth/callback/[provider]/page.tsx +1 -8
- package/src/app/auth/verify/page.tsx +9 -36
- package/src/app/channels/error.tsx +2 -10
- package/src/app/channels/layout.tsx +9 -0
- package/src/app/channels/page.tsx +8 -20
- package/src/app/channels/setup/[plugin]/page.tsx +3 -5
- package/src/app/error.tsx +1 -7
- package/src/app/fleet/error.tsx +1 -7
- package/src/app/fleet/layout.tsx +5 -0
- package/src/app/fleet/settings/page.tsx +1 -3
- package/src/app/global-error.tsx +2 -10
- package/src/app/globals.css +1 -4
- package/src/app/instances/[id]/instance-detail-client.tsx +51 -125
- package/src/app/instances/error.tsx +2 -10
- package/src/app/instances/instance-list-client.tsx +20 -69
- package/src/app/instances/layout.tsx +9 -0
- package/src/app/instances/new/create-instance-client.tsx +10 -31
- package/src/app/layout.tsx +2 -10
- package/src/app/not-found.tsx +1 -3
- package/src/app/page.tsx +1 -2
- package/src/app/plugins/error.tsx +2 -10
- package/src/app/plugins/layout.tsx +5 -0
- package/src/app/plugins/page.tsx +16 -48
- package/src/app/pricing/error.tsx +1 -7
- package/src/app/privacy/page.tsx +93 -150
- package/src/app/status/error.tsx +1 -7
- package/src/app/terms/page.tsx +89 -144
- package/src/components/account-switcher.tsx +25 -52
- package/src/components/admin/accounting-dashboard.tsx +1 -3
- package/src/components/admin/admin-guard.tsx +1 -3
- package/src/components/admin/admin-nav.tsx +1 -3
- package/src/components/admin/affiliate-dashboard.tsx +25 -94
- package/src/components/admin/audit-log-table.tsx +13 -49
- package/src/components/admin/billing-health-dashboard.tsx +7 -25
- package/src/components/admin/bulk-actions-bar.test.tsx +1 -7
- package/src/components/admin/bulk-actions-bar.tsx +1 -3
- package/src/components/admin/bulk-export-dialog.test.tsx +1 -7
- package/src/components/admin/bulk-export-dialog.tsx +6 -32
- package/src/components/admin/bulk-grant-dialog.test.tsx +2 -6
- package/src/components/admin/bulk-grant-dialog.tsx +4 -15
- package/src/components/admin/bulk-preview-dialog.tsx +3 -12
- package/src/components/admin/bulk-reactivate-dialog.tsx +1 -7
- package/src/components/admin/bulk-select-all-banner.tsx +1 -6
- package/src/components/admin/bulk-suspend-dialog.tsx +5 -12
- package/src/components/admin/bulk-undo-toast.tsx +1 -2
- package/src/components/admin/compliance-dashboard.tsx +31 -101
- package/src/components/admin/gpu-dashboard.tsx +21 -70
- package/src/components/admin/grant-credits-dialog.tsx +4 -17
- package/src/components/admin/incident-dashboard.tsx +10 -25
- package/src/components/admin/inference-dashboard.tsx +14 -54
- package/src/components/admin/marketplace-admin.tsx +18 -60
- package/src/components/admin/migrations-dashboard.tsx +9 -42
- package/src/components/admin/onboarding-dashboard.tsx +14 -64
- package/src/components/admin/pool-config-dashboard.tsx +4 -10
- package/src/components/admin/products/fleet-form.tsx +2 -11
- package/src/components/admin/products/nav-editor.tsx +3 -10
- package/src/components/admin/promotions/promotion-form.tsx +9 -42
- package/src/components/admin/roles-dashboard.tsx +7 -34
- package/src/components/admin/suspend-dialog.tsx +4 -11
- package/src/components/admin/tenant-notes-panel.tsx +1 -3
- package/src/components/admin/tenant-row-actions.tsx +4 -20
- package/src/components/admin/tenant-table.tsx +12 -49
- package/src/components/auth/auth-redirect.tsx +11 -3
- package/src/components/auth/email-verification-result-banner.tsx +1 -3
- package/src/components/auth/resend-verification-button.tsx +2 -10
- package/src/components/auth/wopr-wordmark.tsx +1 -3
- package/src/components/billing/add-payment-method-dialog.tsx +1 -2
- package/src/components/billing/affiliate-dashboard.tsx +4 -16
- package/src/components/billing/amount-selector.tsx +1 -3
- package/src/components/billing/auto-topup-card.tsx +2 -11
- package/src/components/billing/buy-credits-panel.tsx +14 -17
- package/src/components/billing/byok-callout.tsx +6 -8
- package/src/components/billing/confirmation-tracker.tsx +4 -14
- package/src/components/billing/credit-balance-badge.tsx +22 -0
- package/src/components/billing/credit-balance.tsx +3 -9
- package/src/components/billing/crypto-checkout.tsx +5 -24
- package/src/components/billing/degraded-state-banner.tsx +1 -3
- package/src/components/billing/deposit-view.tsx +301 -41
- package/src/components/billing/dividend-banner.tsx +1 -3
- package/src/components/billing/dividend-eligibility.tsx +3 -12
- package/src/components/billing/dividend-pool-stats.tsx +6 -20
- package/src/components/billing/first-dividend-dialog.tsx +2 -2
- package/src/components/billing/org-billing-page.tsx +8 -31
- package/src/components/billing/payment-method-picker.tsx +2 -10
- package/src/components/billing/suspension-banner.tsx +2 -7
- package/src/components/billing/transaction-history.tsx +10 -58
- package/src/components/billing/unified-checkout.tsx +547 -0
- package/src/components/bot-settings/backups-tab.tsx +9 -33
- package/src/components/bot-settings/bot-settings-client.tsx +32 -134
- package/src/components/bot-settings/resources-tab.tsx +2 -9
- package/src/components/bot-settings/storage-tab.tsx +19 -48
- package/src/components/bot-settings/vps-info-panel.tsx +3 -11
- package/src/components/bot-settings/vps-upgrade-card.tsx +3 -4
- package/src/components/brand-hydrator.tsx +13 -0
- package/src/components/channel-wizard/field-interactive.tsx +1 -3
- package/src/components/channel-wizard/field-qr.tsx +10 -39
- package/src/components/channel-wizard/step-renderer.tsx +5 -28
- package/src/components/channel-wizard/wizard.tsx +6 -31
- package/src/components/chat/chat-message.tsx +1 -4
- package/src/components/chat/chat-panel.tsx +4 -18
- package/src/components/chat/chat-widget.tsx +3 -14
- package/src/components/dashboard/command-center.tsx +15 -61
- package/src/components/fleet/update-settings-card.tsx +7 -23
- package/src/components/instance-update-banner.tsx +130 -0
- package/src/components/instances/friends-tab.test.tsx +2 -9
- package/src/components/instances/friends-tab.tsx +18 -74
- package/src/components/instances/update-available-badge.tsx +2 -11
- package/src/components/landing/hero.tsx +3 -9
- package/src/components/landing/landing-page.tsx +1 -3
- package/src/components/landing/portfolio-chart.tsx +4 -9
- package/src/components/landing/story-sections.tsx +1 -3
- package/src/components/landing/terminal-sequence.tsx +4 -17
- package/src/components/marketplace/empty-state.tsx +2 -6
- package/src/components/marketplace/first-visit-hero.tsx +1 -3
- package/src/components/marketplace/install-wizard.tsx +20 -77
- package/src/components/marketplace/marketplace-tabs.tsx +1 -4
- package/src/components/marketplace/plugin-card.tsx +2 -9
- package/src/components/marketplace/superpower-content.tsx +1 -3
- package/src/components/marketplace/terminal-search.tsx +2 -8
- package/src/components/oauth-buttons.tsx +29 -14
- package/src/components/observability/fleet-health.tsx +5 -18
- package/src/components/observability/health-overview.tsx +7 -20
- package/src/components/observability/logs-viewer.tsx +8 -32
- package/src/components/observability/metrics-dashboard.tsx +2 -15
- package/src/components/onboarding/fallback-setup.tsx +6 -25
- package/src/components/onboarding/setup-checklist.tsx +18 -51
- package/src/components/onboarding/step-superpowers.tsx +1 -4
- package/src/components/plugin-setup/setup-chat-panel.tsx +6 -22
- package/src/components/pricing/dividend-calculator.tsx +6 -12
- package/src/components/pricing/dividend-stats.tsx +5 -17
- package/src/components/pricing/pricing-page.tsx +17 -36
- package/src/components/settings/create-org-wizard.tsx +2 -5
- package/src/components/sidebar.tsx +7 -42
- package/src/components/sidecar-frame.tsx +78 -0
- package/src/components/status/status-page.tsx +6 -28
- package/src/components/ui/alert-dialog.tsx +8 -25
- package/src/components/ui/badge.tsx +2 -8
- package/src/components/ui/banner.tsx +1 -6
- package/src/components/ui/card.tsx +5 -24
- package/src/components/ui/checkbox.tsx +1 -5
- package/src/components/ui/collapsible.tsx +3 -8
- package/src/components/ui/dialog.tsx +4 -10
- package/src/components/ui/dropdown-menu.tsx +9 -18
- package/src/components/ui/form.tsx +2 -16
- package/src/components/ui/popover.tsx +3 -23
- package/src/components/ui/progress.tsx +1 -5
- package/src/components/ui/radio-group.tsx +3 -15
- package/src/components/ui/select.tsx +4 -17
- package/src/components/ui/sheet.tsx +5 -19
- package/src/components/ui/skeleton.tsx +1 -7
- package/src/components/ui/table.tsx +5 -22
- package/src/components/ui/tabs.tsx +3 -13
- package/src/components/ui/tooltip.tsx +1 -1
- package/src/components/unified-sidebar.tsx +493 -0
- package/src/hooks/__tests__/use-fleet-sse.test.ts +1 -4
- package/src/hooks/__tests__/use-save-queue.test.ts +2 -8
- package/src/hooks/use-credit-balance.ts +27 -0
- package/src/hooks/use-my-org-role.ts +1 -3
- package/src/hooks/use-plugin-registry.ts +8 -14
- package/src/hooks/use-plugin-setup-chat.ts +2 -5
- package/src/hooks/use-sidecar-bridge.tsx +148 -0
- package/src/hooks/use-webmcp.ts +1 -4
- package/src/lib/__tests__/admin-api.test.ts +1 -3
- package/src/lib/__tests__/api-bot-crud.test.ts +8 -18
- package/src/lib/__tests__/api-fetch.test.ts +4 -16
- package/src/lib/__tests__/org-billing-api.test.ts +1 -3
- package/src/lib/__tests__/pricing-data.test.ts +0 -8
- package/src/lib/__tests__/settings-api.test.ts +1 -3
- package/src/lib/admin-affiliate-api.ts +2 -7
- package/src/lib/admin-api.ts +6 -26
- package/src/lib/admin-incident-api.ts +11 -19
- package/src/lib/admin-marketplace-api.ts +1 -5
- package/src/lib/api-config.test.ts +5 -50
- package/src/lib/api.ts +143 -122
- package/src/lib/auth-client.ts +1 -2
- package/src/lib/bot-settings-data.ts +11 -36
- package/src/lib/brand-config.ts +56 -115
- package/src/lib/brand.ts +2 -15
- package/src/lib/chat/use-chat.ts +2 -7
- package/src/lib/cost-comparison-data.test.ts +1 -3
- package/src/lib/cost-comparison-data.ts +1 -4
- package/src/lib/errors.ts +1 -4
- package/src/lib/fetch-utils.test.ts +26 -9
- package/src/lib/fetch-utils.ts +40 -11
- package/src/lib/logger.ts +2 -0
- package/src/lib/marketplace-data.ts +3 -11
- package/src/lib/oauth-errors.ts +2 -4
- package/src/lib/onboarding-data.ts +3 -11
- package/src/lib/org-api.ts +2 -10
- package/src/lib/org-billing-api.ts +5 -19
- package/src/lib/plugin/tool-definitions.ts +1 -2
- package/src/lib/require-auth.ts +57 -0
- package/src/lib/settings-api.ts +1 -4
- package/src/lib/sidecar-routes.ts +43 -0
- package/src/lib/trpc-server.ts +49 -0
- package/src/lib/trpc-types.ts +4 -6
- package/src/lib/trpc.tsx +12 -4
- package/src/lib/validate-redirect-url.ts +1 -4
- package/src/lib/webmcp/marketplace-onboarding-tools.ts +6 -16
- package/src/lib/webmcp/register.ts +1 -4
- package/src/lib/webmcp/tools.ts +2 -9
- package/src/proxy.ts +35 -212
- package/src/types/missing-deps.d.ts +2 -8
- package/tsconfig.json +1 -8
- package/biome.json +0 -52
- package/src/__tests__/__snapshots__/layout-snapshots.test.tsx.snap +0 -741
- package/src/__tests__/billing-byok-callout.test.tsx +0 -76
- package/src/lib/__tests__/__snapshots__/pricing-data.test.ts.snap +0 -112
|
@@ -1,73 +1,113 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
1
2
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
2
3
|
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { createElement, type ReactNode } from "react";
|
|
3
5
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
-
import
|
|
6
|
+
import { trpcVanillaProxy } from "./setup.js";
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
// Mock tRPC hook return value
|
|
9
|
+
const mockUseQuery = vi.fn();
|
|
10
|
+
const mockRefetch = vi.fn();
|
|
7
11
|
|
|
8
|
-
vi.mock("@/lib/
|
|
9
|
-
|
|
12
|
+
vi.mock("@/lib/trpc", () => ({
|
|
13
|
+
trpc: {
|
|
14
|
+
billing: {
|
|
15
|
+
creditsDailySummary: {
|
|
16
|
+
useQuery: (...args: unknown[]) => mockUseQuery(...args),
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
trpcVanilla: trpcVanillaProxy,
|
|
10
21
|
}));
|
|
11
22
|
|
|
12
23
|
// Must import AFTER vi.mock
|
|
13
24
|
const { TransactionHistory } = await import("@/components/billing/transaction-history");
|
|
14
25
|
|
|
26
|
+
const NANO = 1_000_000_000;
|
|
27
|
+
|
|
28
|
+
function createWrapper() {
|
|
29
|
+
const queryClient = new QueryClient({
|
|
30
|
+
defaultOptions: { queries: { retry: false } },
|
|
31
|
+
});
|
|
32
|
+
return function Wrapper({ children }: { children: ReactNode }) {
|
|
33
|
+
return createElement(QueryClientProvider, { client: queryClient }, children);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
15
37
|
describe("TransactionHistory", () => {
|
|
16
38
|
beforeEach(() => {
|
|
17
|
-
|
|
39
|
+
mockUseQuery.mockReset();
|
|
40
|
+
mockRefetch.mockReset();
|
|
18
41
|
});
|
|
19
42
|
|
|
20
43
|
it("shows loading skeletons initially", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
mockUseQuery.mockReturnValue({
|
|
45
|
+
data: undefined,
|
|
46
|
+
isLoading: true,
|
|
47
|
+
error: null,
|
|
48
|
+
refetch: mockRefetch,
|
|
49
|
+
});
|
|
50
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
25
51
|
expect(screen.getByText("Transaction History")).toBeInTheDocument();
|
|
26
|
-
// 4 skeleton rows are rendered (no transaction text visible)
|
|
27
52
|
expect(screen.queryByText("No transactions yet.")).toBeNull();
|
|
28
53
|
});
|
|
29
54
|
|
|
30
55
|
it("renders empty state when no transactions", async () => {
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
mockUseQuery.mockReturnValue({
|
|
57
|
+
data: { rows: [] },
|
|
58
|
+
isLoading: false,
|
|
59
|
+
error: null,
|
|
60
|
+
refetch: mockRefetch,
|
|
61
|
+
});
|
|
62
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
33
63
|
await waitFor(() => {
|
|
34
64
|
expect(screen.getByText("No transactions yet.")).toBeInTheDocument();
|
|
35
65
|
});
|
|
36
66
|
});
|
|
37
67
|
|
|
38
68
|
it("renders transaction descriptions", async () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
mockUseQuery.mockReturnValue({
|
|
70
|
+
data: {
|
|
71
|
+
rows: [
|
|
72
|
+
{
|
|
73
|
+
id: "tx-1",
|
|
74
|
+
entryType: "purchase",
|
|
75
|
+
description: "Credit top-up",
|
|
76
|
+
signedAmountNano: 25 * NANO,
|
|
77
|
+
entryCount: 1,
|
|
78
|
+
postedAt: "2025-06-15T10:00:00Z",
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
isLoading: false,
|
|
83
|
+
error: null,
|
|
84
|
+
refetch: mockRefetch,
|
|
50
85
|
});
|
|
51
|
-
render(<TransactionHistory
|
|
86
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
52
87
|
await waitFor(() => {
|
|
53
88
|
expect(screen.getByText("Credit top-up")).toBeInTheDocument();
|
|
54
89
|
});
|
|
55
90
|
});
|
|
56
91
|
|
|
57
92
|
it("renders positive amounts with + prefix and emerald color", async () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
mockUseQuery.mockReturnValue({
|
|
94
|
+
data: {
|
|
95
|
+
rows: [
|
|
96
|
+
{
|
|
97
|
+
id: "tx-1",
|
|
98
|
+
entryType: "purchase",
|
|
99
|
+
description: "Top-up",
|
|
100
|
+
signedAmountNano: 50 * NANO,
|
|
101
|
+
entryCount: 1,
|
|
102
|
+
postedAt: "2025-06-15T10:00:00Z",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
isLoading: false,
|
|
107
|
+
error: null,
|
|
108
|
+
refetch: mockRefetch,
|
|
69
109
|
});
|
|
70
|
-
render(<TransactionHistory
|
|
110
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
71
111
|
await waitFor(() => {
|
|
72
112
|
const amountEl = screen.getByText("+$50.00");
|
|
73
113
|
expect(amountEl).toBeInTheDocument();
|
|
@@ -76,19 +116,24 @@ describe("TransactionHistory", () => {
|
|
|
76
116
|
});
|
|
77
117
|
|
|
78
118
|
it("renders negative amounts with - prefix and red color", async () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
119
|
+
mockUseQuery.mockReturnValue({
|
|
120
|
+
data: {
|
|
121
|
+
rows: [
|
|
122
|
+
{
|
|
123
|
+
id: "tx-1",
|
|
124
|
+
entryType: "bot_runtime",
|
|
125
|
+
description: "Bot usage",
|
|
126
|
+
signedAmountNano: -3.5 * NANO,
|
|
127
|
+
entryCount: 1,
|
|
128
|
+
postedAt: "2025-06-15T10:00:00Z",
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
isLoading: false,
|
|
133
|
+
error: null,
|
|
134
|
+
refetch: mockRefetch,
|
|
90
135
|
});
|
|
91
|
-
render(<TransactionHistory
|
|
136
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
92
137
|
await waitFor(() => {
|
|
93
138
|
const amountEl = screen.getByText("-$3.50");
|
|
94
139
|
expect(amountEl).toBeInTheDocument();
|
|
@@ -97,61 +142,72 @@ describe("TransactionHistory", () => {
|
|
|
97
142
|
});
|
|
98
143
|
|
|
99
144
|
it("renders correct type badge labels", async () => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
mockUseQuery.mockReturnValue({
|
|
146
|
+
data: {
|
|
147
|
+
rows: [
|
|
148
|
+
{
|
|
149
|
+
id: "tx-1",
|
|
150
|
+
entryType: "purchase",
|
|
151
|
+
description: "a",
|
|
152
|
+
signedAmountNano: 10 * NANO,
|
|
153
|
+
entryCount: 1,
|
|
154
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: "tx-2",
|
|
158
|
+
entryType: "signup_credit",
|
|
159
|
+
description: "b",
|
|
160
|
+
signedAmountNano: 5 * NANO,
|
|
161
|
+
entryCount: 1,
|
|
162
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "tx-3",
|
|
166
|
+
entryType: "bot_runtime",
|
|
167
|
+
description: "c",
|
|
168
|
+
signedAmountNano: -2 * NANO,
|
|
169
|
+
entryCount: 1,
|
|
170
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "tx-4",
|
|
174
|
+
entryType: "refund",
|
|
175
|
+
description: "d",
|
|
176
|
+
signedAmountNano: 3 * NANO,
|
|
177
|
+
entryCount: 1,
|
|
178
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: "tx-5",
|
|
182
|
+
entryType: "bonus",
|
|
183
|
+
description: "e",
|
|
184
|
+
signedAmountNano: 1 * NANO,
|
|
185
|
+
entryCount: 1,
|
|
186
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: "tx-6",
|
|
190
|
+
entryType: "adjustment",
|
|
191
|
+
description: "f",
|
|
192
|
+
signedAmountNano: -1 * NANO,
|
|
193
|
+
entryCount: 1,
|
|
194
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: "tx-7",
|
|
198
|
+
entryType: "community_dividend",
|
|
199
|
+
description: "g",
|
|
200
|
+
signedAmountNano: 2 * NANO,
|
|
201
|
+
entryCount: 1,
|
|
202
|
+
postedAt: "2025-01-01T00:00:00Z",
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
isLoading: false,
|
|
207
|
+
error: null,
|
|
208
|
+
refetch: mockRefetch,
|
|
153
209
|
});
|
|
154
|
-
render(<TransactionHistory
|
|
210
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
155
211
|
await waitFor(() => {
|
|
156
212
|
expect(screen.getByText("Purchase")).toBeInTheDocument();
|
|
157
213
|
expect(screen.getByText("Signup credit")).toBeInTheDocument();
|
|
@@ -164,28 +220,37 @@ describe("TransactionHistory", () => {
|
|
|
164
220
|
});
|
|
165
221
|
|
|
166
222
|
it("renders formatted dates", async () => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
223
|
+
mockUseQuery.mockReturnValue({
|
|
224
|
+
data: {
|
|
225
|
+
rows: [
|
|
226
|
+
{
|
|
227
|
+
id: "tx-1",
|
|
228
|
+
entryType: "purchase",
|
|
229
|
+
description: "Top-up",
|
|
230
|
+
signedAmountNano: 10 * NANO,
|
|
231
|
+
entryCount: 1,
|
|
232
|
+
postedAt: "2025-06-15T10:00:00Z",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
isLoading: false,
|
|
237
|
+
error: null,
|
|
238
|
+
refetch: mockRefetch,
|
|
178
239
|
});
|
|
179
|
-
render(<TransactionHistory
|
|
240
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
180
241
|
await waitFor(() => {
|
|
181
|
-
// toLocaleDateString("en-US", { month: "short", day: "numeric" }) → "Jun 15"
|
|
182
242
|
expect(screen.getByText("Jun 15")).toBeInTheDocument();
|
|
183
243
|
});
|
|
184
244
|
});
|
|
185
245
|
|
|
186
246
|
it("shows error state with retry button", async () => {
|
|
187
|
-
|
|
188
|
-
|
|
247
|
+
mockUseQuery.mockReturnValue({
|
|
248
|
+
data: undefined,
|
|
249
|
+
isLoading: false,
|
|
250
|
+
error: new Error("Network error"),
|
|
251
|
+
refetch: mockRefetch,
|
|
252
|
+
});
|
|
253
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
189
254
|
await waitFor(() => {
|
|
190
255
|
expect(screen.getByText("Failed to load transactions.")).toBeInTheDocument();
|
|
191
256
|
expect(screen.getByText("Retry")).toBeInTheDocument();
|
|
@@ -194,132 +259,19 @@ describe("TransactionHistory", () => {
|
|
|
194
259
|
|
|
195
260
|
it("retries loading on retry button click", async () => {
|
|
196
261
|
const user = userEvent.setup();
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
262
|
+
mockUseQuery.mockReturnValue({
|
|
263
|
+
data: undefined,
|
|
264
|
+
isLoading: false,
|
|
265
|
+
error: new Error("fail"),
|
|
266
|
+
refetch: mockRefetch,
|
|
267
|
+
});
|
|
201
268
|
|
|
202
|
-
render(<TransactionHistory
|
|
269
|
+
render(<TransactionHistory />, { wrapper: createWrapper() });
|
|
203
270
|
await waitFor(() => {
|
|
204
271
|
expect(screen.getByText("Retry")).toBeInTheDocument();
|
|
205
272
|
});
|
|
206
273
|
|
|
207
274
|
await user.click(screen.getByText("Retry"));
|
|
208
|
-
|
|
209
|
-
expect(screen.getByText("No transactions yet.")).toBeInTheDocument();
|
|
210
|
-
});
|
|
211
|
-
expect(mockGetCreditHistory).toHaveBeenCalledTimes(2);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("shows 'Load more' button when cursor exists", async () => {
|
|
215
|
-
mockGetCreditHistory.mockResolvedValue({
|
|
216
|
-
transactions: [
|
|
217
|
-
{
|
|
218
|
-
id: "tx-1",
|
|
219
|
-
type: "purchase",
|
|
220
|
-
description: "Top-up",
|
|
221
|
-
amount: 10,
|
|
222
|
-
createdAt: "2025-01-01T00:00:00Z",
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
nextCursor: "next-page-cursor",
|
|
226
|
-
});
|
|
227
|
-
render(<TransactionHistory />);
|
|
228
|
-
await waitFor(() => {
|
|
229
|
-
expect(screen.getByText("Load more")).toBeInTheDocument();
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("does not show 'Load more' when cursor is null", async () => {
|
|
234
|
-
mockGetCreditHistory.mockResolvedValue({
|
|
235
|
-
transactions: [
|
|
236
|
-
{
|
|
237
|
-
id: "tx-1",
|
|
238
|
-
type: "purchase",
|
|
239
|
-
description: "Top-up",
|
|
240
|
-
amount: 10,
|
|
241
|
-
createdAt: "2025-01-01T00:00:00Z",
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
nextCursor: null,
|
|
245
|
-
});
|
|
246
|
-
render(<TransactionHistory />);
|
|
247
|
-
await waitFor(() => {
|
|
248
|
-
expect(screen.getByText("Top-up")).toBeInTheDocument();
|
|
249
|
-
});
|
|
250
|
-
expect(screen.queryByText("Load more")).toBeNull();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("loads more transactions on 'Load more' click", async () => {
|
|
254
|
-
const user = userEvent.setup();
|
|
255
|
-
mockGetCreditHistory
|
|
256
|
-
.mockResolvedValueOnce({
|
|
257
|
-
transactions: [
|
|
258
|
-
{
|
|
259
|
-
id: "tx-1",
|
|
260
|
-
type: "purchase",
|
|
261
|
-
description: "First batch",
|
|
262
|
-
amount: 10,
|
|
263
|
-
createdAt: "2025-01-01T00:00:00Z",
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
nextCursor: "cursor-2",
|
|
267
|
-
})
|
|
268
|
-
.mockResolvedValueOnce({
|
|
269
|
-
transactions: [
|
|
270
|
-
{
|
|
271
|
-
id: "tx-2",
|
|
272
|
-
type: "refund",
|
|
273
|
-
description: "Second batch",
|
|
274
|
-
amount: 5,
|
|
275
|
-
createdAt: "2025-01-02T00:00:00Z",
|
|
276
|
-
},
|
|
277
|
-
],
|
|
278
|
-
nextCursor: null,
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
render(<TransactionHistory />);
|
|
282
|
-
await waitFor(() => {
|
|
283
|
-
expect(screen.getByText("First batch")).toBeInTheDocument();
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
await user.click(screen.getByText("Load more"));
|
|
287
|
-
await waitFor(() => {
|
|
288
|
-
expect(screen.getByText("Second batch")).toBeInTheDocument();
|
|
289
|
-
});
|
|
290
|
-
// Both batches visible
|
|
291
|
-
expect(screen.getByText("First batch")).toBeInTheDocument();
|
|
292
|
-
// Cursor was passed to second call
|
|
293
|
-
expect(mockGetCreditHistory).toHaveBeenCalledWith("cursor-2");
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("shows inline error when load-more fails but keeps existing transactions", async () => {
|
|
297
|
-
const user = userEvent.setup();
|
|
298
|
-
mockGetCreditHistory
|
|
299
|
-
.mockResolvedValueOnce({
|
|
300
|
-
transactions: [
|
|
301
|
-
{
|
|
302
|
-
id: "tx-1",
|
|
303
|
-
type: "purchase",
|
|
304
|
-
description: "Existing",
|
|
305
|
-
amount: 10,
|
|
306
|
-
createdAt: "2025-01-01T00:00:00Z",
|
|
307
|
-
},
|
|
308
|
-
],
|
|
309
|
-
nextCursor: "cursor-2",
|
|
310
|
-
})
|
|
311
|
-
.mockRejectedValueOnce(new Error("fail"));
|
|
312
|
-
|
|
313
|
-
render(<TransactionHistory />);
|
|
314
|
-
await waitFor(() => {
|
|
315
|
-
expect(screen.getByText("Existing")).toBeInTheDocument();
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
await user.click(screen.getByText("Load more"));
|
|
319
|
-
await waitFor(() => {
|
|
320
|
-
expect(screen.getByText("Failed to load more transactions.")).toBeInTheDocument();
|
|
321
|
-
});
|
|
322
|
-
// Original transaction still visible
|
|
323
|
-
expect(screen.getByText("Existing")).toBeInTheDocument();
|
|
275
|
+
expect(mockRefetch).toHaveBeenCalledTimes(1);
|
|
324
276
|
});
|
|
325
277
|
});
|
|
@@ -70,9 +70,7 @@ describe("trpc-types AppRouter contract", () => {
|
|
|
70
70
|
type _CheckActivate = Assert<"activate" extends keyof Promos ? true : false>;
|
|
71
71
|
type _CheckPause = Assert<"pause" extends keyof Promos ? true : false>;
|
|
72
72
|
type _CheckCancel = Assert<"cancel" extends keyof Promos ? true : false>;
|
|
73
|
-
type _CheckGenerateCouponBatch = Assert<
|
|
74
|
-
"generateCouponBatch" extends keyof Promos ? true : false
|
|
75
|
-
>;
|
|
73
|
+
type _CheckGenerateCouponBatch = Assert<"generateCouponBatch" extends keyof Promos ? true : false>;
|
|
76
74
|
// Runtime assertion is intentionally trivial — the real gate is tsc --noEmit
|
|
77
75
|
// which fails if any Assert<...> type above resolves to `false`.
|
|
78
76
|
expect(true).toBe(true);
|
|
@@ -82,9 +80,7 @@ describe("trpc-types AppRouter contract", () => {
|
|
|
82
80
|
type Caps = AppRouter["_def"]["record"]["capabilities"];
|
|
83
81
|
type _CheckStoreKey = Assert<"storeKey" extends keyof Caps ? true : false>;
|
|
84
82
|
type _CheckTestKey = Assert<"testKey" extends keyof Caps ? true : false>;
|
|
85
|
-
type _CheckListCapabilitySettings = Assert<
|
|
86
|
-
"listCapabilitySettings" extends keyof Caps ? true : false
|
|
87
|
-
>;
|
|
83
|
+
type _CheckListCapabilitySettings = Assert<"listCapabilitySettings" extends keyof Caps ? true : false>;
|
|
88
84
|
type _CheckListCapabilityMeta = Assert<"listCapabilityMeta" extends keyof Caps ? true : false>;
|
|
89
85
|
// Runtime assertion is intentionally trivial — the real gate is tsc --noEmit
|
|
90
86
|
// which fails if any Assert<...> type above resolves to `false`.
|
|
@@ -222,9 +222,7 @@ describe("useChat", () => {
|
|
|
222
222
|
expect(result.current.messages[0].role).toBe("user");
|
|
223
223
|
expect(result.current.messages[0].content).toBe("test");
|
|
224
224
|
expect(result.current.messages[1].role).toBe("bot");
|
|
225
|
-
expect(result.current.messages[1].content).toBe(
|
|
226
|
-
"Sorry, your message could not be sent. Please try again.",
|
|
227
|
-
);
|
|
225
|
+
expect(result.current.messages[1].content).toBe("Sorry, your message could not be sent. Please try again.");
|
|
228
226
|
|
|
229
227
|
sse.close();
|
|
230
228
|
});
|
|
@@ -24,10 +24,7 @@ describe("usePluginSetupChat sendMessage stale closure", () => {
|
|
|
24
24
|
result.current.sendMessage("hello");
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
expect(apiFetch).toHaveBeenCalledWith(
|
|
28
|
-
"/chat/setup/message",
|
|
29
|
-
expect.objectContaining({ method: "POST" }),
|
|
30
|
-
);
|
|
27
|
+
expect(apiFetch).toHaveBeenCalledWith("/chat/setup/message", expect.objectContaining({ method: "POST" }));
|
|
31
28
|
const firstCall = (apiFetch as ReturnType<typeof vi.fn>).mock.calls[0][1] as { body: string };
|
|
32
29
|
const firstBody = JSON.parse(firstCall.body) as Record<string, unknown>;
|
|
33
30
|
expect(firstBody.pluginId).toBe("plugin-A");
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { act, render } from "@testing-library/react";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { SidecarBridgeProvider, useSidecarBridge } from "@/hooks/use-sidecar-bridge";
|
|
6
|
+
|
|
7
|
+
function IframeRegistrar({ iframe }: { iframe: HTMLIFrameElement }) {
|
|
8
|
+
const { setIframeRef } = useSidecarBridge();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setIframeRef(iframe);
|
|
11
|
+
return () => setIframeRef(null);
|
|
12
|
+
}, [iframe, setIframeRef]);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function makeIframeWithSpy() {
|
|
17
|
+
const postMessage = vi.fn();
|
|
18
|
+
const iframe = {
|
|
19
|
+
contentWindow: { postMessage } as unknown as Window,
|
|
20
|
+
} as unknown as HTMLIFrameElement;
|
|
21
|
+
return { iframe, postMessage };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function fireReady() {
|
|
25
|
+
act(() => {
|
|
26
|
+
window.dispatchEvent(
|
|
27
|
+
new MessageEvent("message", {
|
|
28
|
+
data: { type: "ready" },
|
|
29
|
+
origin: window.location.origin,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Initial deep-link forwarding was moved out of `ready` — it now travels
|
|
37
|
+
* through `SidecarFrame`'s iframe src as `?initial-path=…`, which the
|
|
38
|
+
* sidecar's CompanyRootRedirect reads on first render. The ready-time
|
|
39
|
+
* postMessage approach was removed because it raced with the sidecar's
|
|
40
|
+
* own root redirect.
|
|
41
|
+
*/
|
|
42
|
+
describe("SidecarBridgeProvider", () => {
|
|
43
|
+
const originalUrl = window.location.pathname + window.location.search + window.location.hash;
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
window.history.replaceState(null, "", "/dashboard");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
window.history.replaceState(null, "", originalUrl);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("does not forward on ready — deep links travel via iframe src", () => {
|
|
54
|
+
window.history.replaceState(null, "", "/issues/IRA-10");
|
|
55
|
+
const { iframe, postMessage } = makeIframeWithSpy();
|
|
56
|
+
|
|
57
|
+
render(
|
|
58
|
+
<SidecarBridgeProvider>
|
|
59
|
+
<IframeRegistrar iframe={iframe} />
|
|
60
|
+
</SidecarBridgeProvider>,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
fireReady();
|
|
64
|
+
|
|
65
|
+
expect(postMessage).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("ignores duplicate ready messages without erroring", () => {
|
|
69
|
+
window.history.replaceState(null, "", "/dashboard");
|
|
70
|
+
const { iframe, postMessage } = makeIframeWithSpy();
|
|
71
|
+
|
|
72
|
+
render(
|
|
73
|
+
<SidecarBridgeProvider>
|
|
74
|
+
<IframeRegistrar iframe={iframe} />
|
|
75
|
+
</SidecarBridgeProvider>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
fireReady();
|
|
79
|
+
fireReady();
|
|
80
|
+
|
|
81
|
+
expect(postMessage).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("still updates shell URL on routeChanged", () => {
|
|
85
|
+
window.history.replaceState(null, "", "/");
|
|
86
|
+
const { iframe } = makeIframeWithSpy();
|
|
87
|
+
|
|
88
|
+
render(
|
|
89
|
+
<SidecarBridgeProvider>
|
|
90
|
+
<IframeRegistrar iframe={iframe} />
|
|
91
|
+
</SidecarBridgeProvider>,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
act(() => {
|
|
95
|
+
window.dispatchEvent(
|
|
96
|
+
new MessageEvent("message", {
|
|
97
|
+
data: { type: "routeChanged", path: "/LED/issues/LED-1" },
|
|
98
|
+
origin: window.location.origin,
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(window.location.pathname).toBe("/issues/LED-1");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -30,9 +30,7 @@ describe("useWebMCP", () => {
|
|
|
30
30
|
beforeEach(() => {
|
|
31
31
|
vi.resetAllMocks();
|
|
32
32
|
mockRegisterWebMCPTools.mockReturnValue(true);
|
|
33
|
-
vi.mocked(useSession).mockReturnValue({ data: { user: mockSession.user } } as ReturnType<
|
|
34
|
-
typeof useSession
|
|
35
|
-
>);
|
|
33
|
+
vi.mocked(useSession).mockReturnValue({ data: { user: mockSession.user } } as ReturnType<typeof useSession>);
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
it("registers tools when user is authenticated", () => {
|