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
8 changes: 4 additions & 4 deletions javascript/grid-ui/src/screens/Overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Overview (): JSX.Element {
pollInterval: GridConfig.status.xhrPollingIntervalMillis,
fetchPolicy: 'network-only'
})

const { data: sessionsData } = useQuery(GRID_SESSIONS_QUERY, {
pollInterval: GridConfig.status.xhrPollingIntervalMillis,
fetchPolicy: 'network-only'
Expand Down Expand Up @@ -190,7 +190,7 @@ function Overview (): JSX.Element {
<Select value={sortOption} onChange={handleSortChange}
label="Sort By" style={{ minWidth: '170px' }}>
{Object.keys(sortProperties).map((key) => (
<MenuItem value={key}>
<MenuItem key={key} value={key}>
{sortPropertiesLabel[key]}
</MenuItem>
))}
Expand Down Expand Up @@ -223,8 +223,8 @@ function Overview (): JSX.Element {
flexDirection: 'column'
}}
>
<Node
node={node}
<Node
node={node}
sessions={sessionsData?.sessionsInfo?.sessions?.filter(
session => session.nodeId === node.id
) || []}
Expand Down
38 changes: 18 additions & 20 deletions javascript/grid-ui/src/tests/components/Node.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const sessionWithVnc = {
capabilities: JSON.stringify({
'browserName': 'chrome',
'browserVersion': '88.0',
'se:vnc': 'ws://192.168.1.7:5900/websockify'
'se:vnc': 'ws://172.17.0.2:4444/session/4d31d065-6cb9-4545-ac8d-d70ed5f5168b/se/vnc'
}),
nodeId: node.id
}
Expand Down Expand Up @@ -116,10 +116,10 @@ describe('Node component', () => {

it('opens live view dialog when camera icon is clicked', async () => {
render(<Node node={node} sessions={[sessionWithVnc]} origin="http://localhost:4444" />)

const user = userEvent.setup()
await user.click(screen.getByTestId('VideocamIcon'))

expect(screen.getByText('Node Session Live View')).toBeInTheDocument()
const dialogTitle = screen.getByText('Node Session Live View')
const dialog = dialogTitle.closest('.MuiDialog-root')
Expand All @@ -132,42 +132,40 @@ describe('Node component', () => {

it('closes live view dialog when close button is clicked', async () => {
render(<Node node={node} sessions={[sessionWithVnc]} origin="http://localhost:4444" />)

const user = userEvent.setup()
await user.click(screen.getByTestId('VideocamIcon'))

expect(screen.getByText('Node Session Live View')).toBeInTheDocument()

await user.click(screen.getByRole('button', { name: /close/i }))

expect(screen.queryByText('Node Session Live View')).not.toBeInTheDocument()
})

it('correctly transforms VNC URL for WebSocket connection', async () => {
const origin = 'https://grid.example.com'
render(<Node node={node} sessions={[sessionWithVnc]} origin={origin} />)

const user = userEvent.setup()
await user.click(screen.getByTestId('VideocamIcon'))

const liveView = screen.getByTestId('mock-live-view')
const url = liveView.getAttribute('data-url')

expect(url).toContain('wss:')
expect(url).toContain('grid.example.com')
expect(url).toContain('/websockify')

expect(url).toBe('wss://grid.example.com/session/4d31d065-6cb9-4545-ac8d-d70ed5f5168b/se/vnc')
})

it('handles HTTP to WS protocol conversion correctly', async () => {
const httpOrigin = 'http://grid.example.com'
render(<Node node={node} sessions={[sessionWithVnc]} origin={httpOrigin} />)

const user = userEvent.setup()
await user.click(screen.getByTestId('VideocamIcon'))

const liveView = screen.getByTestId('mock-live-view')
const url = liveView.getAttribute('data-url')

expect(url).toContain('ws:')
expect(url).not.toContain('wss:')
})
Expand All @@ -182,15 +180,15 @@ describe('Node component', () => {
}),
nodeId: node.id
}

render(<Node node={node} sessions={[invalidVncSession]} origin="http://localhost:4444" />)

const user = userEvent.setup()
await user.click(screen.getByTestId('VideocamIcon'))

const liveView = screen.getByTestId('mock-live-view')
const url = liveView.getAttribute('data-url')

expect(url).toBe('')
})
})
73 changes: 70 additions & 3 deletions javascript/grid-ui/src/tests/components/Overview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ const mockSessionsData = {
browserVersion: '88.0',
platformName: 'linux',
'se:vnc': 'ws://192.168.1.10:5900/websockify'
})
}),
startTime: '2023-01-01T00:00:00Z',
uri: 'http://192.168.1.10:4444/session/session1',
nodeUri: 'http://192.168.1.10:4444',
sessionDurationMillis: 60000,
slot: {
id: 'slot1',
stereotype: '{"browserName":"chrome"}',
lastStarted: '2023-01-01T00:00:00Z'
}
},
{
id: 'session2',
Expand All @@ -111,9 +120,19 @@ const mockSessionsData = {
browserName: 'firefox',
browserVersion: '78.0',
platformName: 'windows'
})
}),
startTime: '2023-01-01T00:00:00Z',
uri: 'http://192.168.1.11:4444/session/session2',
nodeUri: 'http://192.168.1.11:4444',
sessionDurationMillis: 60000,
slot: {
id: 'slot2',
stereotype: '{"browserName":"firefox"}',
lastStarted: '2023-01-01T00:00:00Z'
}
}
]
],
sessionQueueRequests: []
}
}

Expand All @@ -126,6 +145,22 @@ const mocks = [
data: mockNodesData
}
},
{
request: {
query: GRID_SESSIONS_QUERY
},
result: {
data: mockSessionsData
}
},
{
request: {
query: GRID_SESSIONS_QUERY
},
result: {
data: mockSessionsData
}
},
{
request: {
query: GRID_SESSIONS_QUERY
Expand Down Expand Up @@ -295,6 +330,22 @@ describe('Overview component', () => {
query: NODES_QUERY
},
error: new Error('Network error')
},
{
request: {
query: GRID_SESSIONS_QUERY
},
result: {
data: mockSessionsData
}
},
{
request: {
query: GRID_SESSIONS_QUERY
},
result: {
data: mockSessionsData
}
}
]

Expand All @@ -319,6 +370,22 @@ describe('Overview component', () => {
result: {
data: { nodesInfo: { nodes: [] } }
}
},
{
request: {
query: GRID_SESSIONS_QUERY
},
result: {
data: mockSessionsData
}
},
{
request: {
query: GRID_SESSIONS_QUERY
},
result: {
data: mockSessionsData
}
}
]

Expand Down