From c8c258b95886d3b2bc9c7ecaebcad121543461ae Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Tue, 23 Aug 2022 09:52:10 -0400 Subject: [PATCH] feat(targets): include target ID in dropdown --- src/app/Shared/Services/Target.service.tsx | 1 + src/app/TargetSelect/TargetSelect.tsx | 4 +- src/test/Targets/TargetSelect.test.tsx | 43 +++++++++++----------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/app/Shared/Services/Target.service.tsx b/src/app/Shared/Services/Target.service.tsx index 9a161e9523..92a3fc3495 100644 --- a/src/app/Shared/Services/Target.service.tsx +++ b/src/app/Shared/Services/Target.service.tsx @@ -40,6 +40,7 @@ import { Observable, Subject, BehaviorSubject } from 'rxjs'; export const NO_TARGET = {} as Target; export interface Target { + id?: string; // present in responses, but we do not need to provide it in requests connectUrl: string; alias: string; labels?: Map; diff --git a/src/app/TargetSelect/TargetSelect.tsx b/src/app/TargetSelect/TargetSelect.tsx index 3f15aa9c02..287b626686 100644 --- a/src/app/TargetSelect/TargetSelect.tsx +++ b/src/app/TargetSelect/TargetSelect.tsx @@ -261,13 +261,13 @@ export const TargetSelect: React.FunctionComponent = (props) key={t.connectUrl} value={t} isPlaceholder={false} - >{`${t.connectUrl}`} + >{`${t.connectUrl}: ${t.id}`} : {`${t.alias} (${t.connectUrl})`} + >{`${t.alias} (${t.connectUrl}): ${t.id}`} )) ) } diff --git a/src/test/Targets/TargetSelect.test.tsx b/src/test/Targets/TargetSelect.test.tsx index 934ddb7b82..32f077184a 100644 --- a/src/test/Targets/TargetSelect.test.tsx +++ b/src/test/Targets/TargetSelect.test.tsx @@ -1,8 +1,8 @@ /* * Copyright The Cryostat Authors - * + * * The Universal Permissive License (UPL), Version 1.0 - * + * * Subject to the condition set forth below, permission is hereby granted to any * person obtaining a copy of this software, associated documentation and/or data * (collectively the "Software"), free of charge and under any and all copyright @@ -10,23 +10,23 @@ * licensable by each licensor hereunder covering either (i) the unmodified * Software as contributed to or provided by such licensor, or (ii) the Larger * Works (as defined below), to deal in both - * + * * (a) the Software, and * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if * one is included with the Software (each a "Larger Work" to which the Software * is contributed by such licensors), - * + * * without restriction, including without limitation the rights to copy, create * derivative works of, display, perform, and distribute the Software and make, * use, sell, offer for sale, import, export, have made, and have sold the * Software and the Larger Work(s), and to sublicense the foregoing rights on * either these or other terms. - * + * * This license is subject to the following condition: * The above copyright notice and either this complete permission notice or at * a minimum a reference to the UPL must be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -54,15 +54,16 @@ const mockBazConnectUrl = 'service:jmx:rmi://someBazUrl'; // Test fails if new Map([['REALM', 'Custom Targets']]) is used, most likely since 'cryostat' Map is not being utilized const cryostatAnnotation = new Map(); cryostatAnnotation['REALM'] = CUSTOM_TARGETS_REALM; -const mockFooTarget: Target = { - connectUrl: mockFooConnectUrl, - alias: 'fooTarget', - annotations: { - cryostat: cryostatAnnotation, - platform : new Map() +const mockFooTarget: Target = { + id: 'abcd', + connectUrl: mockFooConnectUrl, + alias: 'fooTarget', + annotations: { + cryostat: cryostatAnnotation, + platform : new Map() } }; -const mockBarTarget: Target = { ...mockFooTarget, connectUrl: mockBarConnectUrl, alias: 'barTarget' } +const mockBarTarget: Target = { ...mockFooTarget, id: 'efgh', connectUrl: mockBarConnectUrl, alias: 'barTarget' } const mockBazTarget: Target = { connectUrl: mockBazConnectUrl, alias: 'bazTarget' } jest.mock('react-router-dom', () => ({ @@ -103,7 +104,7 @@ afterEach(cleanup); describe('', () => { it('renders correctly', () => { - const tree = renderer.create( + const tree = renderer.create( ); @@ -135,12 +136,12 @@ describe('', () => { ); expect(screen.getByText(`fooTarget`)).toBeInTheDocument(); - + userEvent.click(screen.getByLabelText("Options menu")); expect(screen.getByLabelText('Select Input')).toBeInTheDocument(); expect(screen.getByText(`Select Target...`)).toBeInTheDocument(); - expect(screen.getByText(`fooTarget (service:jmx:rmi://someFooUrl)`)).toBeInTheDocument(); - expect(screen.getByText(`barTarget (service:jmx:rmi://someBarUrl)`)).toBeInTheDocument(); + expect(screen.getByText(`fooTarget (service:jmx:rmi://someFooUrl): abcd`)).toBeInTheDocument(); + expect(screen.getByText(`barTarget (service:jmx:rmi://someBarUrl): efgh`)).toBeInTheDocument(); expect(screen.getByText('2')).toBeInTheDocument(); // Number of discoverable targets }); @@ -163,7 +164,7 @@ describe('', () => { expect(createTargetRequestSpy).toBeCalledTimes(1); expect(createTargetRequestSpy).toBeCalledWith(mockBazTarget); - }); + }); it('deletes target when delete button clicked', async () => { render( @@ -180,7 +181,7 @@ describe('', () => { const deleteTargetRequestSpy = jest.spyOn(defaultServices.api, 'deleteTarget'); expect(deleteTargetRequestSpy).toBeCalledTimes(1); expect(deleteTargetRequestSpy).toBeCalledWith(mockFooTarget); - }); + }); it('does nothing when trying to delete non-custom targets', () => { render( @@ -195,7 +196,7 @@ describe('', () => { expect(deleteTargetRequestSpy).toBeCalledTimes(0); expect(deleteButton).toBeDisabled(); - }); + }); it('refreshes targets when button clicked', () => { render( @@ -208,5 +209,5 @@ describe('', () => { const refreshTargetsRequestSpy = jest.spyOn(defaultServices.targets, 'queryForTargets'); expect(refreshTargetsRequestSpy).toBeCalledTimes(1); - }); + }); });