Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @vitest-environment jsdom
import { act } from 'react'
import { createRoot } from 'react-dom/client'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { PodRenderer } from './PodRenderer'

const data = {
metadata: { name: 'worker', namespace: 'app' },
spec: { containers: [], priority: 1000, priorityClassName: 'urgent', runtimeClassName: 'sandbox' },
status: { phase: 'Pending' },
}

describe('PodRenderer class references', () => {
it('links explicit class names with their API groups and cluster scope', async () => {
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
const container = document.createElement('div')
const root = createRoot(container)
const onNavigate = vi.fn()
try {
await act(async () => root.render(<PodRenderer data={data} onCopy={() => {}} copied={null} onNavigate={onNavigate} />))
for (const [name, kind, group] of [
['urgent', 'priorityclasses', 'scheduling.k8s.io'],
['sandbox', 'runtimeclasses', 'node.k8s.io'],
]) {
const button = [...container.querySelectorAll('button')].find(button => button.textContent === name)
expect(button).toBeDefined()
await act(async () => button!.click())
expect(onNavigate).toHaveBeenLastCalledWith({ kind, group, namespace: '', name })
}
} finally {
await act(async () => root.unmount())
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: false })
}
})

it('does not infer a class from numeric priority alone', () => {
const html = renderToStaticMarkup(<PodRenderer data={{ ...data, spec: { containers: [], priority: 1000 } }} onCopy={() => {}} copied={null} />)
expect(html).not.toContain('Priority Class')
expect(html).not.toContain('Runtime Class')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ export function PodRenderer({
<Property label="Node" value={
data.spec?.nodeName ? <ResourceLink name={data.spec.nodeName} kind="nodes" onNavigate={onNavigate} /> : undefined
} copyable onCopy={onCopy} copied={copied} />
{data.spec?.priorityClassName && <Property label="Priority Class" value={
<ResourceLink name={data.spec.priorityClassName} kind="priorityclasses" group="scheduling.k8s.io" onNavigate={onNavigate} />
} />}
{data.spec?.runtimeClassName && <Property label="Runtime Class" value={
<ResourceLink name={data.spec.runtimeClassName} kind="runtimeclasses" group="node.k8s.io" onNavigate={onNavigate} />
} />}
<Property label="Pod IP" value={data.status?.podIP} copyable onCopy={onCopy} copied={copied} />
<Property label="Host IP" value={data.status?.hostIP} />
<Property
Expand Down
Loading