Skip to content

Fix console warnings when running ui tests #3364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 15, 2023
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
62 changes: 32 additions & 30 deletions ui/src/components/GitAuth/RepoInputWithAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ export function RepoInputWithAuth({
}: Props) {
const parsedValue = value && JSON.parse(value);
const { data: res, error: err } = useParseRepoUrl(parsedValue?.value);
const { data } = useListSources('', '', { retry: false });
const gitRepos = React.useMemo(
() => getGitRepos(data?.result),
[data?.result],
);
const { data, isLoading } = useListSources('', '', { retry: false });
const gitRepos = getGitRepos(data?.result);

const { gitAuthClient } = React.useContext(GitAuth);

const [valueForSelect, setValueForSelect] = React.useState<string>('');
Expand Down Expand Up @@ -95,31 +93,35 @@ export function RepoInputWithAuth({

return (
<GitAuthForm className={props.className} align between>
<Select
error={
!!parsedValue?.value && gitRepos.length > 0 && !!err?.message
? true
: false
}
description={!formData.repo || !err ? props.description : err?.message}
name="repo-select"
required={true}
label="SELECT_GIT_REPO"
value={valueForSelect || ''}
onChange={handleSelectSource}
disabled={!enableGitRepoSelection}
>
{gitRepos
?.map(gitRepo => ({
value: getRepositoryUrl(gitRepo),
key: gitRepo.obj.spec.url,
}))
.map((option, index: number) => (
<MenuItem key={index} value={JSON.stringify(option)}>
{option.key}
</MenuItem>
))}
</Select>
{!isLoading ? (
<Select
error={
!!parsedValue?.value && gitRepos.length > 0 && !!err?.message
? true
: false
}
description={
!formData.repo || !err ? props.description : err?.message
}
name="repo-select"
required={true}
label="SELECT_GIT_REPO"
value={valueForSelect || ''}
onChange={handleSelectSource}
disabled={!enableGitRepoSelection}
>
{gitRepos
?.map(gitRepo => ({
value: getRepositoryUrl(gitRepo),
key: gitRepo.obj.spec.url,
}))
.map((option, index: number) => (
<MenuItem key={index} value={JSON.stringify(option)}>
{option.key}
</MenuItem>
))}
</Select>
) : null}
<div className="auth-message">
{isAuthenticated && (
<Flex align>
Expand Down
31 changes: 30 additions & 1 deletion ui/src/components/GitAuth/__tests__/GitlabAuth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { gitlabOAuthRedirectURI } from '../../../utils/formatters';
import { Routes } from '../../../utils/nav';
import {
ApplicationsClientMock,
CoreClientMock,
defaultContexts,
promisify,
withContext,
} from '../../../utils/test-utils';
import { RepoInputWithAuth } from '../RepoInputWithAuth';
import { CoreClientContextProvider, Kind } from '@weaveworks/weave-gitops';

Object.assign(navigator, {
clipboard: {
Expand All @@ -21,9 +23,11 @@ Object.assign(navigator, {
describe('Gitlab Authenticate', () => {
let wrap: (el: JSX.Element) => JSX.Element;
let api: ApplicationsClientMock;
let coreApi: CoreClientMock;

const gitRepoUrl = JSON.stringify({
value: 'https://gitlab.git.dev.weave.works/test',
key: 'https://gitlab.git.dev.weave.works/test',
});

const onProviderChange = jest.fn();
Expand All @@ -44,7 +48,32 @@ describe('Gitlab Authenticate', () => {
});

api = new ApplicationsClientMock();
wrap = withContext([...defaultContexts(), [GitAuthProvider, { api }]]);
coreApi = new CoreClientMock();

wrap = withContext([
...defaultContexts(),
[GitAuthProvider, { api }],
[CoreClientContextProvider, { api: coreApi }],
]);

coreApi.ListObjectsReturns = {
[Kind.GitRepository]: {
objects: [
{
payload: JSON.stringify({
kind: 'GitRepository',
metadata: {
name: 'test',
},
spec: {
url: 'https://gitlab.git.dev.weave.works/test',
ref: 'master',
},
}),
},
],
},
};
});

it('renders', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('Auth redirect', () => {
beforeEach(() => {
api = new PipelinesClientMock();
wrap = withContext([...defaultContexts(), [PipelinesProvider, { api }]]);
jest.spyOn(console, 'error').mockImplementationOnce(() => {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell this is coming from the library and it's something that we indeed see in the console as well when we're trying to retrieve objects but the token has expired. I've hidden it here to reduce noise

});
const mockResponse = jest.fn();
Object.defineProperty(window, 'location', {
Expand Down