summaryrefslogtreecommitdiff
path: root/spec/frontend/ide
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 09:10:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 09:10:17 +0000
commitad0265eead72a624ce7a020847db4f0f0c877e57 (patch)
tree206e0564b02aa9530e3c95f70eb10a77e074bdf0 /spec/frontend/ide
parent4dfc8711171fe0c04bc6b8b224687603026dea46 (diff)
downloadgitlab-ce-ad0265eead72a624ce7a020847db4f0f0c877e57.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r--spec/frontend/ide/components/commit_sidebar/actions_spec.js32
-rw-r--r--spec/frontend/ide/stores/getters_spec.js49
-rw-r--r--spec/frontend/ide/stores/modules/commit/getters_spec.js11
3 files changed, 53 insertions, 39 deletions
diff --git a/spec/frontend/ide/components/commit_sidebar/actions_spec.js b/spec/frontend/ide/components/commit_sidebar/actions_spec.js
index b3b98a64891..a303e2b9bee 100644
--- a/spec/frontend/ide/components/commit_sidebar/actions_spec.js
+++ b/spec/frontend/ide/components/commit_sidebar/actions_spec.js
@@ -17,7 +17,11 @@ describe('IDE commit sidebar actions', () => {
let store;
let vm;
- const createComponent = ({ hasMR = false, currentBranchId = 'master' } = {}) => {
+ const createComponent = ({
+ hasMR = false,
+ currentBranchId = 'master',
+ emptyRepo = false,
+ } = {}) => {
const Component = Vue.extend(commitActions);
vm = createComponentWithStore(Component, store);
@@ -27,6 +31,7 @@ describe('IDE commit sidebar actions', () => {
const proj = { ...projectData };
proj.branches[currentBranchId] = branches.find(branch => branch.name === currentBranchId);
+ proj.empty_repo = emptyRepo;
Vue.set(vm.$store.state.projects, 'abcproject', proj);
@@ -52,24 +57,27 @@ describe('IDE commit sidebar actions', () => {
vm = null;
});
+ const findText = () => vm.$el.textContent;
+ const findRadios = () => Array.from(vm.$el.querySelectorAll('input[type="radio"]'));
+
it('renders 2 groups', () => {
createComponent();
- expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2);
+ expect(findRadios().length).toBe(2);
});
it('renders current branch text', () => {
createComponent();
- expect(vm.$el.textContent).toContain('Commit to master branch');
+ expect(findText()).toContain('Commit to master branch');
});
it('hides merge request option when project merge requests are disabled', done => {
- createComponent({ mergeRequestsEnabled: false });
+ createComponent({ hasMR: false });
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');
+ expect(findRadios().length).toBe(2);
+ expect(findText()).not.toContain('Create a new branch and merge request');
done();
});
@@ -119,6 +127,7 @@ describe('IDE commit sidebar actions', () => {
it.each`
input | expectedOption
${{ currentBranchId: BRANCH_DEFAULT }} | ${consts.COMMIT_TO_NEW_BRANCH}
+ ${{ currentBranchId: BRANCH_DEFAULT, emptyRepo: true }} | ${consts.COMMIT_TO_CURRENT_BRANCH}
${{ currentBranchId: BRANCH_PROTECTED, hasMR: true }} | ${consts.COMMIT_TO_CURRENT_BRANCH}
${{ currentBranchId: BRANCH_PROTECTED, hasMR: false }} | ${consts.COMMIT_TO_CURRENT_BRANCH}
${{ currentBranchId: BRANCH_PROTECTED_NO_ACCESS, hasMR: true }} | ${consts.COMMIT_TO_NEW_BRANCH}
@@ -138,4 +147,15 @@ describe('IDE commit sidebar actions', () => {
},
);
});
+
+ describe('when empty project', () => {
+ beforeEach(() => {
+ createComponent({ emptyRepo: true });
+ });
+
+ it('only renders commit to current branch', () => {
+ expect(findRadios().length).toBe(1);
+ expect(findText()).toContain('Commit to master branch');
+ });
+ });
});
diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js
index 011be95c1d2..408ea2b2939 100644
--- a/spec/frontend/ide/stores/getters_spec.js
+++ b/spec/frontend/ide/stores/getters_spec.js
@@ -280,39 +280,21 @@ describe('IDE store getters', () => {
});
describe('canPushToBranch', () => {
- it('returns false when no currentBranch exists', () => {
- const localGetters = {
- currentProject: undefined,
- };
-
- expect(getters.canPushToBranch({}, localGetters)).toBeFalsy();
- });
-
- it('returns true when can_push to currentBranch', () => {
- const localGetters = {
- currentProject: {
- default_branch: 'master',
- },
- currentBranch: {
- can_push: true,
- },
- };
-
- expect(getters.canPushToBranch({}, localGetters)).toBeTruthy();
- });
-
- it('returns false when !can_push to currentBranch', () => {
- const localGetters = {
- currentProject: {
- default_branch: 'master',
- },
- currentBranch: {
- can_push: false,
- },
- };
-
- expect(getters.canPushToBranch({}, localGetters)).toBeFalsy();
- });
+ it.each`
+ currentBranch | canPushCode | expectedValue
+ ${undefined} | ${undefined} | ${false}
+ ${{ can_push: true }} | ${false} | ${true}
+ ${{ can_push: true }} | ${true} | ${true}
+ ${{ can_push: false }} | ${false} | ${false}
+ ${{ can_push: false }} | ${true} | ${false}
+ ${undefined} | ${true} | ${true}
+ ${undefined} | ${false} | ${false}
+ `(
+ 'with currentBranch ($currentBranch) and canPushCode ($canPushCode), it is $expectedValue',
+ ({ currentBranch, canPushCode, expectedValue }) => {
+ expect(getters.canPushToBranch({}, { currentBranch, canPushCode })).toBe(expectedValue);
+ },
+ );
});
describe('isFileDeletedAndReadded', () => {
@@ -422,6 +404,7 @@ describe('IDE store getters', () => {
getterName | permissionKey
${'canReadMergeRequests'} | ${'readMergeRequest'}
${'canCreateMergeRequests'} | ${'createMergeRequestIn'}
+ ${'canPushCode'} | ${'pushCode'}
`('$getterName', ({ getterName, permissionKey }) => {
it.each([true, false])('finds permission for current project (%s)', val => {
localState.projects[TEST_PROJECT_ID] = {
diff --git a/spec/frontend/ide/stores/modules/commit/getters_spec.js b/spec/frontend/ide/stores/modules/commit/getters_spec.js
index 07445c22917..adbfd7c6835 100644
--- a/spec/frontend/ide/stores/modules/commit/getters_spec.js
+++ b/spec/frontend/ide/stores/modules/commit/getters_spec.js
@@ -292,4 +292,15 @@ describe('IDE commit module getters', () => {
expect(getters.shouldHideNewMrOption(state, localGetters, null, rootGetters)).toBeFalsy();
});
});
+
+ describe('shouldDisableNewMrOption', () => {
+ it.each`
+ rootGetters | expectedValue
+ ${{ canCreateMergeRequests: false, emptyRepo: false }} | ${true}
+ ${{ canCreateMergeRequests: true, emptyRepo: true }} | ${true}
+ ${{ canCreateMergeRequests: true, emptyRepo: false }} | ${false}
+ `('with $rootGetters, it is $expectedValue', ({ rootGetters, expectedValue }) => {
+ expect(getters.shouldDisableNewMrOption(state, getters, {}, rootGetters)).toBe(expectedValue);
+ });
+ });
});