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
28 changes: 11 additions & 17 deletions web/packages/teleterm/src/ui/Search/SearchBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ it('does not display empty results copy after selecting two filters', () => {
expect(results).not.toHaveTextContent('No matching results found');
});

it('does display empty results copy after providing search query for which there is no results', () => {
it('displays empty results copy after providing search query for which there is no results', () => {
const appContext = new MockAppContext();
appContext.workspacesService.setState(draft => {
draft.rootClusterUri = '/clusters/foo';
Expand Down Expand Up @@ -110,22 +110,14 @@ it('does display empty results copy after providing search query for which there
expect(results).toHaveTextContent('No matching results found.');
});

it('does display empty results copy and excluded clusters after providing search query for which there is no results', () => {
it('includes offline cluster names in the empty results copy', () => {
const appContext = new MockAppContext();
jest
.spyOn(appContext.clustersService, 'getRootClusters')
.mockImplementation(() => [
{
uri: '/clusters/teleport-12-ent.asteroid.earth',
name: 'teleport-12-ent.asteroid.earth',
connected: false,
leaf: false,
proxyHost: 'test:3030',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
},
]);
const cluster = makeRootCluster({ connected: false });
appContext.clustersService.setState(draftState => {
draftState.clusters.set(cluster.uri, cluster);
});
appContext.workspacesService.setState(draft => {
draft.rootClusterUri = '/clusters/foo';
draft.rootClusterUri = cluster.uri;
});

const mockActionAttempts = {
Expand Down Expand Up @@ -153,7 +145,7 @@ it('does display empty results copy and excluded clusters after providing search
const results = screen.getByRole('menu');
expect(results).toHaveTextContent('No matching results found.');
expect(results).toHaveTextContent(
'The cluster teleport-12-ent.asteroid.earth was excluded from the search because you are not logged in to it.'
`The cluster ${cluster.name} was excluded from the search because you are not logged in to it.`
);
});

Expand Down Expand Up @@ -216,6 +208,7 @@ it('notifies about resource search errors and allows to display details', () =>
});

it('maintains focus on the search input after closing a resource search error modal', async () => {
const user = userEvent.setup();
const appContext = new MockAppContext();
appContext.workspacesService.setState(draft => {
draft.rootClusterUri = '/clusters/foo';
Expand Down Expand Up @@ -247,7 +240,8 @@ it('maintains focus on the search input after closing a resource search error mo
</MockAppContextProvider>
);

screen.getByRole('searchbox').focus();
await user.type(screen.getByRole('searchbox'), 'foo');

expect(screen.getByRole('menu')).toHaveTextContent(
'Some of the search results are incomplete.'
);
Expand Down
20 changes: 8 additions & 12 deletions web/packages/teleterm/src/ui/Search/pickers/ActionPicker.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,16 @@ const AuxiliaryItems = () => (
ExtraTopComponent={
<>
<NoResultsItem
clusters={[
{
uri: clusterUri,
name: 'teleport-12-ent.asteroid.earth',
connected: false,
leaf: false,
proxyHost: 'test:3030',
authClusterId: '73c4746b-d956-4f16-9848-4e3469f70762',
},
]}
clustersWithExpiredCerts={new Set([clusterUri])}
getClusterName={routing.parseClusterName}
/>
<NoResultsItem
clustersWithExpiredCerts={new Set([clusterUri, '/clusters/foobar'])}
getClusterName={routing.parseClusterName}
/>
<ResourceSearchErrorsItem
getClusterName={routing.parseClusterName}
onShowDetails={() => window.alert('Error details')}
showErrorsInModal={() => window.alert('Error details')}
errors={[
new ResourceSearchError(
'/clusters/foo',
Expand All @@ -381,7 +377,7 @@ const AuxiliaryItems = () => (
/>
<ResourceSearchErrorsItem
getClusterName={routing.parseClusterName}
onShowDetails={() => window.alert('Error details')}
showErrorsInModal={() => window.alert('Error details')}
errors={[
new ResourceSearchError(
'/clusters/bar',
Expand Down
121 changes: 121 additions & 0 deletions web/packages/teleterm/src/ui/Search/pickers/ActionPicker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* Copyright 2023 Gravitational, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { makeSuccessAttempt } from 'shared/hooks/useAsync';

import { makeRootCluster } from 'teleterm/services/tshd/testHelpers';
import { ResourceSearchError } from 'teleterm/ui/services/resources';

import { getActionPickerStatus } from './ActionPicker';

describe('getActionPickerStatus', () => {
it('partitions resource search errors into clusters with expired certs and non-retryable errors', () => {
const retryableError = new ResourceSearchError(
'/clusters/foo',
'server',
new Error('ssh: cert has expired')
);

const nonRetryableError = new ResourceSearchError(
'/clusters/bar',
'database',
new Error('whoops')
);

const status = getActionPickerStatus({
inputValue: 'foo',
filterActionsAttempt: makeSuccessAttempt([]),
allClusters: [],
actionAttempts: [makeSuccessAttempt([])],
resourceSearchAttempt: makeSuccessAttempt({
errors: [retryableError, nonRetryableError],
results: [],
search: 'foo',
}),
});

expect(status.status).toBe('finished');

const { clustersWithExpiredCerts, nonRetryableResourceSearchErrors } =
status.status === 'finished' && status;

expect([...clustersWithExpiredCerts]).toEqual([retryableError.clusterUri]);
expect(nonRetryableResourceSearchErrors).toEqual([nonRetryableError]);
});

it('merges non-connected clusters with clusters that returned retryable errors', () => {
const offlineCluster = makeRootCluster({ connected: false });
const retryableError = new ResourceSearchError(
'/clusters/foo',
'server',
new Error('ssh: cert has expired')
);

const status = getActionPickerStatus({
inputValue: 'foo',
filterActionsAttempt: makeSuccessAttempt([]),
allClusters: [offlineCluster],
actionAttempts: [makeSuccessAttempt([])],
resourceSearchAttempt: makeSuccessAttempt({
errors: [retryableError],
results: [],
search: 'foo',
}),
});

expect(status.status).toBe('finished');
const { clustersWithExpiredCerts } = status.status === 'finished' && status;

expect(clustersWithExpiredCerts.size).toBe(2);
expect(clustersWithExpiredCerts).toContain(offlineCluster.uri);
expect(clustersWithExpiredCerts).toContain(retryableError.clusterUri);
});

it('includes a cluster with expired cert only once even if multiple requests fail with retryable errors', () => {
const retryableErrors = [
new ResourceSearchError(
'/clusters/foo',
'server',
new Error('ssh: cert has expired')
),
new ResourceSearchError(
'/clusters/foo',
'database',
new Error('ssh: cert has expired')
),
new ResourceSearchError(
'/clusters/foo',
'kube',
new Error('ssh: cert has expired')
),
];
const status = getActionPickerStatus({
inputValue: 'foo',
filterActionsAttempt: makeSuccessAttempt([]),
allClusters: [],
actionAttempts: [makeSuccessAttempt([])],
resourceSearchAttempt: makeSuccessAttempt({
errors: retryableErrors,
results: [],
search: 'foo',
}),
});

expect(status.status).toBe('finished');
const { clustersWithExpiredCerts } = status.status === 'finished' && status;
expect([...clustersWithExpiredCerts]).toEqual(['/clusters/foo']);
});
});
Loading