summaryrefslogtreecommitdiff
path: root/spec/frontend/pipeline_new
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /spec/frontend/pipeline_new
parent4b1de649d0168371549608993deac953eb692019 (diff)
downloadgitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/frontend/pipeline_new')
-rw-r--r--spec/frontend/pipeline_new/components/pipeline_new_form_spec.js125
-rw-r--r--spec/frontend/pipeline_new/mock_data.js16
-rw-r--r--spec/frontend/pipeline_new/utils/format_refs_spec.js21
3 files changed, 120 insertions, 42 deletions
diff --git a/spec/frontend/pipeline_new/components/pipeline_new_form_spec.js b/spec/frontend/pipeline_new/components/pipeline_new_form_spec.js
index 197f646a22e..b42339f626e 100644
--- a/spec/frontend/pipeline_new/components/pipeline_new_form_spec.js
+++ b/spec/frontend/pipeline_new/components/pipeline_new_form_spec.js
@@ -5,7 +5,14 @@ import waitForPromises from 'helpers/wait_for_promises';
import httpStatusCodes from '~/lib/utils/http_status';
import axios from '~/lib/utils/axios_utils';
import PipelineNewForm from '~/pipeline_new/components/pipeline_new_form.vue';
-import { mockRefs, mockParams, mockPostParams, mockProjectId, mockError } from '../mock_data';
+import {
+ mockBranches,
+ mockTags,
+ mockParams,
+ mockPostParams,
+ mockProjectId,
+ mockError,
+} from '../mock_data';
import { redirectTo } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility', () => ({
@@ -37,6 +44,10 @@ describe('Pipeline New Form', () => {
const findWarnings = () => wrapper.findAll('[data-testid="run-pipeline-warning"]');
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const getExpectedPostParams = () => JSON.parse(mock.history.post[0].data);
+ const changeRef = i =>
+ findDropdownItems()
+ .at(i)
+ .vm.$emit('click');
const createComponent = (term = '', props = {}, method = shallowMount) => {
wrapper = method(PipelineNewForm, {
@@ -44,7 +55,8 @@ describe('Pipeline New Form', () => {
projectId: mockProjectId,
pipelinesPath,
configVariablesPath,
- refs: mockRefs,
+ branches: mockBranches,
+ tags: mockTags,
defaultBranch: 'master',
settingsLink: '',
maxWarnings: 25,
@@ -76,8 +88,11 @@ describe('Pipeline New Form', () => {
});
it('displays dropdown with all branches and tags', () => {
+ const refLength = mockBranches.length + mockTags.length;
+
createComponent();
- expect(findDropdownItems()).toHaveLength(mockRefs.length);
+
+ expect(findDropdownItems()).toHaveLength(refLength);
});
it('when user enters search term the list is filtered', () => {
@@ -130,15 +145,6 @@ describe('Pipeline New Form', () => {
expect(findVariableRows()).toHaveLength(2);
});
- it('creates a pipeline on submit', async () => {
- findForm().vm.$emit('submit', dummySubmitEvent);
-
- await waitForPromises();
-
- expect(getExpectedPostParams()).toEqual(mockPostParams);
- expect(redirectTo).toHaveBeenCalledWith(`${pipelinesPath}/${postResponse.id}`);
- });
-
it('creates blank variable on input change event', async () => {
const input = findKeyInputs().at(2);
input.element.value = 'test_var_2';
@@ -150,45 +156,81 @@ describe('Pipeline New Form', () => {
expect(findKeyInputs().at(3).element.value).toBe('');
expect(findValueInputs().at(3).element.value).toBe('');
});
+ });
- describe('when the form has been modified', () => {
- const selectRef = i =>
- findDropdownItems()
- .at(i)
- .vm.$emit('click');
+ describe('Pipeline creation', () => {
+ beforeEach(async () => {
+ mock.onPost(pipelinesPath).reply(httpStatusCodes.OK, postResponse);
- beforeEach(async () => {
- const input = findKeyInputs().at(0);
- input.element.value = 'test_var_2';
- input.trigger('change');
+ await waitForPromises();
+ });
+ it('creates pipeline with full ref and variables', async () => {
+ createComponent();
- findRemoveIcons()
- .at(1)
- .trigger('click');
+ changeRef(0);
- await wrapper.vm.$nextTick();
- });
+ findForm().vm.$emit('submit', dummySubmitEvent);
- it('form values are restored when the ref changes', async () => {
- expect(findVariableRows()).toHaveLength(2);
+ await waitForPromises();
- selectRef(1);
- await waitForPromises();
+ expect(getExpectedPostParams().ref).toEqual(wrapper.vm.$data.refValue.fullName);
+ expect(redirectTo).toHaveBeenCalledWith(`${pipelinesPath}/${postResponse.id}`);
+ });
+ it('creates a pipeline with short ref and variables', async () => {
+ // query params are used
+ createComponent('', mockParams);
- expect(findVariableRows()).toHaveLength(3);
- expect(findKeyInputs().at(0).element.value).toBe('test_var');
- });
+ await waitForPromises();
- it('form values are restored again when the ref is reverted', async () => {
- selectRef(1);
- await waitForPromises();
+ findForm().vm.$emit('submit', dummySubmitEvent);
- selectRef(2);
- await waitForPromises();
+ await waitForPromises();
- expect(findVariableRows()).toHaveLength(2);
- expect(findKeyInputs().at(0).element.value).toBe('test_var_2');
- });
+ expect(getExpectedPostParams()).toEqual(mockPostParams);
+ expect(redirectTo).toHaveBeenCalledWith(`${pipelinesPath}/${postResponse.id}`);
+ });
+ });
+
+ describe('When the ref has been changed', () => {
+ beforeEach(async () => {
+ createComponent('', {}, mount);
+
+ await waitForPromises();
+ });
+ it('variables persist between ref changes', async () => {
+ changeRef(0); // change to master
+
+ await waitForPromises();
+
+ const masterInput = findKeyInputs().at(0);
+ masterInput.element.value = 'build_var';
+ masterInput.trigger('change');
+
+ await wrapper.vm.$nextTick();
+
+ changeRef(1); // change to branch-1
+
+ await waitForPromises();
+
+ const branchOneInput = findKeyInputs().at(0);
+ branchOneInput.element.value = 'deploy_var';
+ branchOneInput.trigger('change');
+
+ await wrapper.vm.$nextTick();
+
+ changeRef(0); // change back to master
+
+ await waitForPromises();
+
+ expect(findKeyInputs().at(0).element.value).toBe('build_var');
+ expect(findVariableRows().length).toBe(2);
+
+ changeRef(1); // change back to branch-1
+
+ await waitForPromises();
+
+ expect(findKeyInputs().at(0).element.value).toBe('deploy_var');
+ expect(findVariableRows().length).toBe(2);
});
});
@@ -321,6 +363,7 @@ describe('Pipeline New Form', () => {
it('shows the correct warning title', () => {
const { length } = mockError.warnings;
+
expect(findWarningAlertSummary().attributes('message')).toBe(`${length} warnings found:`);
});
diff --git a/spec/frontend/pipeline_new/mock_data.js b/spec/frontend/pipeline_new/mock_data.js
index cdbd6d4437e..feb24ec602d 100644
--- a/spec/frontend/pipeline_new/mock_data.js
+++ b/spec/frontend/pipeline_new/mock_data.js
@@ -1,4 +1,14 @@
-export const mockRefs = ['master', 'branch-1', 'tag-1'];
+export const mockBranches = [
+ { shortName: 'master', fullName: 'refs/heads/master' },
+ { shortName: 'branch-1', fullName: 'refs/heads/branch-1' },
+ { shortName: 'branch-2', fullName: 'refs/heads/branch-2' },
+];
+
+export const mockTags = [
+ { shortName: '1.0.0', fullName: 'refs/tags/1.0.0' },
+ { shortName: '1.1.0', fullName: 'refs/tags/1.1.0' },
+ { shortName: '1.2.0', fullName: 'refs/tags/1.2.0' },
+];
export const mockParams = {
refParam: 'tag-1',
@@ -31,3 +41,7 @@ export const mockError = {
],
total_warnings: 7,
};
+
+export const mockBranchRefs = ['master', 'dev', 'release'];
+
+export const mockTagRefs = ['1.0.0', '1.1.0', '1.2.0'];
diff --git a/spec/frontend/pipeline_new/utils/format_refs_spec.js b/spec/frontend/pipeline_new/utils/format_refs_spec.js
new file mode 100644
index 00000000000..1fda6a8af83
--- /dev/null
+++ b/spec/frontend/pipeline_new/utils/format_refs_spec.js
@@ -0,0 +1,21 @@
+import formatRefs from '~/pipeline_new/utils/format_refs';
+import { BRANCH_REF_TYPE, TAG_REF_TYPE } from '~/pipeline_new/constants';
+import { mockBranchRefs, mockTagRefs } from '../mock_data';
+
+describe('Format refs util', () => {
+ it('formats branch ref correctly', () => {
+ expect(formatRefs(mockBranchRefs, BRANCH_REF_TYPE)).toEqual([
+ { fullName: 'refs/heads/master', shortName: 'master' },
+ { fullName: 'refs/heads/dev', shortName: 'dev' },
+ { fullName: 'refs/heads/release', shortName: 'release' },
+ ]);
+ });
+
+ it('formats tag ref correctly', () => {
+ expect(formatRefs(mockTagRefs, TAG_REF_TYPE)).toEqual([
+ { fullName: 'refs/tags/1.0.0', shortName: '1.0.0' },
+ { fullName: 'refs/tags/1.1.0', shortName: '1.1.0' },
+ { fullName: 'refs/tags/1.2.0', shortName: '1.2.0' },
+ ]);
+ });
+});