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
14 changes: 14 additions & 0 deletions web/packages/build/jest/jest-environment-patched-jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ export default class PatchedJSDOMEnvironment extends JSDOMEnvironment {
global.AbortSignal = AbortSignal;
global.AbortController = AbortController;
}
// TODO(gzdunek): Remove when JSDOM supports Set.prototype.difference.
// After the update to Node.js 22, we can replace the implementation with
// global.Set.prototype.difference = Set.prototype.difference.
if (!global.Set.difference) {
global.Set.prototype.difference = function (otherSet) {
const result = new Set();
for (const value of this) {
if (!otherSet.has(value)) {
result.add(value);
}
}
return result;
};
}
}
}
export const TestEnvironment = PatchedJSDOMEnvironment;
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ import { useAssumedRolesBar } from './useAssumedRolesBar';
test('dropping a request refreshes resources', async () => {
const appContext = new MockAppContext();
const cluster = makeRootCluster();
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
draftState.workspaces[cluster.uri] = {
localClusterUri: cluster.uri,
documents: [],
location: undefined,
accessRequests: undefined,
};
});
appContext.addRootCluster(cluster);
Comment thread
gzdunek marked this conversation as resolved.
jest.spyOn(appContext.clustersService, 'dropRoles');
const refreshListener = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export function ClusterAdd(props: {
onSuccess(clusterUri: string): void;
prefill: { clusterAddress: string };
}) {
const { clustersService } = useAppContext();
const { clustersService, workspacesService } = useAppContext();
const [{ status, statusText }, addCluster] = useAsync(
async (addr: string) => {
const proxyAddr = parseClusterProxyWebAddr(addr);
const cluster = await clustersService.addRootCluster(proxyAddr);
workspacesService.addWorkspace(cluster.uri);
Comment thread
gzdunek marked this conversation as resolved.
return props.onSuccess(cluster.uri);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { ResourcesContextProvider } from 'teleterm/ui/DocumentCluster/resourcesC
import { MockAppContextProvider } from 'teleterm/ui/fixtures/MockAppContextProvider';
import { MockAppContext } from 'teleterm/ui/fixtures/mocks';
import { MockWorkspaceContextProvider } from 'teleterm/ui/fixtures/MockWorkspaceContextProvider';
import { IAppContext } from 'teleterm/ui/types';

import { ConnectMyComputerContextProvider } from '../connectMyComputerContext';
import { Setup } from './Setup';
Expand Down Expand Up @@ -153,20 +152,11 @@ function ShowState({
clickStartSetup = true,
}: {
cluster: Cluster;
appContext: IAppContext;
appContext: MockAppContext;
clickStartSetup?: boolean;
}) {
if (!appContext.clustersService.state.clusters.get(cluster.uri)) {
appContext.clustersService.state.clusters.set(cluster.uri, cluster);
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
draftState.workspaces[cluster.uri] = {
localClusterUri: cluster.uri,
documents: [],
location: undefined,
accessRequests: undefined,
};
});
appContext.addRootCluster(cluster);
}

useLayoutEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,7 @@ function setupAppContext(): {
const appContext = new MockAppContext({
appVersion: cluster.proxyVersion,
});
appContext.clustersService.state.clusters.set(cluster.uri, cluster);
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
draftState.workspaces[cluster.uri] = {
localClusterUri: cluster.uri,
documents: [],
location: undefined,
accessRequests: undefined,
};
});
appContext.addRootCluster(cluster);

jest
.spyOn(appContext.mainProcessClient, 'isAgentConfigFileCreated')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
makeRootCluster,
makeServer,
} from 'teleterm/services/tshd/testHelpers';
import AppContext from 'teleterm/ui/appContext';
import { ResourcesContextProvider } from 'teleterm/ui/DocumentCluster/resourcesContext';
import { MockAppContextProvider } from 'teleterm/ui/fixtures/MockAppContextProvider';
import { MockAppContext } from 'teleterm/ui/fixtures/mocks';
Expand Down Expand Up @@ -236,7 +235,7 @@ export function UpgradeAgentSuggestion() {

function ShowState(props: {
agentProcessState: AgentProcessState;
appContext?: AppContext;
appContext?: MockAppContext;
proxyVersion?: string;
autoStart?: boolean;
}) {
Expand All @@ -248,18 +247,7 @@ function ShowState(props: {
new MockAppContext({ appVersion: cluster.proxyVersion });

appContext.mainProcessClient.getAgentState = () => props.agentProcessState;
appContext.clustersService.state.clusters.set(cluster.uri, cluster);
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
draftState.workspaces = {
[cluster.uri]: {
localClusterUri: cluster.uri,
documents: [],
location: '/docs/1234',
accessRequests: undefined,
},
};
});
appContext.addRootCluster(cluster);

if (props.autoStart) {
appContext.workspacesService.setConnectMyComputerAutoStart(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
title: 'Teleterm/ConnectMyComputer/NavigationMenu',
};

export function AgenNotConfigured() {
export function AgentNotConfigured() {
return (
<ShowState
agentProcessState={{ status: 'not-started' }}
Expand Down Expand Up @@ -161,16 +161,7 @@ function ShowState({
const cluster = makeRootCluster({
proxyVersion: '17.0.0',
});
appContext.clustersService.state.clusters.set(cluster.uri, cluster);
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = cluster.uri;
draftState.workspaces[cluster.uri] = {
localClusterUri: cluster.uri,
documents: [],
location: undefined,
accessRequests: undefined,
};
});
appContext.addRootCluster(cluster);

appContext.mainProcessClient.getAgentState = () => agentProcessState;
appContext.connectMyComputerService.isAgentConfigFileCreated =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,7 @@ function getMocks() {
const appContext = new MockAppContext({
appVersion: rootCluster.proxyVersion,
});

appContext.clustersService.setState(draftState => {
draftState.clusters.set(rootCluster.uri, rootCluster);
});
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = rootCluster.uri;
draftState.workspaces[rootCluster.uri] = {
documents: [],
location: undefined,
localClusterUri: rootCluster.uri,
accessRequests: undefined,
};
});
appContext.addRootCluster(rootCluster);

return { appContext, rootCluster };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { ResourcesContextProvider } from 'teleterm/ui/DocumentCluster/resourcesC
import { MockAppContext } from 'teleterm/ui/fixtures/mocks';
import { MockWorkspaceContextProvider } from 'teleterm/ui/fixtures/MockWorkspaceContextProvider';
import * as types from 'teleterm/ui/services/workspacesService';
import { getEmptyPendingAccessRequest } from 'teleterm/ui/services/workspacesService/accessRequestsService';

const rootCluster = makeRootCluster();

Expand Down Expand Up @@ -89,18 +88,7 @@ export function Browsing() {
startKey: '',
requests: [mockedAccessRequest],
});
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = rootCluster.uri;
draftState.workspaces[rootCluster.uri] = {
localClusterUri: doc.clusterUri,
documents: [doc],
location: doc.uri,
accessRequests: {
pending: getEmptyPendingAccessRequest(),
isBarCollapsed: true,
},
};
});
appContext.addRootClusterWithDoc(rootCluster, [doc]);

return (
<AppContextProvider value={appContext}>
Expand All @@ -117,21 +105,7 @@ export function BrowsingError() {
const appContext = new MockAppContext();
appContext.tshd.getAccessRequests = () =>
new MockedUnaryCall(null, new Error('network error'));
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = rootCluster.uri;
draftState.workspaces[rootCluster.uri] = {
localClusterUri: doc.clusterUri,
documents: [doc],
location: doc.uri,
accessRequests: {
pending: getEmptyPendingAccessRequest(),
isBarCollapsed: true,
},
};
});
appContext.clustersService.setState(draftState => {
draftState.clusters.set(rootCluster.uri, rootCluster);
});
appContext.addRootClusterWithDoc(rootCluster, [doc]);

return (
<AppContextProvider value={appContext}>
Expand All @@ -156,24 +130,13 @@ export function CreatingWhenUnifiedResourcesShowOnlyAccessibleResources() {
startKey: '',
requests: [mockedAccessRequest],
});
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = rootCluster.uri;
draftState.workspaces[rootCluster.uri] = {
localClusterUri: docCreating.clusterUri,
documents: [docCreating],
location: docCreating.uri,
accessRequests: {
pending: getEmptyPendingAccessRequest(),
isBarCollapsed: true,
},
};
});
appContext.clustersService.setState(draftState => {
draftState.clusters.set(rootCluster.uri, {
appContext.addRootClusterWithDoc(
{
...rootCluster,
showResources: ShowResources.ACCESSIBLE_ONLY,
});
});
},
[doc]
);

return (
<AppContextProvider value={appContext}>
Expand All @@ -198,24 +161,13 @@ export function CreatingWhenUnifiedResourcesShowRequestableAndAccessibleResource
startKey: '',
requests: [mockedAccessRequest],
});
appContext.workspacesService.setState(draftState => {
draftState.rootClusterUri = rootCluster.uri;
draftState.workspaces[rootCluster.uri] = {
localClusterUri: docCreating.clusterUri,
documents: [docCreating],
location: docCreating.uri,
accessRequests: {
pending: getEmptyPendingAccessRequest(),
isBarCollapsed: true,
},
};
});
appContext.clustersService.setState(draftState => {
draftState.clusters.set(rootCluster.uri, {
appContext.addRootClusterWithDoc(
{
...rootCluster,
showResources: ShowResources.REQUESTABLE,
});
});
},
[doc]
);

return (
<AppContextProvider value={appContext}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,7 @@ test('authorizing a session opens its URL and closes document', async () => {
loggedInUser: makeLoggedInUser({ isDeviceTrusted: true }),
});
const appContext = new MockAppContext();
appContext.clustersService.setState(draftState => {
draftState.clusters.set(rootCluster.uri, rootCluster);
});
appContext.workspacesService.setState(draftState => {
draftState.workspaces[rootCluster.uri] = {
localClusterUri: rootCluster.uri,
documents: [doc],
location: undefined,
accessRequests: undefined,
};
});
appContext.addRootClusterWithDoc(rootCluster, doc);

render(
<MockAppContextProvider appContext={appContext}>
Expand Down
Loading