@skyhook-io/radar-app 1.21.5 → 1.21.7
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/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +19 -1
- package/src/RadarApp.tsx +8 -2
- package/src/api/client.discoverMetrics.test.tsx +69 -0
- package/src/api/client.issueCorrelation.test.tsx +244 -0
- package/src/api/client.issueRowChanges.test.tsx +129 -0
- package/src/api/client.pendingOwnership.test.tsx +197 -0
- package/src/api/client.prometheusStatus.test.ts +4 -0
- package/src/api/client.restartError.test.ts +36 -1
- package/src/api/client.stopWorkflow.test.tsx +133 -0
- package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
- package/src/api/client.ts +572 -111
- package/src/api/connectionBinding.test.tsx +3 -1
- package/src/api/connectionBinding.ts +14 -2
- package/src/api/gitOpsPermissions.render.test.tsx +155 -0
- package/src/api/gitOpsPermissions.test.ts +90 -0
- package/src/api/gitOpsPermissions.ts +51 -0
- package/src/api/httpErrors.test.ts +30 -1
- package/src/api/httpErrors.ts +17 -0
- package/src/api/openobserveSetup.ts +85 -0
- package/src/api/podDebug.test.tsx +137 -0
- package/src/api/podDebug.ts +82 -0
- package/src/api/prometheusCharts.test.ts +23 -0
- package/src/api/prometheusCharts.ts +25 -0
- package/src/api/radarFeatures.render.test.tsx +43 -2
- package/src/api/radarFeatures.test.ts +18 -1
- package/src/api/radarFeatures.ts +17 -4
- package/src/api/reviewedActionMutation.ts +9 -2
- package/src/api/workloadMetrics.ts +2 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +56 -31
- package/src/components/cnpg/host.test.tsx +1 -1
- package/src/components/cnpg/host.tsx +0 -2
- package/src/components/dock/BottomDock.tsx +7 -3
- package/src/components/dock/MissingShellDebug.test.tsx +193 -0
- package/src/components/dock/MissingShellDebug.tsx +114 -0
- package/src/components/dock/PodDebugSession.test.tsx +60 -0
- package/src/components/dock/PodDebugSession.tsx +96 -0
- package/src/components/dock/TerminalTab.test.tsx +48 -4
- package/src/components/dock/TerminalTab.tsx +47 -25
- package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
- package/src/components/dock/WorkloadLogsTab.tsx +16 -0
- package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
- package/src/components/execution/BatchExecutionView.tsx +88 -5
- package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
- package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
- package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
- package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
- package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
- package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
- package/src/components/gitops/GitOpsView.tsx +93 -32
- package/src/components/helm/OwnedResources.tsx +1 -0
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +1 -1
- package/src/components/issues/IssuesPane.tsx +11 -0
- package/src/components/issues/useIssueExpansion.ts +91 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
- package/src/components/resource/MetricsNotConnected.tsx +114 -0
- package/src/components/resource/PVCUsageBar.tsx +2 -1
- package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
- package/src/components/resource/PrometheusCharts.tsx +14 -2
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
- package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
- package/src/components/resource/RestartChart.tsx +4 -3
- package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
- package/src/components/resource/RightsizingStrip.tsx +5 -3
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
- package/src/components/resource/nameMatchedScope.ts +9 -3
- package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
- package/src/components/resources/PodDebugAction.test.tsx +157 -0
- package/src/components/resources/PodDebugAction.tsx +207 -0
- package/src/components/resources/PodDebugPermission.tsx +21 -0
- package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
- package/src/components/resources/ResourcesView.tsx +39 -5
- package/src/components/resources/namespaceHint.test.ts +34 -0
- package/src/components/resources/namespaceHint.ts +19 -0
- package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
- package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +12 -5
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +167 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +343 -0
- package/src/components/settings/OpenObserveSetup.tsx +358 -0
- package/src/components/settings/SettingsDialog.tsx +21 -7
- package/src/components/settings/openobserveStatus.test.ts +34 -0
- package/src/components/settings/openobserveStatus.ts +55 -0
- package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
- package/src/components/timeline/TimelineList.test.ts +18 -0
- package/src/components/timeline/TimelineList.tsx +19 -5
- package/src/components/timeline/TimelineView.tsx +2 -0
- package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
- package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +95 -10
- package/src/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +3 -1
- package/src/hooks/useResourceCounts.ts +2 -1
- package/src/hooks/useWorkflowStopAction.ts +31 -0
- package/src/index.css +1 -0
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -2
- package/src/k8s-ui-exports.test.ts +10 -0
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ This package is source-only — it ships TypeScript + TSX files under `src/`. Co
|
|
|
10
10
|
npm install @skyhook-io/radar-app
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Peer deps: `react >=19`, `react-dom >=19`, `react-router-dom >=7`, `@tanstack/react-query >=5`, `@skyhook-io/k8s-ui >=1.
|
|
13
|
+
Peer deps: `react >=19`, `react-dom >=19`, `react-router-dom >=7`, `@tanstack/react-query >=5`, `@skyhook-io/k8s-ui >=1.21.7`, plus `clsx`, `tailwind-merge`, `lucide-react`, `@xyflow/react`, `elkjs`.
|
|
14
14
|
|
|
15
15
|
## Use
|
|
16
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skyhook-io/radar-app",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.7",
|
|
4
4
|
"description": "Radar's full web UI as a reusable React component. Used by Radar's own binary and by external consumers like Radar Cloud.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"yaml": "^2.9.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@skyhook-io/k8s-ui": ">=1.21.
|
|
46
|
+
"@skyhook-io/k8s-ui": ">=1.21.7",
|
|
47
47
|
"@tanstack/react-query": ">=5",
|
|
48
48
|
"@xyflow/react": ">=12.0.0",
|
|
49
49
|
"clsx": ">=2",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"@eslint/js": "^10.0.1",
|
|
59
59
|
"@playwright/test": "^1.64.1",
|
|
60
60
|
"@skyhook-io/k8s-ui": "*",
|
|
61
|
-
"@tailwindcss/vite": "^4.3.
|
|
61
|
+
"@tailwindcss/vite": "^4.3.5",
|
|
62
62
|
"@tanstack/react-query": "^5.105.0",
|
|
63
63
|
"@types/node": "^26.6.6",
|
|
64
64
|
"@types/react": "^19.3.0",
|
|
65
65
|
"@types/react-dom": "^19.3.0",
|
|
66
|
-
"@vitejs/plugin-react": "^6.
|
|
66
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
67
67
|
"@xyflow/react": "^12.12.0",
|
|
68
68
|
"clsx": "^2.1.1",
|
|
69
69
|
"elkjs": "^0.12.1",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
"react-dom": "^19.3.0",
|
|
79
79
|
"react-router-dom": "^7.18.5",
|
|
80
80
|
"tailwind-merge": "^3.7.0",
|
|
81
|
-
"tailwindcss": "^4.3.
|
|
81
|
+
"tailwindcss": "^4.3.5",
|
|
82
82
|
"typescript": "^6.0.2",
|
|
83
|
-
"typescript-eslint": "^8.
|
|
84
|
-
"vite": "^8.3.
|
|
83
|
+
"typescript-eslint": "^8.73.0",
|
|
84
|
+
"vite": "^8.3.8"
|
|
85
85
|
},
|
|
86
86
|
"sideEffects": [
|
|
87
87
|
"*.css"
|
package/src/App.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { switchInProgress } from './api/contextSwitch'
|
|
|
12
12
|
import { ContextSwitchActions } from './components/ContextSwitchActions'
|
|
13
13
|
import { investigationWorkspaceSearch, isInvestigationWorkspacePath, useDiagnoseLayout } from './components/diagnose/DiagnoseContext'
|
|
14
14
|
import { DiagnoseSurface } from './components/diagnose/DiagnoseSurface'
|
|
15
|
-
import { TopologyGraph, TopologySearch, TopologyBreadcrumb, TopologyFilterSidebar, TopologyControls, FreshnessControl, gitOpsRouteForKind, gitOpsRouteForResource, ScopePill, PaneLoader, usePhoneLayout, PHONE_MEDIA_QUERY } from '@skyhook-io/k8s-ui'
|
|
15
|
+
import { type IssueTimelineEventTarget, TopologyGraph, TopologySearch, TopologyBreadcrumb, TopologyFilterSidebar, TopologyControls, FreshnessControl, gitOpsRouteForKind, gitOpsRouteForResource, ScopePill, PaneLoader, usePhoneLayout, PHONE_MEDIA_QUERY } from '@skyhook-io/k8s-ui'
|
|
16
16
|
import { resetNavigationMap } from '@skyhook-io/k8s-ui/utils/navigation'
|
|
17
17
|
import { topologyNodeResourceKind } from '@skyhook-io/k8s-ui/utils/topology-neighborhood'
|
|
18
18
|
import { useAPIResources, findAPIResourceForRoute } from './api/apiResources'
|
|
@@ -28,6 +28,7 @@ import { TrafficView } from './components/traffic/TrafficView'
|
|
|
28
28
|
import { CostView } from './components/cost/CostView'
|
|
29
29
|
import { AuditView } from './components/audit/AuditView'
|
|
30
30
|
import { IssuesPane } from './components/issues/IssuesPane'
|
|
31
|
+
import { TimelineNavigationProvider, canOpenTimelineEvent, openTimelineEventIn } from './context/TimelineNavigation'
|
|
31
32
|
import { GitOpsView } from './components/gitops/GitOpsView'
|
|
32
33
|
import { gitopsTableChange } from './components/gitops/gitopsRowEvents'
|
|
33
34
|
import { ApplicationsView } from './components/applications/ApplicationsView'
|
|
@@ -1538,6 +1539,21 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1538
1539
|
{ onSuccess: (_scope, _vars, start) => { if (isAppliedNamespaceSwitch(start)) setNamespaces([]) } },
|
|
1539
1540
|
)
|
|
1540
1541
|
}, [namespaceScope?.cacheScoped, namespaces.length, setActiveNamespace])
|
|
1542
|
+
// A change's timeline event, in its namespace (all namespaces for a
|
|
1543
|
+
// cluster-scoped event). See openTimelineEventIn.
|
|
1544
|
+
const openTimelineEvent = useCallback((target: IssueTimelineEventTarget) => {
|
|
1545
|
+
openTimelineEventIn(target, {
|
|
1546
|
+
currentNamespaces: namespaces,
|
|
1547
|
+
cacheScoped: Boolean(namespaceScope?.cacheScoped),
|
|
1548
|
+
setNamespaces,
|
|
1549
|
+
requestNamespaces: (picked) => setActiveNamespace.mutate({ namespaces: picked }),
|
|
1550
|
+
navigate: (search) => navigate({ pathname: '/timeline', search: search.toString() }),
|
|
1551
|
+
})
|
|
1552
|
+
}, [namespaceScope?.cacheScoped, namespaces, navigate, setActiveNamespace])
|
|
1553
|
+
const timelineEventLinks = useMemo(() => ({
|
|
1554
|
+
onTimelineEventClick: openTimelineEvent,
|
|
1555
|
+
canOpenTimelineEvent: (target: IssueTimelineEventTarget) => canOpenTimelineEvent(target, Boolean(namespaceScope?.cacheScoped)),
|
|
1556
|
+
}), [openTimelineEvent, namespaceScope?.cacheScoped])
|
|
1541
1557
|
// Same write as the header picker, which then mirrors it into `namespaces`.
|
|
1542
1558
|
// The flash shows where that scope lives from now on. The picker owns the
|
|
1543
1559
|
// namespace scope from then on, so no kind keeps a Namespace column filter.
|
|
@@ -1895,6 +1911,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
1895
1911
|
const navActiveView = mainView === 'helmCompare' ? 'helm' : activeWorkspace?.navView ?? mainView
|
|
1896
1912
|
|
|
1897
1913
|
return (
|
|
1914
|
+
<TimelineNavigationProvider value={timelineEventLinks}>
|
|
1898
1915
|
<PortForwardProvider>
|
|
1899
1916
|
{/* Preserve the ~800px content floor: the rail is a fixed-width sibling, so
|
|
1900
1917
|
the outer minimum must include it (176px pinned / 56px collapsed) or the
|
|
@@ -2717,6 +2734,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2717
2734
|
</div>
|
|
2718
2735
|
</div>
|
|
2719
2736
|
</PortForwardProvider>
|
|
2737
|
+
</TimelineNavigationProvider>
|
|
2720
2738
|
)
|
|
2721
2739
|
}
|
|
2722
2740
|
|
package/src/RadarApp.tsx
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
} from "./components/ui/Toast";
|
|
35
35
|
import { setApiBase, setBasename } from "./api/config";
|
|
36
36
|
import { shouldRetryRadarQuery } from "./api/radarFeatures";
|
|
37
|
-
import { isShownInline } from "./api/httpErrors";
|
|
37
|
+
import { GitOpsActionError, isShownInline } from "./api/httpErrors";
|
|
38
38
|
import { NavCustomizationProvider } from "./context/NavCustomization";
|
|
39
39
|
import { FilterLocationBridge } from "./filter/FilterLocationBridge";
|
|
40
40
|
import type { NavCustomization } from "./context/NavCustomization";
|
|
@@ -203,7 +203,13 @@ export function makeDefaultQueryClient(): QueryClient {
|
|
|
203
203
|
mutationCache: new MutationCache({
|
|
204
204
|
onError: (error, _variables, _context, mutation) => {
|
|
205
205
|
const message = mutation.options.meta?.errorMessage;
|
|
206
|
-
if (message && !isShownInline(error))
|
|
206
|
+
if (message && !isShownInline(error)) {
|
|
207
|
+
if (error instanceof GitOpsActionError) {
|
|
208
|
+
showApiError(message, error.notificationDetail, error.rawDetail);
|
|
209
|
+
} else {
|
|
210
|
+
showApiError(message, (error as Error).message);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
207
213
|
},
|
|
208
214
|
onSuccess: (_data, _variables, _context, mutation) => {
|
|
209
215
|
const message = mutation.options.meta?.successMessage;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { useDiscoverMetrics } from './client'
|
|
7
|
+
|
|
8
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.unstubAllGlobals()
|
|
11
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
async function discover(connect: Response | Error, collector: Response) {
|
|
15
|
+
const calls: string[] = []
|
|
16
|
+
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input, init) => {
|
|
17
|
+
const url = String(input)
|
|
18
|
+
calls.push(`${init?.method ?? 'GET'} ${url}`)
|
|
19
|
+
if (!url.includes('/prometheus/connect')) return collector
|
|
20
|
+
if (connect instanceof Error) throw connect
|
|
21
|
+
return connect
|
|
22
|
+
}))
|
|
23
|
+
const client = new QueryClient({ defaultOptions: { mutations: { retry: false } } })
|
|
24
|
+
let mutate: (() => Promise<unknown>) | undefined
|
|
25
|
+
function Probe() {
|
|
26
|
+
const m = useDiscoverMetrics()
|
|
27
|
+
mutate = () => m.mutateAsync()
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
const root = createRoot(document.createElement('div'))
|
|
31
|
+
await act(async () => { root.render(<QueryClientProvider client={client}><Probe /></QueryClientProvider>) })
|
|
32
|
+
let outcome: unknown
|
|
33
|
+
await act(async () => { outcome = await mutate!().catch((e: unknown) => e) })
|
|
34
|
+
act(() => root.unmount())
|
|
35
|
+
return { outcome, calls }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const json = (body: unknown, status = 200) => new Response(JSON.stringify(body), { status })
|
|
39
|
+
|
|
40
|
+
it('stops when the connect call finds a source', async () => {
|
|
41
|
+
const { outcome, calls } = await discover(json({ available: true, connected: true }), json({ detected: true }))
|
|
42
|
+
expect(outcome).toBe('connected')
|
|
43
|
+
expect(calls).toHaveLength(1)
|
|
44
|
+
expect(calls[0]).toMatch(/^POST .*\/prometheus\/connect$/)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('reports a running OpenObserve collector when nothing connected', async () => {
|
|
48
|
+
const { outcome, calls } = await discover(json({ error: 'Prometheus connection failed' }, 502), json({ detected: true }))
|
|
49
|
+
expect(outcome).toBe('collector')
|
|
50
|
+
expect(calls[1]).toMatch(/^GET .*\/metrics\/openobserve\/collector$/)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it.each([
|
|
54
|
+
['no collector', json({ detected: false })],
|
|
55
|
+
['a Radar without the presence check', json({ error: 'not found' }, 404)],
|
|
56
|
+
])('reports nothing found with %s', async (_, collector) => {
|
|
57
|
+
const { outcome } = await discover(json({ available: true, connected: false }), collector)
|
|
58
|
+
expect(outcome).toBe('none')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it.each([
|
|
62
|
+
['the server refuses', json({ error: 'Not connected to a cluster' }, 503), 'Not connected to a cluster'],
|
|
63
|
+
['the request fails', new TypeError('Failed to fetch'), 'Failed to fetch'],
|
|
64
|
+
])('reports a failure instead of nothing found when %s', async (_, connect, message) => {
|
|
65
|
+
const { outcome, calls } = await discover(connect, json({ detected: true }))
|
|
66
|
+
expect(outcome).toBeInstanceOf(Error)
|
|
67
|
+
expect((outcome as Error).message).toBe(message)
|
|
68
|
+
expect(calls).toHaveLength(1)
|
|
69
|
+
})
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { focusManager, QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { IssueRow, issueTimingForDisplay, type Issue, type IssueExpansion } from '@skyhook-io/k8s-ui'
|
|
7
|
+
import { renderToString } from 'react-dom/server'
|
|
8
|
+
import { setApiBase } from './config'
|
|
9
|
+
import { RADAR_FEATURES, RadarFeatureUnsupportedError } from './radarFeatures'
|
|
10
|
+
import { issueExpansionFromQuery, useIssueExpansion } from '../components/issues/useIssueExpansion'
|
|
11
|
+
|
|
12
|
+
const issue: Issue = {
|
|
13
|
+
id: 'crash-api', severity: 'critical', source: 'problem', category: 'crashloop', category_group: 'runtime', grouping_scope: 'workload',
|
|
14
|
+
kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'api', reason: 'CrashLoopBackOff', first_seen: '2026-11-18T12:00:00Z',
|
|
15
|
+
}
|
|
16
|
+
const fresh: Issue = { ...issue, correlated_changes: [], no_recent_changes: { window_seconds: 3600 }, correlation: { window_from: '2026-11-18T11:00:00Z', window_to: '2026-11-18T12:10:00Z' } }
|
|
17
|
+
|
|
18
|
+
describe('issueExpansionFromQuery', () => {
|
|
19
|
+
const base = { data: undefined, error: null, isFetching: false, dataUpdatedAt: 0, refetch: () => {} }
|
|
20
|
+
it('uses the fresh issue with the same id', () => {
|
|
21
|
+
const e = issueExpansionFromQuery(issue, { ...base, data: { issues: [{ ...fresh, id: 'other' }, fresh], coverage: 'ok' } })
|
|
22
|
+
expect(e.recentChanges.status).toBe('loaded')
|
|
23
|
+
expect(e.issue).toBe(fresh)
|
|
24
|
+
})
|
|
25
|
+
it('keeps the last answer when a refresh fails and says when it arrived', () => {
|
|
26
|
+
const e = issueExpansionFromQuery(issue, { ...base, data: { issues: [fresh], coverage: 'ok' }, error: new Error('boom'), dataUpdatedAt: 1234 })
|
|
27
|
+
expect(e.recentChanges.status).toBe('loaded')
|
|
28
|
+
expect(e.issue).toBe(fresh)
|
|
29
|
+
expect(e.refreshFailed).toEqual({ fetchedAt: 1234 })
|
|
30
|
+
expect(e.onRetry).toEqual(expect.any(Function))
|
|
31
|
+
})
|
|
32
|
+
it('marks no refresh failure on a clean answer', () => {
|
|
33
|
+
expect(issueExpansionFromQuery(issue, { ...base, data: { issues: [fresh], coverage: 'ok' }, dataUpdatedAt: 1234 }).refreshFailed).toBeUndefined()
|
|
34
|
+
})
|
|
35
|
+
it.each([
|
|
36
|
+
['the server reports not_found', { issues: [fresh], coverage: 'ok' as const, correlation_status: 'not_found' as const }],
|
|
37
|
+
['the id is missing from the answer', { issues: [{ ...fresh, id: 'other' }], coverage: 'ok' as const }],
|
|
38
|
+
])('is not_found when %s', (_name, data) => {
|
|
39
|
+
const e = issueExpansionFromQuery(issue, { ...base, data })
|
|
40
|
+
expect(e.recentChanges.status).toBe('not_found')
|
|
41
|
+
expect(e.issue).toBeUndefined()
|
|
42
|
+
})
|
|
43
|
+
it.each(['user_forbidden', 'read_error'] as const)('maps a native Helm %s answer to that reason, not to not_found', (status) => {
|
|
44
|
+
const e = issueExpansionFromQuery(issue, { ...base, data: { issues: [], coverage: 'ok', correlation_status: status } })
|
|
45
|
+
expect(e.recentChanges).toEqual({ status: 'unavailable', reason: status })
|
|
46
|
+
expect(e.issue).toBeUndefined()
|
|
47
|
+
expect(e.onRetry).toEqual(expect.any(Function))
|
|
48
|
+
})
|
|
49
|
+
it.each([false, true])('does not override the row with an uncorrelated (ineligible) issue (refresh failed: %s)', (failed) => {
|
|
50
|
+
const unchanged = { ...issue, cause: 'from the correlation request' }
|
|
51
|
+
const e = issueExpansionFromQuery(issue, { ...base, data: { issues: [unchanged], coverage: 'ok' }, ...(failed ? { error: new Error('boom'), dataUpdatedAt: 5 } : {}) })
|
|
52
|
+
expect(e.recentChanges.status).toBe('loaded')
|
|
53
|
+
expect(e.issue).toBeUndefined()
|
|
54
|
+
})
|
|
55
|
+
it('maps an older Radar to the upgrade note', () => {
|
|
56
|
+
const e = issueExpansionFromQuery(issue, { ...base, error: new RadarFeatureUnsupportedError('issueCorrelation', {}) })
|
|
57
|
+
expect(e.recentChanges).toMatchObject({ status: 'unsupported', upgrade: { feature: RADAR_FEATURES.issueCorrelation.label } })
|
|
58
|
+
})
|
|
59
|
+
it('maps any other failure to a retryable error, and no answer yet to loading', () => {
|
|
60
|
+
expect(issueExpansionFromQuery(issue, { ...base, error: new Error('boom') })).toMatchObject({ recentChanges: { status: 'failed' }, onRetry: expect.any(Function) })
|
|
61
|
+
expect(issueExpansionFromQuery(issue, base).recentChanges.status).toBe('loading')
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
interface Captured { open?: (issue: Issue | null) => void; expansion?: IssueExpansion; other?: IssueExpansion }
|
|
66
|
+
function Probe({ onRender, onNotFound }: { onRender: (captured: Captured) => void; onNotFound: () => void }) {
|
|
67
|
+
const { onOpenIssueChange, expandedIssue } = useIssueExpansion(onNotFound)
|
|
68
|
+
onRender({ open: onOpenIssueChange, expansion: expandedIssue(issue), other: expandedIssue({ ...issue, id: 'other' }) })
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const roots: ReturnType<typeof createRoot>[] = []
|
|
73
|
+
const clients: QueryClient[] = []
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
vi.useFakeTimers()
|
|
77
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
78
|
+
focusManager.setFocused(true)
|
|
79
|
+
setApiBase('/api')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
roots.splice(0).forEach((root) => act(() => root.unmount()))
|
|
84
|
+
clients.splice(0).forEach((client) => client.clear())
|
|
85
|
+
focusManager.setFocused(undefined)
|
|
86
|
+
vi.unstubAllGlobals()
|
|
87
|
+
vi.useRealTimers()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
async function setup(flag: boolean, reply: object | ((issueRequest: number) => object) = { issues: [fresh], coverage: 'ok' }) {
|
|
91
|
+
let issueRequestCount = 0
|
|
92
|
+
const requests: URL[] = []
|
|
93
|
+
let failIssues = false
|
|
94
|
+
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
|
95
|
+
const url = new URL(input, 'http://localhost')
|
|
96
|
+
requests.push(url)
|
|
97
|
+
if (failIssues && url.pathname.includes('/issues/resource/')) return new Response(JSON.stringify({ error: 'store unavailable' }), { status: 500, headers: { 'Content-Type': 'application/json' } })
|
|
98
|
+
const isCapabilities = url.pathname.endsWith('/capabilities')
|
|
99
|
+
if (!isCapabilities && url.pathname.includes('/issues/resource/')) issueRequestCount++
|
|
100
|
+
const body = isCapabilities
|
|
101
|
+
? { version: 'v1.30.0', features: { resourceIssues: true, issueCorrelation: flag } }
|
|
102
|
+
: typeof reply === 'function' ? reply(issueRequestCount) : reply
|
|
103
|
+
return new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
104
|
+
}))
|
|
105
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } } })
|
|
106
|
+
clients.push(client)
|
|
107
|
+
const root = createRoot(document.createElement('div'))
|
|
108
|
+
roots.push(root)
|
|
109
|
+
const captured: Captured = {}
|
|
110
|
+
const onNotFound = vi.fn()
|
|
111
|
+
await act(async () => { root.render(<QueryClientProvider client={client}><Probe onRender={(next) => Object.assign(captured, next)} onNotFound={onNotFound} /></QueryClientProvider>) })
|
|
112
|
+
const settle = async (ms = 50) => { await act(async () => { await vi.advanceTimersByTimeAsync(ms) }) }
|
|
113
|
+
await settle()
|
|
114
|
+
const issueRequests = () => requests.filter((url) => url.pathname.includes('/issues/resource/'))
|
|
115
|
+
return { captured, onNotFound, settle, issueRequests, setFailIssues: (value: boolean) => { failIssues = value } }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
describe('useIssueExpansion', () => {
|
|
119
|
+
it('requests nothing until a row opens', async () => {
|
|
120
|
+
const h = await setup(true)
|
|
121
|
+
expect(h.issueRequests()).toHaveLength(0)
|
|
122
|
+
expect(h.captured.expansion).toBeUndefined()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('sends correlate=<id> for the open issue only, and polls every 60s while open', async () => {
|
|
126
|
+
const h = await setup(true)
|
|
127
|
+
await act(async () => { h.captured.open!(issue) })
|
|
128
|
+
await h.settle()
|
|
129
|
+
expect(h.issueRequests()).toHaveLength(1)
|
|
130
|
+
const url = h.issueRequests()[0]
|
|
131
|
+
expect(url.pathname).toBe('/api/issues/resource/Deployment/shop/api')
|
|
132
|
+
expect(url.searchParams.get('correlate')).toBe('crash-api')
|
|
133
|
+
expect(url.searchParams.get('coverage')).toBe('1')
|
|
134
|
+
expect(url.searchParams.get('group')).toBe('apps')
|
|
135
|
+
expect(h.captured.expansion?.issue).toMatchObject({ id: 'crash-api', no_recent_changes: { window_seconds: 3600 } })
|
|
136
|
+
expect(h.captured.other).toBeUndefined()
|
|
137
|
+
|
|
138
|
+
await h.settle(60_000)
|
|
139
|
+
expect(h.issueRequests()).toHaveLength(2)
|
|
140
|
+
|
|
141
|
+
await act(async () => { h.captured.open!(null) })
|
|
142
|
+
await h.settle(120_000)
|
|
143
|
+
expect(h.issueRequests()).toHaveLength(2)
|
|
144
|
+
expect(h.captured.expansion).toBeUndefined()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('keeps the fresh issue when a later poll fails, and says the refresh failed', async () => {
|
|
148
|
+
const h = await setup(true)
|
|
149
|
+
await act(async () => { h.captured.open!(issue) })
|
|
150
|
+
await h.settle()
|
|
151
|
+
expect(h.captured.expansion?.refreshFailed).toBeUndefined()
|
|
152
|
+
const firstAnswerAt = Date.now()
|
|
153
|
+
h.setFailIssues(true)
|
|
154
|
+
await h.settle(60_000)
|
|
155
|
+
await h.settle(5_000)
|
|
156
|
+
expect(h.captured.expansion?.issue).toMatchObject({ id: 'crash-api', no_recent_changes: { window_seconds: 3600 } })
|
|
157
|
+
expect(h.captured.expansion?.recentChanges.status).toBe('loaded')
|
|
158
|
+
expect(h.captured.expansion?.refreshFailed?.fetchedAt).toBeLessThanOrEqual(firstAnswerAt)
|
|
159
|
+
expect(h.captured.expansion?.refreshFailed?.fetchedAt).toBeGreaterThan(0)
|
|
160
|
+
|
|
161
|
+
h.setFailIssues(false)
|
|
162
|
+
await act(async () => { h.captured.expansion!.onRetry!() })
|
|
163
|
+
await h.settle()
|
|
164
|
+
expect(h.captured.expansion?.refreshFailed).toBeUndefined()
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('shows a new occurrence its own answer, even within the stale time', async () => {
|
|
168
|
+
const oldAnswer: Issue = {
|
|
169
|
+
...fresh, first_seen: '2026-11-18T10:00:00Z', cause: 'Old occurrence: probe failed after the 10:00 rollout.',
|
|
170
|
+
issue_timing: 'started_at_resource_creation', issue_timing_basis: 'pod_creation',
|
|
171
|
+
correlation: { window_from: '2026-11-18T09:00:00Z', window_to: '2026-11-18T10:30:00Z' },
|
|
172
|
+
}
|
|
173
|
+
const newAnswer: Issue = {
|
|
174
|
+
...fresh, first_seen: '2026-11-18T14:00:00Z', cause: 'New occurrence: image tag missing.',
|
|
175
|
+
issue_timing: 'started_after_resource_was_healthy', issue_timing_basis: 'condition',
|
|
176
|
+
correlation: { window_from: '2026-11-18T13:00:00Z', window_to: '2026-11-18T14:10:00Z' },
|
|
177
|
+
}
|
|
178
|
+
const h = await setup(true, (n) => ({ issues: [n === 1 ? oldAnswer : newAnswer], coverage: 'ok' }))
|
|
179
|
+
await act(async () => { h.captured.open!({ ...issue, first_seen: oldAnswer.first_seen }) })
|
|
180
|
+
await h.settle()
|
|
181
|
+
expect(h.issueRequests()).toHaveLength(1)
|
|
182
|
+
expect(h.captured.expansion?.issue?.cause).toBe(oldAnswer.cause)
|
|
183
|
+
|
|
184
|
+
await act(async () => { h.captured.open!(null) })
|
|
185
|
+
const recurred = { ...issue, first_seen: newAnswer.first_seen }
|
|
186
|
+
await act(async () => { h.captured.open!(recurred) })
|
|
187
|
+
await h.settle()
|
|
188
|
+
expect(h.issueRequests()).toHaveLength(2)
|
|
189
|
+
const shown = h.captured.expansion?.issue
|
|
190
|
+
expect(shown).toMatchObject({
|
|
191
|
+
first_seen: newAnswer.first_seen, issue_timing: newAnswer.issue_timing, correlation: { window_from: newAnswer.correlation!.window_from },
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const html = renderToString(<IssueRow issue={recurred} open onToggle={() => {}} expandedIssue={h.captured.expansion} />)
|
|
195
|
+
expect(html).toContain(newAnswer.cause)
|
|
196
|
+
expect(html).not.toContain(oldAnswer.cause)
|
|
197
|
+
expect(html).toContain(issueTimingForDisplay(newAnswer)!.chip)
|
|
198
|
+
expect(html).not.toContain(issueTimingForDisplay(oldAnswer)!.chip)
|
|
199
|
+
await act(async () => { h.captured.open!({ ...issue, first_seen: newAnswer.first_seen }) })
|
|
200
|
+
await h.settle()
|
|
201
|
+
expect(h.issueRequests()).toHaveLength(2)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('tells occurrences apart by the subject creation time when first_seen is missing', async () => {
|
|
205
|
+
const h = await setup(true)
|
|
206
|
+
await act(async () => { h.captured.open!({ ...issue, first_seen: undefined, resource_created_at: '2026-11-18T10:00:00Z' }) })
|
|
207
|
+
await h.settle()
|
|
208
|
+
await act(async () => { h.captured.open!({ ...issue, first_seen: undefined, resource_created_at: '2026-11-18T13:00:00Z' }) })
|
|
209
|
+
await h.settle()
|
|
210
|
+
expect(h.issueRequests()).toHaveLength(2)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('uses _ for a cluster-scoped subject', async () => {
|
|
214
|
+
const h = await setup(true, { issues: [{ ...fresh, kind: 'Node', group: undefined, namespace: undefined, name: 'n1' }], coverage: 'ok' })
|
|
215
|
+
await act(async () => { h.captured.open!({ ...issue, kind: 'Node', group: undefined, namespace: undefined, name: 'n1' }) })
|
|
216
|
+
await h.settle()
|
|
217
|
+
expect(h.issueRequests()[0].pathname).toBe('/api/issues/resource/Node/_/n1')
|
|
218
|
+
expect(h.issueRequests()[0].searchParams.has('group')).toBe(false)
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('sends no request to a Radar without the flag and shows the upgrade note', async () => {
|
|
222
|
+
const h = await setup(false)
|
|
223
|
+
await act(async () => { h.captured.open!(issue) })
|
|
224
|
+
await h.settle()
|
|
225
|
+
expect(h.issueRequests()).toHaveLength(0)
|
|
226
|
+
expect(h.captured.expansion?.recentChanges.status).toBe('unsupported')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it.each(['user_forbidden', 'read_error'] as const)('does not refresh the list for a native Helm %s answer', async (status) => {
|
|
230
|
+
const h = await setup(true, { issues: [], coverage: 'ok', correlation_status: status, unchecked_sources: [{ source: 'helm', reason: status }] })
|
|
231
|
+
await act(async () => { h.captured.open!(issue) })
|
|
232
|
+
await h.settle()
|
|
233
|
+
expect(h.captured.expansion?.recentChanges).toEqual({ status: 'unavailable', reason: status })
|
|
234
|
+
expect(h.onNotFound).not.toHaveBeenCalled()
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('asks the host to refresh its list when the open issue is not found', async () => {
|
|
238
|
+
const h = await setup(true, { issues: [], coverage: 'ok', correlation_status: 'not_found' })
|
|
239
|
+
await act(async () => { h.captured.open!(issue) })
|
|
240
|
+
await h.settle()
|
|
241
|
+
expect(h.captured.expansion?.recentChanges.status).toBe('not_found')
|
|
242
|
+
expect(h.onNotFound).toHaveBeenCalledTimes(1)
|
|
243
|
+
})
|
|
244
|
+
})
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { focusManager, QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { issueRowKey, type Issue, type IssueRowChange } from '@skyhook-io/k8s-ui'
|
|
7
|
+
import { setApiBase } from './config'
|
|
8
|
+
import { ISSUE_ROW_CHANGES_MAX, issueRowChangeParam, useIssueRowChanges } from './client'
|
|
9
|
+
import { timelineEventSearch } from '../context/TimelineNavigation'
|
|
10
|
+
|
|
11
|
+
const issue = (id: string, extra: Partial<Issue> = {}): Issue => ({
|
|
12
|
+
id, severity: 'critical', source: 'problem', category: 'crashloop', category_group: 'runtime', grouping_scope: 'workload',
|
|
13
|
+
kind: 'Deployment', group: 'apps', namespace: 'shop', name: id, reason: 'CrashLoopBackOff', ...extra,
|
|
14
|
+
})
|
|
15
|
+
const change: IssueRowChange = {
|
|
16
|
+
first_seen: '2026-11-18T12:00:00Z',
|
|
17
|
+
change: { kind: 'Deployment', apiVersion: 'apps/v1', namespace: 'shop', name: 'api', changeType: 'update', timestamp: '2026-11-18T11:56:00Z', event_id: 'ev-1' },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('issueRowChangeParam', () => {
|
|
21
|
+
it("names the issue and its subject in the per-resource route's terms", () => {
|
|
22
|
+
expect(issueRowChangeParam(issue('api'))).toBe('api/Deployment/shop/api/apps')
|
|
23
|
+
expect(issueRowChangeParam(issue('svc', { kind: 'Service', group: '' }))).toBe('svc/Service/shop/svc')
|
|
24
|
+
expect(issueRowChangeParam(issue('node', { kind: 'Node', group: '', namespace: undefined }))).toBe('node/Node/_/node')
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('timelineEventSearch', () => {
|
|
29
|
+
it('opens the event in a frozen range around it, so an event older than the default hour is in view', () => {
|
|
30
|
+
const now = Date.parse('2026-11-18T15:00:00Z')
|
|
31
|
+
const at = Date.parse('2026-11-18T12:00:00Z')
|
|
32
|
+
const search = timelineEventSearch({ eventId: 'ev-1', namespace: 'shop', timestamp: '2026-11-18T12:00:00Z' }, now)
|
|
33
|
+
expect(search.get('event')).toBe('ev-1')
|
|
34
|
+
expect(Number(search.get('from'))).toBeLessThan(at)
|
|
35
|
+
expect(Number(search.get('to'))).toBeGreaterThan(at)
|
|
36
|
+
})
|
|
37
|
+
it("widens a list that keeps its own time range far enough to hold the event", () => {
|
|
38
|
+
const now = Date.parse('2026-11-18T15:00:00Z')
|
|
39
|
+
const range = (at: string) => timelineEventSearch({ eventId: 'ev-1', namespace: 'shop', timestamp: at }, now).get('time')
|
|
40
|
+
expect(range('2026-11-18T14:50:00Z')).toBe('1h')
|
|
41
|
+
expect(range('2026-11-18T12:00:00Z')).toBe('6h')
|
|
42
|
+
expect(range('2026-11-17T12:00:00Z')).toBe('all')
|
|
43
|
+
expect(range('2026-09-01T12:00:00Z')).toBe('all')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('never ends the range in the future', () => {
|
|
47
|
+
const now = Date.parse('2026-11-18T12:05:00Z')
|
|
48
|
+
const search = timelineEventSearch({ eventId: 'ev-1', namespace: '', timestamp: '2026-11-18T12:00:00Z' }, now)
|
|
49
|
+
expect(Number(search.get('to'))).toBe(now)
|
|
50
|
+
expect(Number(search.get('from'))).toBeLessThan(Date.parse('2026-11-18T12:00:00Z'))
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
let captured: ReadonlyMap<string, IssueRowChange> | undefined
|
|
55
|
+
function Probe({ issues, onRender }: { issues: Issue[]; onRender: (changes: ReadonlyMap<string, IssueRowChange> | undefined) => void }) {
|
|
56
|
+
onRender(useIssueRowChanges(issues))
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const roots: ReturnType<typeof createRoot>[] = []
|
|
61
|
+
const clients: QueryClient[] = []
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
vi.useFakeTimers()
|
|
64
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
65
|
+
focusManager.setFocused(true)
|
|
66
|
+
setApiBase('/api')
|
|
67
|
+
captured = undefined
|
|
68
|
+
})
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
roots.splice(0).forEach((root) => act(() => root.unmount()))
|
|
71
|
+
clients.splice(0).forEach((client) => client.clear())
|
|
72
|
+
focusManager.setFocused(undefined)
|
|
73
|
+
vi.unstubAllGlobals()
|
|
74
|
+
vi.useRealTimers()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
async function setup(flag: boolean, issues: Issue[]) {
|
|
78
|
+
const requests: URL[] = []
|
|
79
|
+
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
|
80
|
+
const url = new URL(input, 'http://localhost')
|
|
81
|
+
requests.push(url)
|
|
82
|
+
const body = url.pathname.endsWith('/capabilities')
|
|
83
|
+
? { version: 'v1.30.0', features: { resourceIssues: true, issueCorrelation: flag } }
|
|
84
|
+
: { changes: { api: change } }
|
|
85
|
+
return new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
86
|
+
}))
|
|
87
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } } })
|
|
88
|
+
clients.push(client)
|
|
89
|
+
const root = createRoot(document.createElement('div'))
|
|
90
|
+
roots.push(root)
|
|
91
|
+
const render = (next: Issue[]) => act(async () => { root.render(<QueryClientProvider client={client}><Probe issues={next} onRender={(changes) => { captured = changes }} /></QueryClientProvider>) })
|
|
92
|
+
await render(issues)
|
|
93
|
+
const settle = async (ms = 50) => { await act(async () => { await vi.advanceTimersByTimeAsync(ms) }) }
|
|
94
|
+
await settle()
|
|
95
|
+
return { settle, render, rowRequests: () => requests.filter((url) => url.pathname.endsWith('/issues/recent-changes')) }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
describe('useIssueRowChanges', () => {
|
|
99
|
+
it('asks once for the rows on screen and keys the answer by row', async () => {
|
|
100
|
+
const h = await setup(true, [issue('api'), issue('web')])
|
|
101
|
+
expect(h.rowRequests()).toHaveLength(1)
|
|
102
|
+
expect(h.rowRequests()[0].searchParams.getAll('issue')).toEqual(['api/Deployment/shop/api/apps', 'web/Deployment/shop/web/apps'])
|
|
103
|
+
expect(captured?.get(issueRowKey(issue('api')))).toEqual(change)
|
|
104
|
+
expect(captured?.has(issueRowKey(issue('web')))).toBe(false)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('asks again when the rows on screen change, and polls every minute', async () => {
|
|
108
|
+
const h = await setup(true, [issue('api')])
|
|
109
|
+
await h.render([issue('api'), issue('web')])
|
|
110
|
+
await h.settle()
|
|
111
|
+
expect(h.rowRequests()).toHaveLength(2)
|
|
112
|
+
await h.settle(60_000)
|
|
113
|
+
expect(h.rowRequests()).toHaveLength(3)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it(`sends at most ${ISSUE_ROW_CHANGES_MAX} rows`, async () => {
|
|
117
|
+
const many = Array.from({ length: ISSUE_ROW_CHANGES_MAX + 5 }, (_, i) => issue(`i${i}`))
|
|
118
|
+
const h = await setup(true, many)
|
|
119
|
+
expect(h.rowRequests()[0].searchParams.getAll('issue')).toHaveLength(ISSUE_ROW_CHANGES_MAX)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('asks nothing of a Radar without the capability, or with no rows on screen', async () => {
|
|
123
|
+
const old = await setup(false, [issue('api')])
|
|
124
|
+
expect(old.rowRequests()).toHaveLength(0)
|
|
125
|
+
expect(captured).toBeUndefined()
|
|
126
|
+
const none = await setup(true, [])
|
|
127
|
+
expect(none.rowRequests()).toHaveLength(0)
|
|
128
|
+
})
|
|
129
|
+
})
|