@skyhook-io/radar-app 1.19.0 → 1.20.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/README.md +1 -1
- package/package.json +5 -5
- package/src/App.tsx +31 -5
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +40 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/diagnose/AIMarkdown.tsx +3 -0
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
- package/src/components/diagnose/DiagnoseContext.tsx +68 -2
- package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +26 -0
- package/src/components/diagnose/Home.tsx +20 -1
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
- package/src/components/diagnose/InvestigationView.tsx +94 -26
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.tsx +8 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/home/ClusterHealthCard.tsx +1 -1
- package/src/components/home/HomeAgentBlock.test.tsx +31 -3
- package/src/components/home/HomeAgentBlock.tsx +13 -4
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +81 -41
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
- package/src/components/whats-new/releaseNotes.ts +77 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +6 -4
- package/src/hooks/useElementSize.ts +30 -0
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
5
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
6
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
7
|
+
import type { GitOpsHistoryItem, GitOpsInsight } from '@skyhook-io/k8s-ui'
|
|
8
|
+
import { GitOpsView } from './GitOpsView'
|
|
9
|
+
|
|
10
|
+
const harness = vi.hoisted(() => ({
|
|
11
|
+
rollback: vi.fn(),
|
|
12
|
+
resume: vi.fn(),
|
|
13
|
+
onResume: undefined as undefined | (() => void),
|
|
14
|
+
showError: vi.fn(),
|
|
15
|
+
multiSourceWarning: undefined as boolean | undefined,
|
|
16
|
+
source: undefined as string | undefined,
|
|
17
|
+
confirm: undefined as undefined | ((opts: { prune: boolean; dryRun: boolean }) => void),
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const app = {
|
|
21
|
+
apiVersion: 'argoproj.io/v1alpha1',
|
|
22
|
+
kind: 'Application',
|
|
23
|
+
metadata: { name: 'guestbook', namespace: 'argocd' },
|
|
24
|
+
spec: { project: 'default', source: {}, destination: {}, syncPolicy: {} },
|
|
25
|
+
status: { sync: { status: 'Synced' }, health: { status: 'Healthy' } },
|
|
26
|
+
}
|
|
27
|
+
const insight = {
|
|
28
|
+
summary: { tool: 'argocd', kind: 'Application', namespace: 'argocd', name: 'guestbook', autoSyncMode: 'Manual' },
|
|
29
|
+
capabilities: { rollback: true },
|
|
30
|
+
history: [{ id: '0', revision: 'aaa111' }],
|
|
31
|
+
} as unknown as GitOpsInsight
|
|
32
|
+
|
|
33
|
+
// The layout and the history view are replaced by stubs that expose just what
|
|
34
|
+
// the rollback path needs: the Activity body, the dialog, and the gate.
|
|
35
|
+
vi.mock('@skyhook-io/k8s-ui', async (importOriginal) => {
|
|
36
|
+
const actual = await importOriginal<typeof import('@skyhook-io/k8s-ui')>()
|
|
37
|
+
return {
|
|
38
|
+
...actual,
|
|
39
|
+
useToast: () => ({ showError: harness.showError, showSuccess: vi.fn(), showToast: vi.fn() }),
|
|
40
|
+
GitOpsDetailLayout: (props: { argo?: { onResume: () => void; resumeUpgrade?: unknown; resumeBlockedReason?: string }; renderTabBody: (ctx: { tab: 'activity'; fullscreen: boolean }) => React.ReactNode; children?: React.ReactNode }) => {
|
|
41
|
+
harness.onResume = props.argo?.onResume
|
|
42
|
+
return <div>
|
|
43
|
+
<button disabled={!!props.argo?.resumeUpgrade || !!props.argo?.resumeBlockedReason} onClick={props.argo?.onResume}>Enable auto-sync</button>
|
|
44
|
+
{props.argo?.resumeBlockedReason}
|
|
45
|
+
{props.renderTabBody({ tab: 'activity', fullscreen: false })}{props.children}
|
|
46
|
+
</div>
|
|
47
|
+
},
|
|
48
|
+
GitOpsActivityInsightView: (props: { onRollback?: (item: GitOpsHistoryItem) => void; rollbackUpgrade?: unknown; rollbackBlockedReason?: string }) => (
|
|
49
|
+
<div>{props.rollbackBlockedReason}<button type="button" disabled={!!props.rollbackUpgrade || !!props.rollbackBlockedReason} onClick={() => props.onRollback?.({ id: '0', revision: 'aaa111', source: 'guestbook (+1 more)', rollbackMultiSourceWarning: true })}>Rollback</button></div>
|
|
50
|
+
),
|
|
51
|
+
RollbackDialog: (props: { open: boolean; source?: string; multiSourceWarning?: boolean; onConfirm: (opts: { prune: boolean; dryRun: boolean }) => void }) => {
|
|
52
|
+
if (props.open) {
|
|
53
|
+
harness.confirm = props.onConfirm
|
|
54
|
+
harness.multiSourceWarning = props.multiSourceWarning
|
|
55
|
+
harness.source = props.source
|
|
56
|
+
}
|
|
57
|
+
return props.open ? <div role="dialog">Roll back?</div> : null
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
vi.mock('../../api/client', async (importOriginal) => {
|
|
62
|
+
const actual = await importOriginal<typeof import('../../api/client')>()
|
|
63
|
+
const idle = () => ({ mutate: vi.fn(), reset: vi.fn(), isPending: false })
|
|
64
|
+
return {
|
|
65
|
+
...actual,
|
|
66
|
+
useResource: () => ({ data: app, isLoading: false, error: null }),
|
|
67
|
+
useGitOpsTree: () => ({ data: undefined, isLoading: false, error: null }),
|
|
68
|
+
useGitOpsInsights: () => ({ data: insight, isLoading: false, error: null }),
|
|
69
|
+
useArgoRollback: () => ({ mutate: harness.rollback, isPending: false }),
|
|
70
|
+
useArgoSync: idle, useArgoResourceValidation: idle, useArgoRefresh: idle, useArgoTerminate: idle,
|
|
71
|
+
useArgoSuspend: idle, useArgoResume: () => ({ mutate: harness.resume, isPending: false }), useApplyResource: idle,
|
|
72
|
+
useFluxReconcile: idle, useFluxSyncWithSource: idle, useFluxSuspend: idle, useFluxResume: idle,
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
vi.mock('../../api/apiResources', async (importOriginal) => ({
|
|
76
|
+
...(await importOriginal<typeof import('../../api/apiResources')>()),
|
|
77
|
+
useAPIResources: () => ({ data: [], isLoading: false }),
|
|
78
|
+
}))
|
|
79
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { state: 'connected' } }) }))
|
|
80
|
+
vi.mock('../../context/RadarUpgradeHost', () => ({ useRadarUpgradeHost: () => ({}) }))
|
|
81
|
+
vi.mock('../useContextSwitchFlow', () => ({ useContextSwitchFlow: () => ({ confirmDialog: null, requestSwitch: vi.fn() }) }))
|
|
82
|
+
vi.mock('./useDestinationCluster', () => ({ useDestinationCluster: () => ({}) }))
|
|
83
|
+
vi.mock('../../hooks/useKeyboardShortcuts', () => ({ useRegisterShortcut: () => {} }))
|
|
84
|
+
vi.mock('../../hooks/usePreviousIntegrationSettings', () => ({ usePreviousIntegrationSettings: () => ({}), previousSettingsNote: () => undefined }))
|
|
85
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
86
|
+
|
|
87
|
+
let client: QueryClient
|
|
88
|
+
let host: HTMLDivElement
|
|
89
|
+
let root: ReturnType<typeof createRoot>
|
|
90
|
+
|
|
91
|
+
beforeEach(async () => {
|
|
92
|
+
app.spec.syncPolicy = {}
|
|
93
|
+
harness.resume.mockClear()
|
|
94
|
+
harness.onResume = undefined
|
|
95
|
+
harness.rollback.mockClear()
|
|
96
|
+
harness.showError.mockClear()
|
|
97
|
+
harness.confirm = undefined
|
|
98
|
+
harness.multiSourceWarning = undefined
|
|
99
|
+
harness.source = undefined
|
|
100
|
+
// /api/capabilities and /version-check stay pending until a test answers.
|
|
101
|
+
vi.stubGlobal('fetch', vi.fn(() => new Promise<Response>(() => {})))
|
|
102
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
103
|
+
host = document.createElement('div')
|
|
104
|
+
document.body.append(host)
|
|
105
|
+
root = createRoot(host)
|
|
106
|
+
await act(async () => root.render(
|
|
107
|
+
<MemoryRouter initialEntries={['/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io']}>
|
|
108
|
+
<QueryClientProvider client={client}><GitOpsView namespaces={[]} onOpenResource={() => {}} /></QueryClientProvider>
|
|
109
|
+
</MemoryRouter>,
|
|
110
|
+
))
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
afterEach(async () => {
|
|
114
|
+
await act(async () => root.unmount())
|
|
115
|
+
client.clear()
|
|
116
|
+
host.remove()
|
|
117
|
+
vi.unstubAllGlobals()
|
|
118
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const settle = async () => { await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)) }) }
|
|
122
|
+
const rollbackButton = () => [...host.querySelectorAll('button')].find((b) => b.textContent === 'Rollback')!
|
|
123
|
+
|
|
124
|
+
it('does not send a rollback confirmed after capabilities show an older Radar', async () => {
|
|
125
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { argoRollbackSync: true } }) })
|
|
126
|
+
await settle()
|
|
127
|
+
expect(rollbackButton().disabled).toBe(false)
|
|
128
|
+
await act(async () => rollbackButton().click())
|
|
129
|
+
expect(host.querySelector('[role="dialog"]')).not.toBeNull()
|
|
130
|
+
|
|
131
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { workloadHistory: true } }) })
|
|
132
|
+
await settle()
|
|
133
|
+
expect(rollbackButton().disabled).toBe(true)
|
|
134
|
+
await act(async () => harness.confirm!({ prune: false, dryRun: false }))
|
|
135
|
+
|
|
136
|
+
expect(harness.rollback).not.toHaveBeenCalled()
|
|
137
|
+
expect(harness.showError).toHaveBeenCalledWith('Rollback unavailable', expect.stringContaining('Argo CD rollbacks need'))
|
|
138
|
+
expect(host.querySelector('[role="dialog"]')).toBeNull()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('sends history id 0 once capabilities advertise argoRollbackSync', async () => {
|
|
142
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { argoRollbackSync: true } }) })
|
|
143
|
+
await settle()
|
|
144
|
+
expect(rollbackButton().disabled).toBe(false)
|
|
145
|
+
await act(async () => rollbackButton().click())
|
|
146
|
+
await act(async () => harness.confirm!({ prune: false, dryRun: false }))
|
|
147
|
+
expect(harness.rollback).toHaveBeenCalledWith(expect.objectContaining({ namespace: 'argocd', name: 'guestbook', id: 0 }), expect.any(Object))
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('passes the selected multi-source history entry to the rollback confirmation', async () => {
|
|
151
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { argoRollbackSync: true } }) })
|
|
152
|
+
await settle()
|
|
153
|
+
await act(async () => rollbackButton().click())
|
|
154
|
+
expect(harness.multiSourceWarning).toBe(true)
|
|
155
|
+
expect(harness.source).toBe('guestbook (+1 more)')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('disables rollback while capabilities are pending with checking copy', () => {
|
|
159
|
+
expect(rollbackButton().disabled).toBe(true)
|
|
160
|
+
expect(host.textContent).toContain("Checking this cluster's Radar…")
|
|
161
|
+
expect(host.textContent).not.toContain('need the latest Radar')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('does not execute confirmation while capabilities are pending', async () => {
|
|
165
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { argoRollbackSync: true } }) })
|
|
166
|
+
await settle()
|
|
167
|
+
await act(async () => rollbackButton().click())
|
|
168
|
+
expect(host.querySelector('[role="dialog"]')).not.toBeNull()
|
|
169
|
+
await act(async () => { void client.resetQueries({ queryKey: ['capabilities'] }) })
|
|
170
|
+
await settle()
|
|
171
|
+
expect(rollbackButton().disabled).toBe(true)
|
|
172
|
+
await act(async () => harness.confirm!({ prune: false, dryRun: false }))
|
|
173
|
+
expect(harness.rollback).not.toHaveBeenCalled()
|
|
174
|
+
expect(harness.showError).toHaveBeenCalledWith('Rollback unavailable', "Checking this cluster's Radar…")
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('keeps rollback disabled with check-unavailable copy when capabilities fail', async () => {
|
|
178
|
+
await act(async () => {
|
|
179
|
+
client.getQueryCache().find({ queryKey: ['capabilities'] })!.setState({ status: 'error', error: new Error('offline'), fetchStatus: 'idle' })
|
|
180
|
+
})
|
|
181
|
+
await settle()
|
|
182
|
+
expect(rollbackButton().disabled).toBe(true)
|
|
183
|
+
expect(host.textContent).toContain("Couldn't check this cluster's Radar support. Refresh to try again.")
|
|
184
|
+
expect(host.textContent).not.toContain('need the latest Radar')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('requires affirmative support before enabling an automated block switched off in place', async () => {
|
|
188
|
+
app.spec.syncPolicy = { automated: { enabled: false } }
|
|
189
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { argoRollbackSync: true } }) })
|
|
190
|
+
await settle()
|
|
191
|
+
await act(async () => { void client.resetQueries({ queryKey: ['capabilities'] }) })
|
|
192
|
+
await settle()
|
|
193
|
+
const enable = () => [...host.querySelectorAll('button')].find(b => b.textContent === 'Enable auto-sync')!
|
|
194
|
+
expect(enable().disabled).toBe(true)
|
|
195
|
+
await act(async () => harness.onResume!())
|
|
196
|
+
expect(harness.resume).not.toHaveBeenCalled()
|
|
197
|
+
await act(async () => { client.setQueryData(['capabilities'], { features: { argoRollbackSync: true } }) })
|
|
198
|
+
await settle()
|
|
199
|
+
expect(enable().disabled).toBe(false)
|
|
200
|
+
await act(async () => harness.onResume!())
|
|
201
|
+
expect(harness.resume).toHaveBeenCalledOnce()
|
|
202
|
+
})
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
5
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
+
import { normalizeArgoApplication } from '@skyhook-io/k8s-ui'
|
|
8
|
+
import type { ArgoActionHandlers, GitOpsInsight, GitOpsInsightRef, GitOpsRow, GitOpsRowAction } from '@skyhook-io/k8s-ui'
|
|
9
|
+
import { GitOpsView } from './GitOpsView'
|
|
10
|
+
|
|
11
|
+
// The requests the Sync dialog builds, sent by the real useArgoSync and
|
|
12
|
+
// useArgoResourceValidation: only a Radar advertising argoSyncInheritance is
|
|
13
|
+
// trusted to read an omitted syncOptions as the Application's own.
|
|
14
|
+
|
|
15
|
+
const APP_OPTIONS = ['CreateNamespace=true', 'ServerSideApply=true']
|
|
16
|
+
const app = {
|
|
17
|
+
apiVersion: 'argoproj.io/v1alpha1',
|
|
18
|
+
kind: 'Application',
|
|
19
|
+
metadata: { name: 'guestbook', namespace: 'argocd' },
|
|
20
|
+
spec: { project: 'default', source: {} as Record<string, unknown>, sources: undefined as Array<{ repoURL: string; targetRevision: string }> | undefined, destination: {}, syncPolicy: { syncOptions: APP_OPTIONS } },
|
|
21
|
+
status: { sync: { status: 'OutOfSync', revision: undefined as string | undefined, revisions: undefined as string[] | undefined, comparedTo: undefined as Record<string, unknown> | undefined }, health: { status: 'Healthy' } },
|
|
22
|
+
}
|
|
23
|
+
const insight = {
|
|
24
|
+
summary: { tool: 'argocd', kind: 'Application', namespace: 'argocd', name: 'guestbook', autoSyncMode: 'Manual' },
|
|
25
|
+
} as unknown as GitOpsInsight
|
|
26
|
+
const deployment: GitOpsInsightRef = { kind: 'Deployment', group: 'apps', namespace: 'guestbook', name: 'web' }
|
|
27
|
+
|
|
28
|
+
vi.mock('@skyhook-io/k8s-ui', async (importOriginal) => {
|
|
29
|
+
const actual = await importOriginal<typeof import('@skyhook-io/k8s-ui')>()
|
|
30
|
+
return {
|
|
31
|
+
...actual,
|
|
32
|
+
useToast: () => ({ showError: vi.fn(), showSuccess: vi.fn(), showToast: vi.fn() }),
|
|
33
|
+
GitOpsTableView: (props: { rows: GitOpsRow[]; onRowAction: (row: GitOpsRow, action: GitOpsRowAction) => void }) => (
|
|
34
|
+
<button type="button" onClick={() => props.onRowAction(props.rows[0], 'sync')}>Open sync</button>
|
|
35
|
+
),
|
|
36
|
+
GitOpsDetailLayout: (props: { argo?: ArgoActionHandlers; renderTabBody: (ctx: { tab: 'changes'; fullscreen: boolean }) => React.ReactNode; children?: React.ReactNode }) => (
|
|
37
|
+
<div data-resume-settings={JSON.stringify(props.argo?.resumeSettings ?? null)}>
|
|
38
|
+
<button type="button" onClick={() => props.argo?.onSyncRequested()}>Open sync</button>
|
|
39
|
+
{props.renderTabBody({ tab: 'changes', fullscreen: false })}
|
|
40
|
+
{props.children}
|
|
41
|
+
</div>
|
|
42
|
+
),
|
|
43
|
+
GitOpsChangesView: (props: { onSyncResource?: (ref: GitOpsInsightRef) => void }) => (
|
|
44
|
+
<button type="button" onClick={() => props.onSyncResource?.(deployment)}>Open resource sync</button>
|
|
45
|
+
),
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
const toast = vi.hoisted(() => ({ success: vi.fn() }))
|
|
49
|
+
vi.mock('../ui/Toast', async (importOriginal) => ({
|
|
50
|
+
...(await importOriginal<typeof import('../ui/Toast')>()),
|
|
51
|
+
showApiSuccess: toast.success,
|
|
52
|
+
}))
|
|
53
|
+
vi.mock('../../api/client', async (importOriginal) => {
|
|
54
|
+
const actual = await importOriginal<typeof import('../../api/client')>()
|
|
55
|
+
const idle = () => ({ mutate: vi.fn(), reset: vi.fn(), isPending: false })
|
|
56
|
+
return {
|
|
57
|
+
...actual,
|
|
58
|
+
useResource: () => ({ data: app, isLoading: false, error: null }),
|
|
59
|
+
useGitOpsTree: () => ({ data: undefined, isLoading: false, error: null }),
|
|
60
|
+
useGitOpsInsights: () => ({ data: insight, isLoading: false, error: null }),
|
|
61
|
+
useArgoRollback: idle, useArgoRefresh: idle, useArgoTerminate: idle,
|
|
62
|
+
useArgoSuspend: idle, useArgoResume: idle, useApplyResource: idle,
|
|
63
|
+
useFluxReconcile: idle, useFluxSyncWithSource: idle, useFluxSuspend: idle, useFluxResume: idle,
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
vi.mock('../../api/apiResources', async (importOriginal) => ({
|
|
67
|
+
...(await importOriginal<typeof import('../../api/apiResources')>()),
|
|
68
|
+
useAPIResources: () => ({ data: [], isLoading: false }),
|
|
69
|
+
}))
|
|
70
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { state: 'connected' } }) }))
|
|
71
|
+
vi.mock('../../context/RadarUpgradeHost', () => ({ useRadarUpgradeHost: () => ({}) }))
|
|
72
|
+
vi.mock('../useContextSwitchFlow', () => ({ useContextSwitchFlow: () => ({ confirmDialog: null, requestSwitch: vi.fn() }) }))
|
|
73
|
+
vi.mock('./useDestinationCluster', () => ({ useDestinationCluster: () => ({}) }))
|
|
74
|
+
vi.mock('../../hooks/useKeyboardShortcuts', () => ({ useRegisterShortcut: () => {} }))
|
|
75
|
+
vi.mock('../../hooks/usePreviousIntegrationSettings', () => ({ usePreviousIntegrationSettings: () => ({}), previousSettingsNote: () => undefined }))
|
|
76
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
77
|
+
|
|
78
|
+
let client: QueryClient
|
|
79
|
+
let host: HTMLDivElement
|
|
80
|
+
let root: ReturnType<typeof createRoot>
|
|
81
|
+
let requests: Array<{ path: string; body: Record<string, unknown> }>
|
|
82
|
+
|
|
83
|
+
beforeEach(async () => {
|
|
84
|
+
requests = []
|
|
85
|
+
vi.stubGlobal('fetch', vi.fn((input: RequestInfo | URL, init?: RequestInit) => {
|
|
86
|
+
const path = String(input)
|
|
87
|
+
if (init?.method === 'POST') {
|
|
88
|
+
requests.push({ path, body: JSON.parse(String(init.body)) })
|
|
89
|
+
const answer = path.endsWith('/validate-resource') ? { outcome: 'succeeded', message: 'ok' } : { message: 'Sync initiated' }
|
|
90
|
+
return Promise.resolve(new Response(JSON.stringify(answer), { status: 200, headers: { 'Content-Type': 'application/json' } }))
|
|
91
|
+
}
|
|
92
|
+
// /api/capabilities and /version-check stay pending; tests set capabilities.
|
|
93
|
+
return new Promise<Response>(() => {})
|
|
94
|
+
}))
|
|
95
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
96
|
+
host = document.createElement('div')
|
|
97
|
+
document.body.append(host)
|
|
98
|
+
root = createRoot(host)
|
|
99
|
+
await renderView('/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
afterEach(async () => {
|
|
103
|
+
await act(async () => root.unmount())
|
|
104
|
+
client.clear()
|
|
105
|
+
host.remove()
|
|
106
|
+
document.body.innerHTML = ''
|
|
107
|
+
app.spec.source = {}
|
|
108
|
+
app.spec.sources = undefined
|
|
109
|
+
app.status.sync.revision = undefined
|
|
110
|
+
app.status.sync.revisions = undefined
|
|
111
|
+
app.status.sync.comparedTo = undefined
|
|
112
|
+
vi.unstubAllGlobals()
|
|
113
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
async function renderView(path: string) {
|
|
117
|
+
if (path === '/gitops') {
|
|
118
|
+
client.setQueryData(['gitops-rows-main', [], 0], { coverageStatus: 'complete', rows: [normalizeArgoApplication(app)] })
|
|
119
|
+
}
|
|
120
|
+
await act(async () => root.render(
|
|
121
|
+
<MemoryRouter key={path} initialEntries={[path]}>
|
|
122
|
+
<QueryClientProvider client={client}><GitOpsView namespaces={[]} onOpenResource={() => {}} /></QueryClientProvider>
|
|
123
|
+
</MemoryRouter>,
|
|
124
|
+
))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const settle = async () => { await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)) }) }
|
|
128
|
+
// A sync using Replace or Force is labelled "Sync with replace" etc.
|
|
129
|
+
const button = (label: string) => [...document.querySelectorAll('button')].find((b) => {
|
|
130
|
+
const text = b.textContent?.trim() ?? ''
|
|
131
|
+
return text === label || text.startsWith(`${label === 'Sync now' ? 'Sync' : label} with `)
|
|
132
|
+
})!
|
|
133
|
+
const toggle = (label: string) => [...document.querySelectorAll('label')].find((l) => l.textContent?.startsWith(label))!.querySelector('input')!
|
|
134
|
+
const click = async (el: HTMLElement) => { await act(async () => el.click()); await settle() }
|
|
135
|
+
const advertise = async (features: Record<string, boolean>) => {
|
|
136
|
+
await act(async () => { client.setQueryData(['capabilities'], { features }) })
|
|
137
|
+
await settle()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
describe('a Radar that advertises argoSyncInheritance', () => {
|
|
141
|
+
beforeEach(async () => { await advertise({ argoRollbackSync: true, argoSyncInheritance: true }) })
|
|
142
|
+
|
|
143
|
+
it("omits the options for an unchanged sync and always sends prune", async () => {
|
|
144
|
+
await click(button('Open sync'))
|
|
145
|
+
await click(button('Sync now'))
|
|
146
|
+
expect(requests).toHaveLength(1)
|
|
147
|
+
expect(requests[0].path).toBe('/api/argo/applications/argocd/guestbook/sync')
|
|
148
|
+
expect(requests[0].body.prune).toBe(false)
|
|
149
|
+
expect(requests[0].body).not.toHaveProperty('syncOptions')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('sends an edited list when a toggle changes', async () => {
|
|
153
|
+
await click(button('Open sync'))
|
|
154
|
+
await click(toggle('Server-side apply'))
|
|
155
|
+
await click(button('Sync now'))
|
|
156
|
+
expect(requests[0].body).toMatchObject({ prune: false, syncOptions: ['CreateNamespace=true'] })
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it.each([
|
|
160
|
+
{ change: 'the compared revision', apply: () => { app.status.sync.revision = 'new-sha' } },
|
|
161
|
+
{ change: 'the source', apply: () => { app.spec.source = { repoURL: 'https://example.com/other', targetRevision: 'main' } } },
|
|
162
|
+
{ change: 'the comparison', apply: () => { app.status.sync.comparedTo = { source: app.spec.source } } },
|
|
163
|
+
])('drops a dry-run pass once $change changes', async ({ apply }) => {
|
|
164
|
+
await click(button('Open resource sync'))
|
|
165
|
+
await click(button('Dry-run'))
|
|
166
|
+
expect(document.body.textContent).toContain('Dry-run passed')
|
|
167
|
+
apply()
|
|
168
|
+
await renderView('/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io')
|
|
169
|
+
await settle()
|
|
170
|
+
expect(document.body.textContent).toContain('Sync resource')
|
|
171
|
+
expect(document.body.textContent).not.toContain('Dry-run passed')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('keeps a dry-run pass while what it checked is unchanged', async () => {
|
|
175
|
+
await click(button('Open resource sync'))
|
|
176
|
+
await click(button('Dry-run'))
|
|
177
|
+
await renderView('/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io')
|
|
178
|
+
await settle()
|
|
179
|
+
expect(document.body.textContent).toContain('Dry-run passed')
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('validates and syncs one resource with the inherited options', async () => {
|
|
183
|
+
await click(button('Open resource sync'))
|
|
184
|
+
await click(button('Dry-run'))
|
|
185
|
+
await click(button('Sync resource'))
|
|
186
|
+
expect(requests.map((r) => r.path)).toEqual([
|
|
187
|
+
'/api/argo/applications/argocd/guestbook/validate-resource',
|
|
188
|
+
'/api/argo/applications/argocd/guestbook/sync',
|
|
189
|
+
])
|
|
190
|
+
expect(requests[0].body).not.toHaveProperty('syncOptions')
|
|
191
|
+
expect(requests[1].body).toMatchObject({ prune: false, resources: [{ group: 'apps', kind: 'Deployment', namespace: 'guestbook', name: 'web' }] })
|
|
192
|
+
expect(requests[1].body).not.toHaveProperty('syncOptions')
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
describe('an older Radar, without argoSyncInheritance', () => {
|
|
197
|
+
beforeEach(async () => { await advertise({ argoRollbackSync: true }) })
|
|
198
|
+
|
|
199
|
+
it("sends the Application's options, which it would otherwise drop, and prune false, which it would otherwise default to true", async () => {
|
|
200
|
+
await click(button('Open sync'))
|
|
201
|
+
await click(button('Sync now'))
|
|
202
|
+
expect(requests[0].body).toMatchObject({ prune: false, syncOptions: APP_OPTIONS })
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('sends an edited list the same way', async () => {
|
|
206
|
+
await click(button('Open sync'))
|
|
207
|
+
await click(toggle('Server-side apply'))
|
|
208
|
+
await click(button('Sync now'))
|
|
209
|
+
expect(requests[0].body).toMatchObject({ prune: false, syncOptions: ['CreateNamespace=true'] })
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it("validates and syncs one resource with the Application's options", async () => {
|
|
213
|
+
await click(button('Open resource sync'))
|
|
214
|
+
await click(button('Dry-run'))
|
|
215
|
+
await click(button('Sync resource'))
|
|
216
|
+
expect(requests[0].body.syncOptions).toEqual(APP_OPTIONS)
|
|
217
|
+
expect(requests[1].body).toMatchObject({ prune: false, syncOptions: APP_OPTIONS })
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it.each([
|
|
222
|
+
{ dryRun: false, message: 'Sync initiated' },
|
|
223
|
+
{ dryRun: true, message: 'Dry run started' },
|
|
224
|
+
])('confirms a sync with dryRun $dryRun as "$message"', async ({ dryRun, message }) => {
|
|
225
|
+
toast.success.mockClear()
|
|
226
|
+
await click(button('Open sync'))
|
|
227
|
+
if (dryRun) {
|
|
228
|
+
const label = [...document.querySelectorAll('label')].find((l) => l.textContent?.startsWith('Dry run'))!
|
|
229
|
+
await click(label.querySelector('input')!)
|
|
230
|
+
}
|
|
231
|
+
await click(button(dryRun ? 'Run dry-run' : 'Sync now'))
|
|
232
|
+
expect(requests[0].body).toMatchObject({ dryRun })
|
|
233
|
+
expect(toast.success).toHaveBeenCalledWith(message)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('treats a Radar whose capabilities have not loaded as older', async () => {
|
|
237
|
+
await click(button('Open sync'))
|
|
238
|
+
await click(button('Sync now'))
|
|
239
|
+
expect(requests[0].body).toMatchObject({ prune: false, syncOptions: APP_OPTIONS })
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it.each([
|
|
243
|
+
'/gitops',
|
|
244
|
+
'/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io',
|
|
245
|
+
])('explains compared revisions for multi-source sync from %s', async (path) => {
|
|
246
|
+
app.spec.sources = [
|
|
247
|
+
{ repoURL: 'https://example.com/app', targetRevision: 'main' },
|
|
248
|
+
{ repoURL: 'https://example.com/values', targetRevision: 'v1' },
|
|
249
|
+
]
|
|
250
|
+
app.status.sync.revisions = ['app-sha', 'values-sha']
|
|
251
|
+
app.status.sync.comparedTo = { sources: app.spec.sources }
|
|
252
|
+
await advertise({ argoRollbackSync: true, argoSyncInheritance: true })
|
|
253
|
+
await renderView(path)
|
|
254
|
+
await click(button('Open sync'))
|
|
255
|
+
expect(document.body.textContent).not.toContain('Revision (optional)')
|
|
256
|
+
expect(document.body.textContent).toContain('Syncs each source at the revision Argo last compared.')
|
|
257
|
+
await click(button('Sync now'))
|
|
258
|
+
expect(requests).toHaveLength(1)
|
|
259
|
+
expect(requests[0].body).not.toHaveProperty('revision')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it.each([
|
|
263
|
+
'/gitops',
|
|
264
|
+
'/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io',
|
|
265
|
+
])('shows the compared revision in the sync dialog from %s', async (path) => {
|
|
266
|
+
app.spec.source = { repoURL: 'https://example.com/app', targetRevision: 'main' }
|
|
267
|
+
app.status.sync.revision = 'abcdef0123456789abcdef0123456789abcdef01'
|
|
268
|
+
app.status.sync.comparedTo = { source: { targetRevision: 'main', repoURL: 'https://example.com/app' } }
|
|
269
|
+
await advertise({ argoRollbackSync: true, argoSyncInheritance: true })
|
|
270
|
+
await renderView(path)
|
|
271
|
+
await click(button('Open sync'))
|
|
272
|
+
expect(document.body.textContent).toContain('Leave empty for the revision Argo last compared (abcdef0).')
|
|
273
|
+
await click(button('Sync now'))
|
|
274
|
+
expect(requests[0].body).not.toHaveProperty('revision')
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
// A comparison made for an earlier source won't be pinned, so it isn't promised.
|
|
278
|
+
it('promises no compared revision when the source changed since the comparison', async () => {
|
|
279
|
+
app.spec.source = { repoURL: 'https://example.com/app', targetRevision: 'release' }
|
|
280
|
+
app.status.sync.revision = 'abcdef0123456789abcdef0123456789abcdef01'
|
|
281
|
+
app.status.sync.comparedTo = { source: { repoURL: 'https://example.com/app', targetRevision: 'main' } }
|
|
282
|
+
await advertise({ argoRollbackSync: true, argoSyncInheritance: true })
|
|
283
|
+
await renderView('/gitops')
|
|
284
|
+
await click(button('Open sync'))
|
|
285
|
+
expect(document.body.textContent).toContain('Leave empty for the target revision, resolved when the sync runs.')
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
// An older Radar resolves an omitted revision when the sync runs.
|
|
289
|
+
it.each([
|
|
290
|
+
'/gitops',
|
|
291
|
+
'/gitops/detail/applications/argocd/guestbook?apiGroup=argoproj.io',
|
|
292
|
+
])('promises no compared revision to an older Radar from %s', async (path) => {
|
|
293
|
+
app.status.sync.revision = 'abcdef0123456789abcdef0123456789abcdef01'
|
|
294
|
+
await advertise({ argoRollbackSync: true })
|
|
295
|
+
await renderView(path)
|
|
296
|
+
await click(button('Open sync'))
|
|
297
|
+
expect(document.body.textContent).toContain('Leave empty for the target revision, resolved when the sync runs.')
|
|
298
|
+
expect(document.body.textContent).not.toContain('last compared')
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
const STALE_OPTIONS_NOTICE = "The Application's sync options changed while this dialog was open. This sync uses the options shown here. Cancel and reopen to load the latest."
|
|
302
|
+
|
|
303
|
+
async function replaceTableApplication(syncOptions: string[], automated = false) {
|
|
304
|
+
const replacement = {
|
|
305
|
+
...app,
|
|
306
|
+
spec: { ...app.spec, syncPolicy: { syncOptions, ...(automated ? { automated: {} } : {}) } },
|
|
307
|
+
}
|
|
308
|
+
await act(async () => {
|
|
309
|
+
client.setQueryData(['gitops-rows-main', [], 0], { coverageStatus: 'complete', rows: [normalizeArgoApplication(replacement)] })
|
|
310
|
+
})
|
|
311
|
+
await settle()
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
it('uses replacement table rows for untouched sync policy and request context after refetch', async () => {
|
|
315
|
+
await advertise({ argoRollbackSync: true })
|
|
316
|
+
await renderView('/gitops')
|
|
317
|
+
await click(button('Open sync'))
|
|
318
|
+
await replaceTableApplication(['Replace=true', 'FailOnSharedResource=true'])
|
|
319
|
+
expect(toggle('Replace').checked).toBe(true)
|
|
320
|
+
expect(toggle('Server-side apply').checked).toBe(false)
|
|
321
|
+
expect(document.body.textContent).not.toContain(STALE_OPTIONS_NOTICE)
|
|
322
|
+
await click(button('Sync now'))
|
|
323
|
+
expect(requests[0].body.syncOptions).toEqual(['Replace=true', 'FailOnSharedResource=true'])
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('shows the stale-options notice for edited sync options after replacement-row refetch', async () => {
|
|
327
|
+
await advertise({ argoRollbackSync: true, argoSyncInheritance: true })
|
|
328
|
+
await renderView('/gitops')
|
|
329
|
+
await click(button('Open sync'))
|
|
330
|
+
await click(toggle('Replace'))
|
|
331
|
+
await replaceTableApplication(['PruneLast=true'])
|
|
332
|
+
expect(document.body.textContent).toContain(STALE_OPTIONS_NOTICE)
|
|
333
|
+
expect(toggle('Server-side apply').checked).toBe(true)
|
|
334
|
+
await click(button('Sync now'))
|
|
335
|
+
expect(requests[0].body.syncOptions).toEqual(['CreateNamespace=true', 'Replace=true', 'ServerSideApply=true'])
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('closes the table sync dialog when its selected row disappears and keeps it closed if the row returns', async () => {
|
|
339
|
+
await renderView('/gitops')
|
|
340
|
+
await click(button('Open sync'))
|
|
341
|
+
expect(document.querySelector('[role="dialog"]')).not.toBeNull()
|
|
342
|
+
await act(async () => {
|
|
343
|
+
client.setQueryData(['gitops-rows-main', [], 0], { coverageStatus: 'complete', rows: [] })
|
|
344
|
+
})
|
|
345
|
+
await settle()
|
|
346
|
+
await replaceTableApplication(APP_OPTIONS)
|
|
347
|
+
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 250)) })
|
|
348
|
+
expect(document.querySelector('[role="dialog"]')).toBeNull()
|
|
349
|
+
expect(requests).toHaveLength(0)
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('refreshes auto-sync status in the table sync dialog', async () => {
|
|
353
|
+
await renderView('/gitops')
|
|
354
|
+
await click(button('Open sync'))
|
|
355
|
+
const revision = document.querySelector('input:not([type="checkbox"])') as HTMLInputElement
|
|
356
|
+
expect(revision.disabled).toBe(false)
|
|
357
|
+
await replaceTableApplication(APP_OPTIONS, true)
|
|
358
|
+
expect(revision.disabled).toBe(true)
|
|
359
|
+
expect(document.body.textContent).toContain('Turn off auto-sync to deploy another revision')
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it.each([
|
|
363
|
+
{ label: 'starts self-heal off', features: { argoRollbackSync: true, argoSyncInheritance: true, argoEnableSelfHealOff: true }, expected: { prune: false, selfHeal: false } },
|
|
364
|
+
{ label: 'still starts self-heal on', features: { argoRollbackSync: true, argoSyncInheritance: true, argoEnableSelfHealOff: false }, expected: { prune: false, selfHeal: true } },
|
|
365
|
+
])('predicts what a first-time Enable auto-sync turns on for a Radar that $label', async ({ features, expected }) => {
|
|
366
|
+
await advertise(features)
|
|
367
|
+
const settings = document.querySelector('[data-resume-settings]')!.getAttribute('data-resume-settings')!
|
|
368
|
+
expect(JSON.parse(settings)).toEqual(expected)
|
|
369
|
+
})
|