From 872d1e03f60018f9471a6dc4815ab82f9bb2b12c Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Mon, 22 Jun 2026 17:19:53 +0300 Subject: [PATCH] feat(gitops): add "create new source" button to GitSourceSelector [BE-13054] (#2960) Co-authored-by: Claude --- .../gitops/sources/GitSourceSelector.test.tsx | 50 +++++++++++++++++++ .../gitops/sources/GitSourceSelector.tsx | 39 +++++++++------ 2 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 app/react/portainer/gitops/sources/GitSourceSelector.test.tsx diff --git a/app/react/portainer/gitops/sources/GitSourceSelector.test.tsx b/app/react/portainer/gitops/sources/GitSourceSelector.test.tsx new file mode 100644 index 0000000000..268d8c9335 --- /dev/null +++ b/app/react/portainer/gitops/sources/GitSourceSelector.test.tsx @@ -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>; +} = {}) { + 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(() => ) + ); + + return render(); +} + +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(); + }); +}); diff --git a/app/react/portainer/gitops/sources/GitSourceSelector.tsx b/app/react/portainer/gitops/sources/GitSourceSelector.tsx index d617451ce6..efdbccb5c8 100644 --- a/app/react/portainer/gitops/sources/GitSourceSelector.tsx +++ b/app/react/portainer/gitops/sources/GitSourceSelector.tsx @@ -1,3 +1,4 @@ +import { AddButton } from '@@/buttons'; import { FormControl } from '@@/form-components/FormControl'; import { Select } from '@@/form-components/ReactSelect'; @@ -23,20 +24,30 @@ export function GitSourceSelector({
- s.name} + getOptionValue={(s) => String(s.id)} + onChange={onChange} + isClearable + isLoading={sourcesQuery.isLoading} + noOptionsMessage={() => 'No git sources available'} + inputId="source-selector" + data-cy="source-selector" + isDisabled={readOnly} + /> +
+ + Create new source + +