@skyhook-io/radar-app 1.22.2 → 1.23.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/package.json +8 -8
- package/src/App.tsx +35 -10
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +122 -24
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +13 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +315 -0
- package/src/api/workloadSource.ts +128 -12
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +127 -32
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +3 -3
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +4 -4
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +2 -6
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +52 -13
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, type ReactNode } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { ShareLinkButton } from './ShareLinkButton'
|
|
7
|
+
import { resetCloudShareHiddenForTests } from './shareLink'
|
|
8
|
+
|
|
9
|
+
const state = vi.hoisted(() => ({
|
|
10
|
+
capabilities: undefined as Record<string, unknown> | undefined,
|
|
11
|
+
embedded: false,
|
|
12
|
+
connected: [] as { clusterUrl?: string }[],
|
|
13
|
+
pending: false,
|
|
14
|
+
fetching: false,
|
|
15
|
+
desktop: false,
|
|
16
|
+
discoverError: false,
|
|
17
|
+
partialScan: false,
|
|
18
|
+
discoverEnabled: [] as boolean[],
|
|
19
|
+
copyOk: true,
|
|
20
|
+
}))
|
|
21
|
+
const copyText = vi.hoisted(() => vi.fn(async () => state.copyOk))
|
|
22
|
+
const openShareInCloud = vi.hoisted(() => vi.fn())
|
|
23
|
+
const recordUsageEvent = vi.hoisted(() => vi.fn())
|
|
24
|
+
|
|
25
|
+
vi.mock('../../api/client', () => ({
|
|
26
|
+
useCapabilities: () => ({ data: state.capabilities }),
|
|
27
|
+
useClusterInfo: () => ({ data: { context: 'kind-test' } }),
|
|
28
|
+
useCloudInstallDiscover: (enabled: boolean) => {
|
|
29
|
+
state.discoverEnabled.push(enabled)
|
|
30
|
+
const pending = enabled && state.pending
|
|
31
|
+
return { data: enabled && !pending && !state.discoverError ? { connected: state.connected, partialScan: state.partialScan } : undefined, isError: enabled && state.discoverError, isPending: pending, isFetching: enabled && (pending || state.fetching) }
|
|
32
|
+
},
|
|
33
|
+
}))
|
|
34
|
+
vi.mock('../../api/usage-data', () => ({ recordUsageEvent }))
|
|
35
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { state: 'connected' } }) }))
|
|
36
|
+
vi.mock('../../context/NavCustomization', () => ({ useNavCustomization: () => ({ embedded: state.embedded }) }))
|
|
37
|
+
vi.mock('../ui/Tooltip', () => ({ Tooltip: ({ children }: { children: ReactNode }) => children }))
|
|
38
|
+
vi.mock('@skyhook-io/k8s-ui/utils/clipboard', () => ({ copyText }))
|
|
39
|
+
vi.mock('./openShareInCloud', () => ({ openShareInCloud }))
|
|
40
|
+
const openExternal = vi.hoisted(() => vi.fn())
|
|
41
|
+
vi.mock('../../utils/navigation', () => ({ openExternal }))
|
|
42
|
+
let desktopAnswer: Promise<boolean> | null = null
|
|
43
|
+
vi.mock('../../utils/desktop-download', () => ({ isDesktopApp: () => desktopAnswer ?? Promise.resolve(state.desktop) }))
|
|
44
|
+
|
|
45
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
46
|
+
|
|
47
|
+
const LOCAL = { cloudConnect: { lane: 'driver', appUrl: 'https://cloud.example' }, deployment: { mode: 'local' } }
|
|
48
|
+
const SUBJECT = { kind: 'pods', namespace: 'shop', name: 'checkout-0' }
|
|
49
|
+
const PATH = '/resources/pods?namespaces=shop&resource=shop%2Fcheckout-0'
|
|
50
|
+
|
|
51
|
+
let root: Root
|
|
52
|
+
let container: HTMLDivElement
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
state.capabilities = LOCAL
|
|
56
|
+
state.embedded = false
|
|
57
|
+
state.connected = []
|
|
58
|
+
state.pending = false
|
|
59
|
+
state.fetching = false
|
|
60
|
+
state.desktop = false
|
|
61
|
+
desktopAnswer = null
|
|
62
|
+
state.discoverError = false
|
|
63
|
+
state.partialScan = false
|
|
64
|
+
openExternal.mockClear()
|
|
65
|
+
state.discoverEnabled = []
|
|
66
|
+
state.copyOk = true
|
|
67
|
+
copyText.mockClear()
|
|
68
|
+
openShareInCloud.mockClear()
|
|
69
|
+
recordUsageEvent.mockClear()
|
|
70
|
+
window.localStorage.clear()
|
|
71
|
+
resetCloudShareHiddenForTests()
|
|
72
|
+
container = document.createElement('div')
|
|
73
|
+
document.body.appendChild(container)
|
|
74
|
+
root = createRoot(container)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
act(() => root.unmount())
|
|
79
|
+
container.remove()
|
|
80
|
+
vi.restoreAllMocks()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
function render(path = PATH) {
|
|
84
|
+
act(() => {
|
|
85
|
+
root.render(
|
|
86
|
+
<MemoryRouter>
|
|
87
|
+
<ShareLinkButton path={path} subject={SUBJECT} />
|
|
88
|
+
</MemoryRouter>,
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function trigger(): HTMLButtonElement {
|
|
94
|
+
return container.querySelector('button')!
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function click(el: Element) {
|
|
98
|
+
await act(async () => {
|
|
99
|
+
;(el as HTMLElement).click()
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function menu(): HTMLElement | null {
|
|
104
|
+
return document.body.querySelector('[role="dialog"]')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function item(text: string): HTMLElement {
|
|
108
|
+
const found = Array.from(document.body.querySelectorAll<HTMLElement>('[role="menuitem"]')).find((el) => el.textContent?.includes(text))
|
|
109
|
+
if (!found) throw new Error(`No menu item "${text}"`)
|
|
110
|
+
return found
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const ABSOLUTE = `${window.location.origin}${PATH}`
|
|
114
|
+
|
|
115
|
+
describe('ShareLinkButton', () => {
|
|
116
|
+
it('copies at once, then says the link is local and offers Radar Cloud', async () => {
|
|
117
|
+
render()
|
|
118
|
+
expect(trigger().getAttribute('aria-label')).toBe('Copy link')
|
|
119
|
+
expect(menu()).toBeNull()
|
|
120
|
+
await click(trigger())
|
|
121
|
+
expect(copyText).toHaveBeenCalledWith(ABSOLUTE)
|
|
122
|
+
expect(recordUsageEvent).toHaveBeenCalledWith({ type: 'ui', name: 'share:copy-link' })
|
|
123
|
+
expect(menu()?.textContent).toContain('Local link copied')
|
|
124
|
+
expect(menu()?.textContent).toContain(`Works on this computer only (${window.location.host})`)
|
|
125
|
+
expect(menu()?.textContent).toContain('Get a team link')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('copies once while a copy is still finishing, and uses one offer for it', async () => {
|
|
129
|
+
let finish!: (ok: boolean) => void
|
|
130
|
+
copyText.mockImplementationOnce(() => new Promise<boolean>((r) => { finish = r }))
|
|
131
|
+
render()
|
|
132
|
+
await click(trigger())
|
|
133
|
+
await click(trigger())
|
|
134
|
+
await act(async () => finish(true))
|
|
135
|
+
expect(copyText).toHaveBeenCalledTimes(1)
|
|
136
|
+
expect(window.localStorage.getItem('radar.share.cloudOption.shown')).toBe('1')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('uses no offer when the control is gone before the copy finishes', async () => {
|
|
140
|
+
let finish!: (ok: boolean) => void
|
|
141
|
+
copyText.mockImplementationOnce(() => new Promise<boolean>((r) => { finish = r }))
|
|
142
|
+
render()
|
|
143
|
+
await click(trigger())
|
|
144
|
+
act(() => root.unmount())
|
|
145
|
+
root = createRoot(container)
|
|
146
|
+
await act(async () => finish(true))
|
|
147
|
+
expect(window.localStorage.getItem('radar.share.cloudOption.shown')).toBeNull()
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('puts focus inside the popup while the Radar Cloud item is still checking', async () => {
|
|
151
|
+
state.pending = true
|
|
152
|
+
render()
|
|
153
|
+
await click(trigger())
|
|
154
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 50)) })
|
|
155
|
+
expect(menu()?.contains(document.activeElement)).toBe(true)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('offers Radar Cloud with the first three copies only', async () => {
|
|
159
|
+
render()
|
|
160
|
+
for (let i = 0; i < 3; i++) {
|
|
161
|
+
await click(trigger())
|
|
162
|
+
expect(menu()?.textContent).toContain('Get a team link')
|
|
163
|
+
await click(trigger())
|
|
164
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 300)) })
|
|
165
|
+
}
|
|
166
|
+
await click(trigger())
|
|
167
|
+
expect(copyText).toHaveBeenCalledTimes(4)
|
|
168
|
+
expect(menu()).toBeNull()
|
|
169
|
+
expect(container.textContent).toContain('Link copied')
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('moves focus into the popup once it opens, and Escape returns it without closing what is underneath', async () => {
|
|
173
|
+
const onOuterKey = vi.fn()
|
|
174
|
+
document.addEventListener('keydown', onOuterKey)
|
|
175
|
+
render()
|
|
176
|
+
await click(trigger())
|
|
177
|
+
await act(async () => {
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
179
|
+
})
|
|
180
|
+
expect(document.activeElement).toBe(item('Get a team link'))
|
|
181
|
+
await act(async () => {
|
|
182
|
+
document.activeElement!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
|
183
|
+
})
|
|
184
|
+
expect(onOuterKey).not.toHaveBeenCalled()
|
|
185
|
+
expect(document.activeElement).toBe(trigger())
|
|
186
|
+
document.removeEventListener('keydown', onOuterKey)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('opens the Radar Cloud dialog with what was being shared', async () => {
|
|
190
|
+
render()
|
|
191
|
+
await click(trigger())
|
|
192
|
+
await click(item('Get a team link'))
|
|
193
|
+
expect(openShareInCloud).toHaveBeenCalledWith(SUBJECT, 'kind-test')
|
|
194
|
+
expect(recordUsageEvent).toHaveBeenCalledWith({ type: 'ui', name: 'share:cloud' })
|
|
195
|
+
// The local link was already copied by the first click.
|
|
196
|
+
expect(copyText).toHaveBeenCalledTimes(1)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('opens this view in Radar Cloud when the cluster is already connected', async () => {
|
|
200
|
+
state.connected = [{ clusterUrl: 'https://cloud.example/c/abc' }]
|
|
201
|
+
render()
|
|
202
|
+
await click(trigger())
|
|
203
|
+
const link = item('Open in Radar Cloud') as HTMLAnchorElement
|
|
204
|
+
expect(link.getAttribute('href')).toBe('https://cloud.example/c/abc/resources/pods?namespaces=shop&resource=shop%2Fcheckout-0')
|
|
205
|
+
expect(link.getAttribute('target')).toBe('_blank')
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('holds the Radar Cloud item still while the lookup runs', async () => {
|
|
209
|
+
state.pending = true
|
|
210
|
+
render()
|
|
211
|
+
await click(trigger())
|
|
212
|
+
expect(menu()?.textContent).toContain('Checking whether this cluster is connected')
|
|
213
|
+
expect(menu()?.textContent).not.toContain('Get a team link')
|
|
214
|
+
expect(menu()?.textContent).not.toContain('Open in Radar Cloud')
|
|
215
|
+
await click(item('Checking whether this cluster is connected'))
|
|
216
|
+
expect(openShareInCloud).not.toHaveBeenCalled()
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('holds the item still while a cached answer is checked again', async () => {
|
|
220
|
+
state.connected = [{ clusterUrl: 'https://cloud.example/c/abc' }]
|
|
221
|
+
state.fetching = true
|
|
222
|
+
render()
|
|
223
|
+
await click(trigger())
|
|
224
|
+
expect(menu()?.textContent).toContain('Checking whether this cluster is connected')
|
|
225
|
+
expect(menu()?.querySelector('a[href^="https://cloud.example"]')).toBeNull()
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('holds the item until Radar knows whether it runs in the desktop app', async () => {
|
|
229
|
+
let answer!: (d: boolean) => void
|
|
230
|
+
desktopAnswer = new Promise<boolean>((r) => { answer = r })
|
|
231
|
+
state.connected = [{ clusterUrl: 'https://cloud.example/c/abc' }]
|
|
232
|
+
render()
|
|
233
|
+
await click(trigger())
|
|
234
|
+
expect(menu()?.textContent).toContain('Checking whether this cluster is connected')
|
|
235
|
+
await act(async () => { answer(false) })
|
|
236
|
+
expect(item('Open in Radar Cloud')).toBeTruthy()
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
it('opens Radar Cloud in the system browser from the desktop app', async () => {
|
|
240
|
+
state.desktop = true
|
|
241
|
+
state.connected = [{ clusterUrl: 'https://cloud.example/c/abc' }]
|
|
242
|
+
render()
|
|
243
|
+
await click(trigger())
|
|
244
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 0)) })
|
|
245
|
+
await click(item('Open in Radar Cloud'))
|
|
246
|
+
expect(openExternal).toHaveBeenCalledWith('https://cloud.example/c/abc/resources/pods?namespaces=shop&resource=shop%2Fcheckout-0')
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it('does not ask to connect when the lookup failed or could not see the whole cluster', async () => {
|
|
250
|
+
for (const setup of [() => { state.discoverError = true }, () => { state.partialScan = true }]) {
|
|
251
|
+
state.discoverError = false
|
|
252
|
+
state.partialScan = false
|
|
253
|
+
setup()
|
|
254
|
+
render()
|
|
255
|
+
await click(trigger())
|
|
256
|
+
expect(menu()?.textContent).not.toContain('Connect this cluster')
|
|
257
|
+
expect(menu()?.textContent).toContain('Share with Radar Cloud')
|
|
258
|
+
await click(item('Share with Radar Cloud'))
|
|
259
|
+
expect(openShareInCloud).toHaveBeenLastCalledWith(SUBJECT, 'kind-test')
|
|
260
|
+
act(() => root.unmount())
|
|
261
|
+
root = createRoot(container)
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('does not ask a connected cluster without a page link to connect', async () => {
|
|
266
|
+
state.connected = [{}]
|
|
267
|
+
render()
|
|
268
|
+
await click(trigger())
|
|
269
|
+
expect(menu()?.textContent).not.toContain('Connect this cluster')
|
|
270
|
+
await click(item('Share from Radar Cloud'))
|
|
271
|
+
expect(openShareInCloud).toHaveBeenCalledWith(SUBJECT, 'kind-test')
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('asks whether the cluster is connected only once the menu is open', async () => {
|
|
275
|
+
render()
|
|
276
|
+
expect(state.discoverEnabled.every((enabled) => !enabled)).toBe(true)
|
|
277
|
+
await click(trigger())
|
|
278
|
+
expect(state.discoverEnabled.at(-1)).toBe(true)
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it.each([
|
|
282
|
+
['a shared install', { cloudConnect: { lane: 'wizard', appUrl: 'https://cloud.example' }, deployment: { mode: 'in-cluster' } }, false],
|
|
283
|
+
['Radar Cloud turned off', { deployment: { mode: 'local' } }, false],
|
|
284
|
+
['capabilities still loading', undefined, false],
|
|
285
|
+
['an embedding host', LOCAL, true],
|
|
286
|
+
])('copies in one click with no menu for %s', async (_case, capabilities, embedded) => {
|
|
287
|
+
state.capabilities = capabilities
|
|
288
|
+
state.embedded = embedded
|
|
289
|
+
render()
|
|
290
|
+
expect(trigger().getAttribute('aria-label')).toBe('Copy link')
|
|
291
|
+
expect(trigger().hasAttribute('aria-haspopup')).toBe(false)
|
|
292
|
+
await click(trigger())
|
|
293
|
+
expect(copyText).toHaveBeenCalledWith(ABSOLUTE)
|
|
294
|
+
expect(menu()).toBeNull()
|
|
295
|
+
expect(container.textContent).toContain('Link copied')
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('hides Radar Cloud for good', async () => {
|
|
299
|
+
render()
|
|
300
|
+
await click(trigger())
|
|
301
|
+
await click(document.body.querySelector('[aria-label="Don\'t show Radar Cloud here again"]')!)
|
|
302
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 300)) })
|
|
303
|
+
expect(menu()).toBeNull()
|
|
304
|
+
expect(window.localStorage.getItem('radar.share.cloudOption.hidden')).toBe('true')
|
|
305
|
+
|
|
306
|
+
act(() => root.unmount())
|
|
307
|
+
root = createRoot(container)
|
|
308
|
+
resetCloudShareHiddenForTests()
|
|
309
|
+
render()
|
|
310
|
+
expect(trigger().getAttribute('aria-label')).toBe('Copy link')
|
|
311
|
+
await click(trigger())
|
|
312
|
+
expect(menu()).toBeNull()
|
|
313
|
+
expect(copyText).toHaveBeenCalledWith(ABSOLUTE)
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
it('keeps Radar Cloud hidden for the page when storage is blocked', async () => {
|
|
317
|
+
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
|
318
|
+
throw new Error('SecurityError')
|
|
319
|
+
})
|
|
320
|
+
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
|
321
|
+
throw new Error('SecurityError')
|
|
322
|
+
})
|
|
323
|
+
render()
|
|
324
|
+
await click(trigger())
|
|
325
|
+
await click(document.body.querySelector('[aria-label="Don\'t show Radar Cloud here again"]')!)
|
|
326
|
+
await act(async () => { await new Promise((r) => setTimeout(r, 300)) })
|
|
327
|
+
expect(menu()).toBeNull()
|
|
328
|
+
|
|
329
|
+
act(() => root.unmount())
|
|
330
|
+
root = createRoot(container)
|
|
331
|
+
render()
|
|
332
|
+
expect(trigger().getAttribute('aria-label')).toBe('Copy link')
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
it('shows the link to copy by hand when the browser refuses the clipboard', async () => {
|
|
336
|
+
state.capabilities = { deployment: { mode: 'in-cluster' } }
|
|
337
|
+
state.copyOk = false
|
|
338
|
+
render()
|
|
339
|
+
await click(trigger())
|
|
340
|
+
const input = document.body.querySelector<HTMLInputElement>('[role="dialog"] input')
|
|
341
|
+
expect(input?.value).toBe(ABSOLUTE)
|
|
342
|
+
expect(recordUsageEvent).not.toHaveBeenCalled()
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it('does not toggle a parent row when clicked', async () => {
|
|
346
|
+
const onRowClick = vi.fn()
|
|
347
|
+
act(() => {
|
|
348
|
+
root.render(
|
|
349
|
+
<MemoryRouter>
|
|
350
|
+
<div onClick={onRowClick}>
|
|
351
|
+
<ShareLinkButton path={PATH} subject={SUBJECT} />
|
|
352
|
+
</div>
|
|
353
|
+
</MemoryRouter>,
|
|
354
|
+
)
|
|
355
|
+
})
|
|
356
|
+
await click(trigger())
|
|
357
|
+
await click(item('Get a team link'))
|
|
358
|
+
expect(onRowClick).not.toHaveBeenCalled()
|
|
359
|
+
})
|
|
360
|
+
})
|