mirror of
https://github.com/portainer/portainer.git
synced 2026-06-23 04:50:12 +00:00
feat(gitops): add "create new source" button to GitSourceSelector [BE-13054] (#2960)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
|
||||
import { withTestQueryProvider } from '@/react/test-utils/withTestQuery';
|
||||
import { withTestRouter } from '@/react/test-utils/withRouter';
|
||||
import { server } from '@/setup-tests/server';
|
||||
|
||||
import { Source } from './types';
|
||||
import { GitSourceSelector } from './GitSourceSelector';
|
||||
|
||||
function renderComponent({
|
||||
value,
|
||||
sources = [],
|
||||
}: {
|
||||
value?: Source['id'];
|
||||
sources?: Array<Pick<Source, 'id' | 'name'>>;
|
||||
} = {}) {
|
||||
server.use(
|
||||
http.get('/api/gitops/sources', () =>
|
||||
HttpResponse.json(sources, {
|
||||
headers: {
|
||||
'x-total-count': String(sources.length),
|
||||
'x-total-available': String(sources.length),
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const Wrapped = withTestQueryProvider(
|
||||
withTestRouter(() => <GitSourceSelector value={value} onChange={vi.fn()} />)
|
||||
);
|
||||
|
||||
return render(<Wrapped />);
|
||||
}
|
||||
|
||||
describe('GitSourceSelector', () => {
|
||||
it('renders the source selector', async () => {
|
||||
renderComponent();
|
||||
|
||||
expect(await screen.findByLabelText('Source')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the create new source button', async () => {
|
||||
renderComponent();
|
||||
|
||||
expect(
|
||||
await screen.findByTestId('create-source-button')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AddButton } from '@@/buttons';
|
||||
import { FormControl } from '@@/form-components/FormControl';
|
||||
import { Select } from '@@/form-components/ReactSelect';
|
||||
|
||||
@@ -23,6 +24,8 @@ export function GitSourceSelector({
|
||||
<div className="form-group">
|
||||
<div className="col-sm-12">
|
||||
<FormControl label="Source" inputId="source-selector" errors={error}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex-1">
|
||||
<Select
|
||||
placeholder="Select a source"
|
||||
value={selectedSource ?? null}
|
||||
@@ -37,6 +40,14 @@ export function GitSourceSelector({
|
||||
data-cy="source-selector"
|
||||
isDisabled={readOnly}
|
||||
/>
|
||||
</div>
|
||||
<AddButton
|
||||
to="portainer.gitops.sources.new"
|
||||
data-cy="create-source-button"
|
||||
>
|
||||
Create new source
|
||||
</AddButton>
|
||||
</div>
|
||||
</FormControl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user