Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-06-27 06:08:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-27 06:08:49 +0300
commitf33d28f789f690bfc01c8b81d95259a9f1c68b79 (patch)
tree9187328d55a3621801353946d6dc2a1cd8af8cbf /spec/frontend/environments/new_environment_spec.js
parent661be4dd35d8258dee746c26e919e6f552afbec9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/environments/new_environment_spec.js')
-rw-r--r--spec/frontend/environments/new_environment_spec.js108
1 files changed, 14 insertions, 94 deletions
diff --git a/spec/frontend/environments/new_environment_spec.js b/spec/frontend/environments/new_environment_spec.js
index 749e4e5caa4..30cd9265d0d 100644
--- a/spec/frontend/environments/new_environment_spec.js
+++ b/spec/frontend/environments/new_environment_spec.js
@@ -1,5 +1,4 @@
import { GlLoadingIcon } from '@gitlab/ui';
-import MockAdapter from 'axios-mock-adapter';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { mountExtended } from 'helpers/vue_test_utils_helper';
@@ -7,8 +6,6 @@ import waitForPromises from 'helpers/wait_for_promises';
import NewEnvironment from '~/environments/components/new_environment.vue';
import createEnvironment from '~/environments/graphql/mutations/create_environment.mutation.graphql';
import { createAlert } from '~/alert';
-import axios from '~/lib/utils/axios_utils';
-import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status';
import { visitUrl } from '~/lib/utils/url_utility';
import { __ } from '~/locale';
import createMockApollo from '../__helpers__/mock_apollo_helper';
@@ -16,9 +13,6 @@ import createMockApollo from '../__helpers__/mock_apollo_helper';
jest.mock('~/lib/utils/url_utility');
jest.mock('~/alert');
-const newName = 'test';
-const newExternalUrl = 'https://google.ca';
-
const provide = {
projectEnvironmentsPath: '/projects/environments',
projectPath: '/path/to/project',
@@ -32,7 +26,6 @@ const environmentCreateError = {
describe('~/environments/components/new.vue', () => {
let wrapper;
- let mock;
const createMockApolloProvider = (mutationResult) => {
Vue.use(VueApollo);
@@ -47,29 +40,13 @@ describe('~/environments/components/new.vue', () => {
const createWrapperWithApollo = async (mutationResult = environmentCreate) => {
wrapper = mountExtended(NewEnvironment, {
- provide: {
- ...provide,
- glFeatures: {
- environmentSettingsToGraphql: true,
- },
- },
+ provide,
apolloProvider: createMockApolloProvider(mutationResult),
});
await waitForPromises();
};
- const createWrapperWithAxios = () => {
- wrapper = mountExtended(NewEnvironment, {
- provide: {
- ...provide,
- glFeatures: {
- environmentSettingsToGraphql: false,
- },
- },
- });
- };
-
const findNameInput = () => wrapper.findByLabelText(__('Name'));
const findExternalUrlInput = () => wrapper.findByLabelText(__('External URL'));
const findForm = () => wrapper.findByRole('form', { name: __('New environment') });
@@ -84,7 +61,7 @@ describe('~/environments/components/new.vue', () => {
describe('default', () => {
beforeEach(() => {
- createWrapperWithAxios();
+ createWrapperWithApollo();
});
it('sets the title to New environment', () => {
@@ -103,93 +80,36 @@ describe('~/environments/components/new.vue', () => {
});
});
- describe('when environmentSettingsToGraphql feature is enabled', () => {
- describe('when mutation successful', () => {
- beforeEach(() => {
- createWrapperWithApollo();
- });
-
- it('shows loader after form is submitted', async () => {
- expect(showsLoading()).toBe(false);
-
- await submitForm();
-
- expect(showsLoading()).toBe(true);
- });
-
- it('submits the new environment on submit', async () => {
- submitForm();
- await waitForPromises();
-
- expect(visitUrl).toHaveBeenCalledWith('path/to/environment');
- });
- });
-
- describe('when failed', () => {
- beforeEach(async () => {
- createWrapperWithApollo(environmentCreateError);
- submitForm();
- await waitForPromises();
- });
-
- it('shows errors on error', () => {
- expect(createAlert).toHaveBeenCalledWith({ message: 'uh oh!' });
- expect(showsLoading()).toBe(false);
- });
- });
- });
-
- describe('when environmentSettingsToGraphql feature is disabled', () => {
+ describe('when mutation successful', () => {
beforeEach(() => {
- mock = new MockAdapter(axios);
- createWrapperWithAxios();
- });
-
- afterEach(() => {
- mock.restore();
+ createWrapperWithApollo();
});
it('shows loader after form is submitted', async () => {
expect(showsLoading()).toBe(false);
- mock
- .onPost(provide.projectEnvironmentsPath, {
- name: newName,
- external_url: newExternalUrl,
- })
- .reply(HTTP_STATUS_OK, { path: '/test' });
-
await submitForm();
expect(showsLoading()).toBe(true);
});
it('submits the new environment on submit', async () => {
- mock
- .onPost(provide.projectEnvironmentsPath, {
- name: newName,
- external_url: newExternalUrl,
- })
- .reply(HTTP_STATUS_OK, { path: '/test' });
-
- await submitForm();
+ submitForm();
await waitForPromises();
- expect(visitUrl).toHaveBeenCalledWith('/test');
+ expect(visitUrl).toHaveBeenCalledWith('path/to/environment');
});
+ });
- it('shows errors on error', async () => {
- mock
- .onPost(provide.projectEnvironmentsPath, {
- name: newName,
- external_url: newExternalUrl,
- })
- .reply(HTTP_STATUS_BAD_REQUEST, { message: ['name taken'] });
-
- await submitForm();
+ describe('when failed', () => {
+ beforeEach(async () => {
+ createWrapperWithApollo(environmentCreateError);
+ submitForm();
await waitForPromises();
+ });
- expect(createAlert).toHaveBeenCalledWith({ message: 'name taken' });
+ it('display errors', () => {
+ expect(createAlert).toHaveBeenCalledWith({ message: 'uh oh!' });
expect(showsLoading()).toBe(false);
});
});