feat: ui:disabled allowed in RepoUrlPickerName
Signed-off-by: Nikunj Hudka <nikunjhudka123@gmail.com>
This commit is contained in:
@@ -107,4 +107,43 @@ describe('RepoUrlPickerRepoName', () => {
|
||||
await userEvent.click(getByText(availableRepos[0].name));
|
||||
expect(onChange).toHaveBeenCalledWith(availableRepos[0]);
|
||||
});
|
||||
|
||||
it('should disable the repo selection when isDisabled is true', async () => {
|
||||
const allowedRepos = ['foo', 'bar'];
|
||||
const onChange = jest.fn();
|
||||
|
||||
const { getByRole } = await renderInTestApp(
|
||||
<RepoUrlPickerRepoName
|
||||
onChange={onChange}
|
||||
allowedRepos={allowedRepos}
|
||||
rawErrors={[]}
|
||||
isDisabled
|
||||
/>,
|
||||
);
|
||||
|
||||
// Find the select element
|
||||
const selectElement = getByRole('combobox');
|
||||
|
||||
// Ensure it's disabled
|
||||
expect(selectElement).toBeDisabled();
|
||||
});
|
||||
|
||||
it('should disable the text input when no options are passed and isDisabled is true', async () => {
|
||||
const onChange = jest.fn();
|
||||
|
||||
const { getByRole } = await renderInTestApp(
|
||||
<RepoUrlPickerRepoName
|
||||
onChange={onChange}
|
||||
allowedRepos={[]}
|
||||
rawErrors={[]}
|
||||
isDisabled
|
||||
/>,
|
||||
);
|
||||
|
||||
// Find the text input (autocomplete)
|
||||
const textInput = getByRole('textbox');
|
||||
|
||||
// Ensure it's disabled
|
||||
expect(textInput).toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,8 +29,16 @@ export const RepoUrlPickerRepoName = (props: {
|
||||
onChange: (chosenRepo: AvailableRepositories) => void;
|
||||
rawErrors: string[];
|
||||
availableRepos?: AvailableRepositories[];
|
||||
isDisabled?: boolean;
|
||||
}) => {
|
||||
const { repoName, allowedRepos, onChange, rawErrors, availableRepos } = props;
|
||||
const {
|
||||
repoName,
|
||||
allowedRepos,
|
||||
onChange,
|
||||
rawErrors,
|
||||
availableRepos,
|
||||
isDisabled,
|
||||
} = props;
|
||||
const { t } = useTranslationRef(scaffolderTranslationRef);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -63,7 +71,7 @@ export const RepoUrlPickerRepoName = (props: {
|
||||
name: String(Array.isArray(selected) ? selected[0] : selected),
|
||||
})
|
||||
}
|
||||
disabled={allowedRepos.length === 1}
|
||||
disabled={isDisabled || allowedRepos.length === 1}
|
||||
selected={repoName}
|
||||
items={repoItems}
|
||||
/>
|
||||
@@ -86,6 +94,7 @@ export const RepoUrlPickerRepoName = (props: {
|
||||
)}
|
||||
freeSolo
|
||||
autoSelect
|
||||
disabled={isDisabled}
|
||||
/>
|
||||
)}
|
||||
<FormHelperText>
|
||||
|
||||
Reference in New Issue
Block a user