Skip to content

Commit

Permalink
feat(targets): include target ID in dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Aug 23, 2022
1 parent e871759 commit b731bc1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/app/Shared/Services/Target.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
Expand Down
4 changes: 2 additions & 2 deletions src/app/TargetSelect/TargetSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ export const TargetSelect: React.FunctionComponent<TargetSelectProps> = (props)
key={t.connectUrl}
value={t}
isPlaceholder={false}
>{`${t.connectUrl}`}</SelectOption>
>{`${t.connectUrl}: ${t.id}`}</SelectOption>
:
<SelectOption
key={t.connectUrl}
value={t}
isPlaceholder={false}
>{`${t.alias} (${t.connectUrl})`}</SelectOption>
>{`${t.alias} (${t.connectUrl}): ${t.id}`}</SelectOption>
))
)
}
Expand Down
30 changes: 15 additions & 15 deletions src/test/Targets/TargetSelect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
* 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
* rights in the Software, and any and all patent rights owned or freely
* 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
Expand All @@ -51,8 +51,8 @@ import { NotificationMessage } from '@app/Shared/Services/NotificationChannel.se
const mockFooConnectUrl = 'service:jmx:rmi://someFooUrl';
const mockBarConnectUrl = 'service:jmx:rmi://someBarUrl';
const mockBazConnectUrl = 'service:jmx:rmi://someBazUrl';
const mockFooTarget = { connectUrl: mockFooConnectUrl, alias: 'fooTarget' };
const mockBarTarget = { connectUrl: mockBarConnectUrl, alias: 'barTarget' }
const mockFooTarget = { id: 'abcd', connectUrl: mockFooConnectUrl, alias: 'fooTarget' };
const mockBarTarget = { id: 'efgh', connectUrl: mockBarConnectUrl, alias: 'barTarget' }
const mockBazTarget = { connectUrl: mockBazConnectUrl, alias: 'bazTarget' }

const mockHistoryPush = jest.fn();
Expand Down Expand Up @@ -92,7 +92,7 @@ jest.spyOn(defaultServices.notificationChannel, 'messages')

describe('<TargetSelect />', () => {
it('renders correctly', () => {
const tree = renderer.create(
const tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<TargetSelect />
</ServiceContext.Provider>);
Expand Down Expand Up @@ -124,12 +124,12 @@ describe('<TargetSelect />', () => {
);

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
});

Expand All @@ -152,7 +152,7 @@ describe('<TargetSelect />', () => {

expect(createTargetRequestSpy).toBeCalledTimes(1);
expect(createTargetRequestSpy).toBeCalledWith(mockBazTarget);
});
});

it('deletes target when delete button clicked', () => {
render(
Expand All @@ -166,7 +166,7 @@ describe('<TargetSelect />', () => {
const deleteTargetRequestSpy = jest.spyOn(defaultServices.api, 'deleteTarget');
expect(deleteTargetRequestSpy).toBeCalledTimes(1);
expect(deleteTargetRequestSpy).toBeCalledWith(mockFooTarget);
});
});

it('refreshes targets when button clicked', () => {
render(
Expand All @@ -179,5 +179,5 @@ describe('<TargetSelect />', () => {

const refreshTargetsRequestSpy = jest.spyOn(defaultServices.targets, 'queryForTargets');
expect(refreshTargetsRequestSpy).toBeCalledTimes(1);
});
});
});

0 comments on commit b731bc1

Please sign in to comment.