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 Sep 6, 2022
1 parent b355296 commit c8c258b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 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 @@ -261,13 +261,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
43 changes: 22 additions & 21 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 Down Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -103,7 +104,7 @@ afterEach(cleanup);

describe('<TargetSelect />', () => {
it('renders correctly', () => {
const tree = renderer.create(
const tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<TargetSelect />
</ServiceContext.Provider>);
Expand Down Expand Up @@ -135,12 +136,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 @@ -163,7 +164,7 @@ describe('<TargetSelect />', () => {

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

it('deletes target when delete button clicked', async () => {
render(
Expand All @@ -180,7 +181,7 @@ describe('<TargetSelect />', () => {
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(
Expand All @@ -195,7 +196,7 @@ describe('<TargetSelect />', () => {

expect(deleteTargetRequestSpy).toBeCalledTimes(0);
expect(deleteButton).toBeDisabled();
});
});

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

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

0 comments on commit c8c258b

Please sign in to comment.