diff --git a/app/assets/javascripts/projects/new_v2/components/import_by_url_form.vue b/app/assets/javascripts/projects/new_v2/components/import_by_url_form.vue
index b0cd6b9e9018b7c297439dd92e92cbd0cbcad23d..6d69093fa84e43b4097486fa1148e55a92f6f1b8 100644
--- a/app/assets/javascripts/projects/new_v2/components/import_by_url_form.vue
+++ b/app/assets/javascripts/projects/new_v2/components/import_by_url_form.vue
@@ -1,12 +1,52 @@
@@ -15,6 +55,55 @@ export default {
:title="s__('ProjectImport|Import repository by URL')"
:current-step="3"
>
+
+
+
+
+
+
+ {{ s__('ProjectImport|Check connection') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{
let wrapper;
+ let mockAxios;
+
+ const mockImportByUrlValidatePath = '/import/url/validate';
const createComponent = () => {
- wrapper = mountExtended(ImportByUrlForm);
+ wrapper = shallowMountExtended(ImportByUrlForm, {
+ provide: {
+ importByUrlValidatePath: mockImportByUrlValidatePath,
+ },
+ mocks: {
+ $toast,
+ },
+ stubs: {
+ GlFormInputGroup,
+ },
+ });
};
beforeEach(() => {
+ mockAxios = new MockAdapter(axios);
createComponent();
});
+ afterEach(() => {
+ mockAxios.restore();
+ });
+
const findNextButton = () => wrapper.findByTestId('import-project-by-url-next-button');
const findBackButton = () => wrapper.findByTestId('import-project-by-url-back-button');
+ const findUrlInput = () => wrapper.findByTestId('repository-url');
+ const findUsernameInput = () => wrapper.findByTestId('repository-username');
+ const findPasswordInput = () => wrapper.findByTestId('repository-password');
+ const findCheckConnectionButton = () => wrapper.findByTestId('check-connection');
+
+ it('renders URL, username, password fields', () => {
+ expect(findUrlInput().exists()).toBe(true);
+ expect(findUsernameInput().exists()).toBe(true);
+ expect(findPasswordInput().exists()).toBe(true);
+ });
+
+ describe('"Check connection" functionality', () => {
+ const mockUrl = 'https://example.com/repo.git';
+ const mockUsername = 'mockuser';
+ const mockPassword = 'mockpass';
+
+ beforeEach(() => {
+ findUrlInput().vm.$emit('input', mockUrl);
+ findUsernameInput().vm.$emit('input', mockUsername);
+ findPasswordInput().vm.$emit('input', mockPassword);
+ });
+
+ describe('when connection is successful', () => {
+ beforeEach(async () => {
+ mockAxios.onPost(mockImportByUrlValidatePath).reply(HTTP_STATUS_OK, { success: true });
+
+ findCheckConnectionButton().vm.$emit('click');
+ await waitForPromises();
+ });
+
+ it('sends correct request', () => {
+ expect(mockAxios.history.post[0].data).toBe(
+ JSON.stringify({
+ url: mockUrl,
+ user: mockUsername,
+ password: mockPassword,
+ }),
+ );
+ });
+
+ it('shows success message when connection is successful', () => {
+ expect($toast.show).toHaveBeenCalledWith('Connection successful.');
+ });
+ });
+
+ describe('when connection fails', () => {
+ it('shows error message', async () => {
+ const errorMessage = 'Invalid credentials';
+ mockAxios
+ .onPost(mockImportByUrlValidatePath)
+ .reply(HTTP_STATUS_OK, { success: false, message: errorMessage });
+ findCheckConnectionButton().vm.$emit('click');
+
+ await waitForPromises();
+
+ expect($toast.show).toHaveBeenCalledWith(`Connection failed: ${errorMessage}`);
+ });
+ });
+
+ describe('when request fails', () => {
+ it('shows error message', async () => {
+ mockAxios.onPost(mockImportByUrlValidatePath).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR);
+ findCheckConnectionButton().vm.$emit('click');
+
+ await waitForPromises();
+
+ expect($toast.show).toHaveBeenCalledWith(expect.stringContaining('Connection failed'));
+ });
+ });
+ });
it('renders the option to move to Next Step', () => {
expect(findNextButton().text()).toBe('Next step');
});
it(`emits the "back" event when the back button is clicked`, () => {
- findBackButton().trigger('click');
+ findBackButton().vm.$emit('click');
expect(wrapper.emitted('back')).toHaveLength(1);
});
});