feat: ui:disabled allowed in GiteaRepoPicker

Signed-off-by: Nikunj Hudka <nikunjhudka123@gmail.com>
This commit is contained in:
Nikunj Hudka
2025-02-23 23:06:04 -04:00
parent a986c02737
commit 9695c9e29b
2 changed files with 19 additions and 2 deletions
@@ -20,6 +20,22 @@ import { fireEvent } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
describe('GiteaRepoPicker', () => {
it('disables input fields when isDisabled is true', async () => {
const { getAllByRole } = await renderInTestApp(
<GiteaRepoPicker
onChange={jest.fn()}
rawErrors={[]}
state={{}}
isDisabled
/>,
);
const allInputs = getAllByRole('textbox');
allInputs.forEach(input => {
expect(input).toBeDisabled();
});
});
describe('owner input field', () => {
it('calls onChange when the owner input changes', async () => {
const onChange = jest.fn();
@@ -28,7 +28,7 @@ export const GiteaRepoPicker = (
allowedRepos?: string[];
}>,
) => {
const { allowedOwners = [], state, onChange, rawErrors } = props;
const { allowedOwners = [], state, onChange, rawErrors, isDisabled } = props;
const { t } = useTranslationRef(scaffolderTranslationRef);
const ownerItems: SelectItem[] = allowedOwners
? allowedOwners.map(i => ({ label: i, value: i }))
@@ -55,7 +55,7 @@ export const GiteaRepoPicker = (
),
})
}
disabled={allowedOwners.length === 1}
disabled={isDisabled || allowedOwners.length === 1}
selected={owner}
items={ownerItems}
/>
@@ -70,6 +70,7 @@ export const GiteaRepoPicker = (
label={t('fields.giteaRepoPicker.owner.inputTitle')}
onChange={e => onChange({ owner: e.target.value })}
helperText={t('fields.giteaRepoPicker.owner.description')}
disabled={isDisabled}
value={owner}
/>
</>