Skip to content

Commit 0ca133e

Browse files
authored
Fix Template Credentials in the UI / Turn on typechecking of UI code (#3704)
* Turn on typechecking of UI code * Fixes up types after turning on Typechecking in CI * Tidy up types a bit
1 parent bfc1a3f commit 0ca133e

File tree

9 files changed

+63
-40
lines changed

9 files changed

+63
-40
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ jobs:
132132
${{ runner.os }}-${{ env.YARN_CACHE_NAME }}-
133133
- name: Install modules
134134
run: yarn --pure-lockfile
135+
- name: Typecheck Frontend Code
136+
run: yarn tsc
135137
- name: Lint Frontend Code
136138
run: yarn lint
137139
- name: Run Front-end Unit Tests
138140
run: yarn test
139-

tools/dev-resources/user-guide/vcluster-capi-template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
annotations:
77
templates.weave.works/profiles-enabled: "true"
88
templates.weave.works/add-common-bases: "true"
9+
templates.weave.works/credentials-enabled: "true"
910
labels:
1011
weave.works/template-type: cluster
1112
spec:

ui/src/components/Explorer/__tests__/Explorer.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { EnterpriseClientContext } from '../../../contexts/API';
88
import {
99
defaultContexts,
1010
MockQueryService,
11+
newMockQueryService,
1112
withContext,
1213
} from '../../../utils/test-utils';
1314
import Explorer from '../Explorer';
@@ -49,7 +50,7 @@ describe('Explorer', () => {
4950
let api: MockQueryService;
5051

5152
beforeEach(() => {
52-
api = new MockQueryService();
53+
api = newMockQueryService();
5354
wrap = withContext([
5455
...defaultContexts(),
5556
[EnterpriseClientContext.Provider, { value: { query: api } }],

ui/src/components/GitAuth/GithubDeviceAuthModal.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { storeProviderToken } from './utils';
88

99
type Props = {
1010
className?: string;
11-
bodyClassName?: string;
1211
open: boolean;
1312
onSuccess: (token: string) => void;
1413
onClose: () => void;
@@ -17,7 +16,6 @@ type Props = {
1716

1817
export function GithubDeviceAuthModal({
1918
className,
20-
bodyClassName,
2119
open,
2220
onClose,
2321
repoName,
@@ -27,7 +25,6 @@ export function GithubDeviceAuthModal({
2725
return (
2826
<Modal
2927
className={className}
30-
bodyClassName={bodyClassName}
3128
title="Authenticate with Github"
3229
open={open}
3330
onClose={onClose}

ui/src/components/GitAuth/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const GitAuth: FC<{
7777
/>
7878
{showAuthDialog && (
7979
<GithubDeviceAuthModal
80-
bodyClassName="GithubDeviceAuthModal"
8180
onClose={() => setShowAuthDialog(false)}
8281
onSuccess={() => setShowAuthDialog(false)}
8382
open={showAuthDialog}

ui/src/contexts/API/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Pipelines } from '../../api/pipelines/pipelines.pb';
1010
import { Query } from '../../api/query/query.pb';
1111
import { GitAuth } from '../../api/gitauth/gitauth.pb';
1212

13-
interface APIs {
13+
export interface APIs {
1414
terraform: typeof Terraform;
1515
clustersService: typeof ClustersService;
1616
progressiveDeliveryService: typeof ProgressiveDeliveryService;

ui/src/hooks/__tests__/query.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { renderHook } from '@testing-library/react-hooks';
22
import { QueryClient, QueryClientProvider } from 'react-query';
3-
import { EnterpriseClientContext } from '../../contexts/API';
4-
import { MockQueryService } from '../../utils/test-utils';
3+
import { APIs, EnterpriseClientContext } from '../../contexts/API';
4+
import { MockQueryService, newMockQueryService } from '../../utils/test-utils';
55
import { formatFilters, useQueryService } from '../query';
66

77
describe('useQueryService', () => {
88
let mock: MockQueryService;
99
let wrapper: ({ children }: any) => JSX.Element;
1010

1111
beforeEach(() => {
12-
mock = new MockQueryService();
12+
mock = newMockQueryService();
1313

1414
wrapper = ({ children }: any) => (
1515
<QueryClientProvider client={new QueryClient()}>
16-
<EnterpriseClientContext.Provider value={{ query: mock }}>
16+
<EnterpriseClientContext.Provider
17+
// We are supplied an incomplete API set here
18+
value={{ query: mock } as unknown as APIs}
19+
>
1720
{children}
1821
</EnterpriseClientContext.Provider>
1922
</QueryClientProvider>

ui/src/hooks/credentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import { useEnterpriseClient } from '../contexts/API';
66
export function useListCredentials() {
77
const { clustersService } = useEnterpriseClient();
88
return useQuery<ListCredentialsResponse, Error>('credentials', () =>
9-
clustersService.vice.ListCredentials({}),
9+
clustersService.ListCredentials({}),
1010
);
1111
}

ui/src/utils/test-utils.tsx

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ import {
2121
} from '@weaveworks/weave-gitops/ui/lib/api/core/core.pb';
2222
import _ from 'lodash';
2323
import React from 'react';
24-
import {
25-
Query,
26-
QueryCache,
27-
QueryClient,
28-
QueryClientProvider,
29-
} from 'react-query';
24+
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query';
3025
import { MemoryRouter } from 'react-router-dom';
3126
import { ThemeProvider } from 'styled-components';
3227
import {
@@ -77,17 +72,20 @@ import {
7772
import {
7873
DebugGetAccessRulesRequest,
7974
DebugGetAccessRulesResponse,
80-
ListFacetsRequest,
81-
ListFacetsResponse,
8275
DoQueryRequest,
8376
DoQueryResponse,
77+
ListEnabledComponentsRequest,
78+
ListEnabledComponentsResponse,
79+
ListFacetsRequest,
80+
ListFacetsResponse,
81+
Query,
8482
} from '../api/query/query.pb';
8583

8684
import Compose from '../components/ProvidersCompose';
85+
import { EnterpriseClientProvider } from '../contexts/API';
8786
import NotificationProvider from '../contexts/Notifications/Provider';
8887
import RequestContextProvider from '../contexts/Request';
8988
import { muiTheme } from '../muiTheme';
90-
import { EnterpriseClientProvider } from '../contexts/API';
9189

9290
export type RequestError = Error & {
9391
code?: number;
@@ -444,28 +442,51 @@ export class SecretsClientMock {
444442
}
445443
}
446444

447-
export class MockQueryService {
448-
DoQueryReturns: DoQueryResponse = {};
449-
DebugGetAccessRulesReturns: DebugGetAccessRulesResponse = {};
450-
ListFacetsReturns: ListFacetsResponse = {};
445+
export type MockQueryService = typeof Query & {
446+
DoQueryReturns: DoQueryResponse;
447+
DebugGetAccessRulesReturns: DebugGetAccessRulesResponse;
448+
ListFacetsReturns: ListFacetsResponse;
449+
ListEnabledComponentsReturns: ListEnabledComponentsResponse;
450+
};
451451

452-
DoQuery(req: DoQueryRequest, initReq?: any): Promise<DoQueryResponse> {
453-
return promisify(this.DoQueryReturns);
454-
}
452+
// Our Query service is a class with static methods.
453+
// The mock will be mutated between tests, so to keep the tests
454+
// consistent we need to create a new class instance for each test.
455+
export function newMockQueryService(): MockQueryService {
456+
return class {
457+
static DoQueryReturns: DoQueryResponse = {};
458+
static DebugGetAccessRulesReturns: DebugGetAccessRulesResponse = {};
459+
static ListFacetsReturns: ListFacetsResponse = {};
460+
static ListEnabledComponentsReturns: ListEnabledComponentsResponse = {};
461+
462+
static ListEnabledComponents(
463+
req: ListEnabledComponentsRequest,
464+
initReq?: any,
465+
): Promise<ListEnabledComponentsResponse> {
466+
return promisify(this.ListEnabledComponentsReturns);
467+
}
455468

456-
DebugGetAccessRules(
457-
req: DebugGetAccessRulesRequest,
458-
initReq?: any,
459-
): Promise<DebugGetAccessRulesResponse> {
460-
return promisify(this.DebugGetAccessRulesReturns);
461-
}
469+
static DoQuery(
470+
req: DoQueryRequest,
471+
initReq?: any,
472+
): Promise<DoQueryResponse> {
473+
return promisify(this.DoQueryReturns);
474+
}
462475

463-
ListFacets(
464-
req: ListFacetsRequest,
465-
initReq?: any,
466-
): Promise<ListFacetsResponse> {
467-
return promisify(this.ListFacetsReturns);
468-
}
476+
static DebugGetAccessRules(
477+
req: DebugGetAccessRulesRequest,
478+
initReq?: any,
479+
): Promise<DebugGetAccessRulesResponse> {
480+
return promisify(this.DebugGetAccessRulesReturns);
481+
}
482+
483+
static ListFacets(
484+
req: ListFacetsRequest,
485+
initReq?: any,
486+
): Promise<ListFacetsResponse> {
487+
return promisify(this.ListFacetsReturns);
488+
}
489+
};
469490
}
470491

471492
export function findCellInCol(cell: string, tableSelector: string) {

0 commit comments

Comments
 (0)