test: add missing test for gitlab autocomplete
Signed-off-by: asheen1234 <sergeantnumnumz@gmail.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
||||
scaffolderApiRef,
|
||||
useTemplateSecrets,
|
||||
ScaffolderRJSFField,
|
||||
ScaffolderApi,
|
||||
} from '@backstage/plugin-scaffolder-react';
|
||||
import { act, fireEvent, screen } from '@testing-library/react';
|
||||
import { RepoOwnerPicker } from './RepoOwnerPicker';
|
||||
@@ -462,5 +463,51 @@ describe('RepoOwnerPicker', () => {
|
||||
|
||||
expect(getByText('abc123')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should route to GitLabRepoOwnerPicker and call autocomplete with gitlab provider and groups resource', async () => {
|
||||
const secretsKey = 'testKey';
|
||||
const mockScaffolderApi: Partial<ScaffolderApi> = {
|
||||
autocomplete: jest.fn().mockResolvedValue({ results: [] }),
|
||||
};
|
||||
|
||||
await renderInTestApp(
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[scmIntegrationsApiRef, mockIntegrationsApiGitLab],
|
||||
[scmAuthApiRef, mockScmAuthApi],
|
||||
[scaffolderApiRef, mockScaffolderApi],
|
||||
]}
|
||||
>
|
||||
<SecretsContextProvider initialSecrets={{ [secretsKey]: 'abc123' }}>
|
||||
<Form
|
||||
validator={validator}
|
||||
schema={{ type: 'string' }}
|
||||
uiSchema={{
|
||||
'ui:field': 'RepoOwnerPicker',
|
||||
'ui:options': {
|
||||
host: 'gitlab.com',
|
||||
requestUserCredentials: { secretsKey },
|
||||
},
|
||||
}}
|
||||
fields={{
|
||||
RepoOwnerPicker: RepoOwnerPicker as ScaffolderRJSFField<string>,
|
||||
}}
|
||||
/>
|
||||
</SecretsContextProvider>
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
// wait for both the RepoOwnerPicker and GitLabRepoOwnerPicker debounces
|
||||
await new Promise(resolve => setTimeout(resolve, 600));
|
||||
});
|
||||
|
||||
expect(mockScaffolderApi.autocomplete).toHaveBeenCalledWith({
|
||||
token: 'abc123',
|
||||
resource: 'groups',
|
||||
provider: 'gitlab',
|
||||
context: { host: 'gitlab.com' },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user