Skip to content

Commit 1c1db92

Browse files
authored
[grid] Add "URI" to the list of sort-by choices on Overview UI (#16004)
1 parent 7ace725 commit 1c1db92

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

javascript/grid-ui/src/screens/Overview/Overview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function Overview (): JSX.Element {
6666

6767
const sortProperties = {
6868
'platformName': (a, b) => compareSlotStereotypes(a, b, 'platformName'),
69-
'status': (a, b) => a.status.localeCompare(b.status),
69+
'status': (a, b) => (a.status ?? '').localeCompare(b.status ?? ''),
70+
'uri': (a, b) => (a.uri ?? '').localeCompare(b.uri ?? ''),
7071
'browserName': (a, b) => compareSlotStereotypes(a, b, 'browserName'),
7172
'browserVersion': (a, b) => compareSlotStereotypes(a, b, 'browserVersion'),
7273
'slotCount': (a, b) => {
@@ -80,6 +81,7 @@ function Overview (): JSX.Element {
8081
const sortPropertiesLabel = {
8182
'platformName': 'Platform Name',
8283
'status': 'Status',
84+
'uri': 'URI',
8385
'browserName': 'Browser Name',
8486
'browserVersion': 'Browser Version',
8587
'slotCount': 'Slot Count',

javascript/grid-ui/src/tests/components/Overview.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,54 @@ describe('Overview component', () => {
255255
}
256256
})
257257

258+
it('sorts nodes by URI when selected', async () => {
259+
render(
260+
<MockedProvider mocks={mocks} addTypename={false}>
261+
<Overview />
262+
</MockedProvider>
263+
)
264+
265+
await screen.findByText('http://192.168.1.10:4444')
266+
267+
const user = userEvent.setup()
268+
const selectElement = screen.getByRole('combobox')
269+
await user.click(selectElement)
270+
await user.click(screen.getByText('URI'))
271+
272+
// After sorting by URI, node1 should appear before node2
273+
const nodeUris = screen.getAllByText(/http:\/\/192\.168\.1\.\d+:4444/)
274+
expect(nodeUris[0]).toHaveTextContent('http://192.168.1.10:4444')
275+
expect(nodeUris[1]).toHaveTextContent('http://192.168.1.11:4444')
276+
})
277+
278+
it('sorts nodes by URI in descending order when selected', async () => {
279+
render(
280+
<MockedProvider mocks={mocks} addTypename={false}>
281+
<Overview />
282+
</MockedProvider>
283+
)
284+
285+
await screen.findByText('http://192.168.1.10:4444')
286+
287+
const user = userEvent.setup()
288+
const selectElement = screen.getByRole('combobox')
289+
await user.click(selectElement)
290+
await user.click(screen.getByText('URI'))
291+
292+
const descendingLabel = screen.getByText('Descending')
293+
const checkbox = descendingLabel.closest('label')?.querySelector('input[type="checkbox"]')
294+
expect(checkbox).not.toBeNull()
295+
if (checkbox) {
296+
await user.click(checkbox)
297+
expect(checkbox).toBeChecked()
298+
}
299+
300+
// After sorting by URI descending, node2 should appear before node1
301+
const nodeUris = screen.getAllByText(/http:\/\/192\.168\.1\.\d+:4444/)
302+
expect(nodeUris[0]).toHaveTextContent('http://192.168.1.11:4444')
303+
expect(nodeUris[1]).toHaveTextContent('http://192.168.1.10:4444')
304+
})
305+
258306
it('renders live view icon for node with VNC session', async () => {
259307
render(
260308
<MockedProvider mocks={mocks} addTypename={false}>

0 commit comments

Comments
 (0)