debian-mirror-gitlab/spec/javascripts/ide/components/commit_sidebar/actions_spec.js

77 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import Vue from 'vue';
import store from '~/ide/stores';
2019-07-07 11:18:12 +05:30
import consts from '~/ide/stores/modules/commit/constants';
2018-05-09 12:01:36 +05:30
import commitActions from '~/ide/components/commit_sidebar/actions.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from 'spec/ide/helpers';
2018-11-08 19:23:39 +05:30
import { projectData } from 'spec/ide/mock_data';
2018-05-09 12:01:36 +05:30
describe('IDE commit sidebar actions', () => {
let vm;
2019-07-07 11:18:12 +05:30
const createComponent = ({
hasMR = false,
commitAction = consts.COMMIT_TO_NEW_BRANCH,
mergeRequestsEnabled = true,
currentBranchId = 'master',
shouldCreateMR = false,
} = {}) => {
2018-05-09 12:01:36 +05:30
const Component = Vue.extend(commitActions);
vm = createComponentWithStore(Component, store);
2019-07-07 11:18:12 +05:30
vm.$store.state.currentBranchId = currentBranchId;
2018-11-08 19:23:39 +05:30
vm.$store.state.currentProjectId = 'abcproject';
2019-07-07 11:18:12 +05:30
vm.$store.state.commit.commitAction = commitAction;
2018-11-08 19:23:39 +05:30
Vue.set(vm.$store.state.projects, 'abcproject', { ...projectData });
2019-07-07 11:18:12 +05:30
vm.$store.state.projects.abcproject.merge_requests_enabled = mergeRequestsEnabled;
vm.$store.state.commit.shouldCreateMR = shouldCreateMR;
2018-05-09 12:01:36 +05:30
2019-07-07 11:18:12 +05:30
if (hasMR) {
vm.$store.state.currentMergeRequestId = '1';
vm.$store.state.projects[store.state.currentProjectId].mergeRequests[
store.state.currentMergeRequestId
] = { foo: 'bar' };
}
2018-05-09 12:01:36 +05:30
2019-07-07 11:18:12 +05:30
return vm.$mount();
};
2018-05-09 12:01:36 +05:30
afterEach(() => {
vm.$destroy();
resetStore(vm.$store);
});
2019-07-07 11:18:12 +05:30
it('renders 2 groups', () => {
createComponent();
expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2);
2018-05-09 12:01:36 +05:30
});
it('renders current branch text', () => {
2019-07-07 11:18:12 +05:30
createComponent();
2018-05-09 12:01:36 +05:30
expect(vm.$el.textContent).toContain('Commit to master branch');
});
2018-10-15 14:42:47 +05:30
2018-11-08 19:23:39 +05:30
it('hides merge request option when project merge requests are disabled', done => {
2019-07-07 11:18:12 +05:30
createComponent({ mergeRequestsEnabled: false });
2018-11-08 19:23:39 +05:30
vm.$nextTick(() => {
expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2);
expect(vm.$el.textContent).not.toContain('Create a new branch and merge request');
done();
});
});
2018-10-15 14:42:47 +05:30
describe('commitToCurrentBranchText', () => {
it('escapes current branch', () => {
2019-07-07 11:18:12 +05:30
const injectedSrc = '<img src="x" />';
createComponent({ currentBranchId: injectedSrc });
expect(vm.commitToCurrentBranchText).not.toContain(injectedSrc);
});
});
2018-05-09 12:01:36 +05:30
});