Skip to content

Commit

Permalink
Remove ts-ignore comments
Browse files Browse the repository at this point in the history
`accessRequestsService.test.ts` was refactored slightly,
we don't need assumed requests there at all.
  • Loading branch information
gzdunek committed Apr 30, 2024
1 parent dd87d87 commit 22cd5a3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 52 deletions.
5 changes: 1 addition & 4 deletions web/packages/teleterm/src/ui/Documents/DocumentsRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import { createPortal } from 'react-dom';
import styled from 'styled-components';
import { Text } from 'design';

/* eslint-disable @typescript-eslint/ban-ts-comment*/
// @ts-ignore
import { DocumentAccessRequests } from 'e-teleterm/ui/DocumentAccessRequests/DocumentAccessRequests';

import { DocumentAccessRequests } from 'teleterm/ui/DocumentAccessRequests';
import { DocumentGatewayCliClient } from 'teleterm/ui/DocumentGatewayCliClient';

import { useAppContext } from 'teleterm/ui/appContextProvider';
Expand Down
4 changes: 1 addition & 3 deletions web/packages/teleterm/src/ui/LayoutManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

import React, { useRef } from 'react';
import { Flex } from 'design';
/* eslint-disable @typescript-eslint/ban-ts-comment*/
// @ts-ignore
import { AccessRequestCheckout } from 'e-teleterm/ui/AccessRequestCheckout';

import { AccessRequestCheckout } from 'teleterm/ui/AccessRequestCheckout';
import { TabHostContainer } from 'teleterm/ui/TabHost';
import { TopBar } from 'teleterm/ui/TopBar';
import { StatusBar } from 'teleterm/ui/StatusBar';
Expand Down
4 changes: 1 addition & 3 deletions web/packages/teleterm/src/ui/StatusBar/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable @typescript-eslint/ban-ts-comment*/
import React from 'react';
import { Flex, Text } from 'design';
// @ts-ignore
import { AccessRequestCheckoutButton } from 'e-teleterm/ui/StatusBar/AccessRequestCheckoutButton';

import { useActiveDocumentClusterBreadcrumbs } from './useActiveDocumentClusterBreadcrumbs';
import { ShareFeedback } from './ShareFeedback';
import { AccessRequestCheckoutButton } from './AccessRequestCheckoutButton';

export function StatusBar() {
const clusterBreadcrumbs = useActiveDocumentClusterBreadcrumbs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable @typescript-eslint/ban-ts-comment*/
// @ts-ignore
import { AccessRequest } from 'e-teleport/services/workflow';

import { ImmutableStore } from 'teleterm/ui/services/immutableStore';

import {
Expand Down Expand Up @@ -47,23 +43,14 @@ function getMockPendingAccessRequest(): PendingAccessRequest {
};
}

function getMockAssumed(assumed = {}): Record<string, AccessRequest> {
return assumed;
}

function createService(
pending: PendingAccessRequest,
assumed: Record<string, AccessRequest>
): AccessRequestsService {
function createService(pending: PendingAccessRequest): AccessRequestsService {
const store = new ImmutableStore<{
isBarCollapsed: boolean;
pending: PendingAccessRequest;
assumed: Record<string, AccessRequest>;
}>();
store.state = {
isBarCollapsed: false,
pending,
assumed,
};
return new AccessRequestsService(
() => store.state,
Expand All @@ -72,63 +59,48 @@ function createService(
}

test('getCollapsed() returns the bar collapse state', () => {
let service = createService(getMockPendingAccessRequest(), getMockAssumed());
let service = createService(getMockPendingAccessRequest());
expect(service.getCollapsed()).toBe(false);
});

test('toggleBar() changes the collapse state', () => {
let service = createService(getMockPendingAccessRequest(), getMockAssumed());
let service = createService(getMockPendingAccessRequest());
expect(service.getCollapsed()).toBe(false);
service.toggleBar();
expect(service.getCollapsed()).toBe(true);
});

test('clearPendingAccessRequest() clears pending access reuqest', () => {
let service = createService(
getMockPendingAccessRequest(),
getMockAssumed({})
);
let service = createService(getMockPendingAccessRequest());
service.clearPendingAccessRequest();
expect(service.getPendingAccessRequest()).toStrictEqual(
getEmptyPendingAccessRequest()
);
});

test('getAddedResourceCount() returns added resource count for pending request', () => {
let service = createService(
getMockPendingAccessRequest(),
getMockAssumed({})
);
let service = createService(getMockPendingAccessRequest());
expect(service.getAddedResourceCount()).toBe(3);
service.clearPendingAccessRequest();
expect(service.getAddedResourceCount()).toBe(0);
});

test('addOrRemoveResource() adds resource to pending request', () => {
let service = createService(
getMockPendingAccessRequest(),
getMockAssumed({})
);
let service = createService(getMockPendingAccessRequest());
service.addOrRemoveResource('node', '456', 'node2');
const pendingAccessRequest = service.getPendingAccessRequest();
expect(pendingAccessRequest['node']).toHaveProperty('456');
});

test('addOrRemoveResource() removes resource if it already exists on pending request', () => {
let service = createService(
getMockPendingAccessRequest(),
getMockAssumed({})
);
let service = createService(getMockPendingAccessRequest());
service.addOrRemoveResource('node', '123', 'node1');
const pendingAccessRequest = service.getPendingAccessRequest();
expect(pendingAccessRequest['node']).not.toHaveProperty('123');
});

test('addOrRemoveResource() uses resourceId when resourceName is empty', () => {
let service = createService(
getMockPendingAccessRequest(),
getMockAssumed({})
);
let service = createService(getMockPendingAccessRequest());
const resourceId = '567';
const resourceName = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable @typescript-eslint/ban-ts-comment*/
// @ts-ignore
import { ResourceKind } from 'e-teleterm/ui/DocumentAccessRequests/NewRequest/useNewRequest';
import { ResourceKind } from 'shared/components/AccessRequests/NewRequest';

import type { PendingAccessRequest } from '../workspacesService';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import { z } from 'zod';
import { useStore } from 'shared/libs/stores';
import { arrayObjectIsEqual } from 'shared/utils/highbar';

/* eslint-disable @typescript-eslint/ban-ts-comment*/
// @ts-ignore
import { ResourceKind } from 'e-teleport/Workflow/NewRequest/useNewRequest';
import { ResourceKind } from 'shared/components/AccessRequests/NewRequest';

import {
DefaultTab,
Expand Down

0 comments on commit 22cd5a3

Please sign in to comment.