chore: need to convert these to empty strings as they are controlled input values and material ui throws some errors in the frontend unless we have them
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
import { scaffolderApiRef } from '../../../api';
|
||||
import { SecretsContextProvider } from '../../secrets/SecretsContext';
|
||||
import { ScaffolderApi } from '../../..';
|
||||
import { fireEvent } from '@testing-library/react';
|
||||
|
||||
describe('RepoUrlPicker', () => {
|
||||
const mockScaffolderApi: Partial<ScaffolderApi> = {
|
||||
@@ -38,8 +39,9 @@ describe('RepoUrlPicker', () => {
|
||||
};
|
||||
|
||||
describe('happy path rendering', () => {
|
||||
it('should render the repo url picker', async () => {
|
||||
const { getByRole } = await renderInTestApp(
|
||||
it('should render the repo url picker with minimal props', async () => {
|
||||
const onSubmit = jest.fn();
|
||||
const { getAllByRole, getByRole } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[scmIntegrationsApiRef, mockIntegrationsApi],
|
||||
@@ -52,15 +54,26 @@ describe('RepoUrlPicker', () => {
|
||||
schema={{ type: 'string' }}
|
||||
uiSchema={{ 'ui:field': 'RepoUrlPicker' }}
|
||||
fields={{ RepoUrlPicker: RepoUrlPicker }}
|
||||
onSubmit={onSubmit}
|
||||
/>
|
||||
</SecretsContextProvider>
|
||||
,
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
const [ownerInput, repoInput] = getAllByRole('textbox');
|
||||
const submitButton = getByRole('button');
|
||||
|
||||
console.log(getByRole('form'));
|
||||
fireEvent.change(ownerInput, { target: { value: 'backstage' } });
|
||||
fireEvent.change(repoInput, { target: { value: 'repo123' } });
|
||||
|
||||
fireEvent.click(submitButton);
|
||||
|
||||
expect(onSubmit).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
formData: 'github.com?owner=backstage&repo=repo123',
|
||||
}),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,22 +44,22 @@ export function serializeRepoPickerUrl(data: RepoUrlPickerState) {
|
||||
export function parseRepoPickerUrl(
|
||||
url: string | undefined,
|
||||
): RepoUrlPickerState {
|
||||
let host = undefined;
|
||||
let owner = undefined;
|
||||
let repoName = undefined;
|
||||
let organization = undefined;
|
||||
let workspace = undefined;
|
||||
let project = undefined;
|
||||
let host = '';
|
||||
let owner = '';
|
||||
let repoName = '';
|
||||
let organization = '';
|
||||
let workspace = '';
|
||||
let project = '';
|
||||
|
||||
try {
|
||||
if (url) {
|
||||
const parsed = new URL(`https://${url}`);
|
||||
host = parsed.host;
|
||||
owner = parsed.searchParams.get('owner') || undefined;
|
||||
repoName = parsed.searchParams.get('repo') || undefined;
|
||||
organization = parsed.searchParams.get('organization') || undefined;
|
||||
workspace = parsed.searchParams.get('workspace') || undefined;
|
||||
project = parsed.searchParams.get('project') || undefined;
|
||||
owner = parsed.searchParams.get('owner') || '';
|
||||
repoName = parsed.searchParams.get('repo') || '';
|
||||
organization = parsed.searchParams.get('organization') || '';
|
||||
workspace = parsed.searchParams.get('workspace') || '';
|
||||
project = parsed.searchParams.get('project') || '';
|
||||
}
|
||||
} catch {
|
||||
/* ok */
|
||||
|
||||
Reference in New Issue
Block a user