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:
Diffstat (limited to 'spec/frontend/ide/stores/getters_spec.js')
-rw-r--r--spec/frontend/ide/stores/getters_spec.js126
1 files changed, 107 insertions, 19 deletions
diff --git a/spec/frontend/ide/stores/getters_spec.js b/spec/frontend/ide/stores/getters_spec.js
index 6b66c87e205..06456cdb12a 100644
--- a/spec/frontend/ide/stores/getters_spec.js
+++ b/spec/frontend/ide/stores/getters_spec.js
@@ -6,25 +6,40 @@ import {
} from '~/ide/constants';
import {
MSG_CANNOT_PUSH_CODE,
- MSG_CANNOT_PUSH_CODE_SHORT,
+ MSG_CANNOT_PUSH_CODE_GO_TO_FORK,
+ MSG_CANNOT_PUSH_CODE_SHOULD_FORK,
MSG_CANNOT_PUSH_UNSIGNED,
MSG_CANNOT_PUSH_UNSIGNED_SHORT,
+ MSG_FORK,
+ MSG_GO_TO_FORK,
} from '~/ide/messages';
import { createStore } from '~/ide/stores';
import * as getters from '~/ide/stores/getters';
import { file } from '../helpers';
const TEST_PROJECT_ID = 'test_project';
+const TEST_IDE_PATH = '/test/ide/path';
+const TEST_FORK_PATH = '/test/fork/path';
describe('IDE store getters', () => {
let localState;
let localStore;
+ let origGon;
beforeEach(() => {
+ origGon = window.gon;
+
+ // Feature flag is defaulted to on in prod
+ window.gon = { features: { rejectUnsignedCommitsByGitlab: true } };
+
localStore = createStore();
localState = localStore.state;
});
+ afterEach(() => {
+ window.gon = origGon;
+ });
+
describe('activeFile', () => {
it('returns the current active file', () => {
localState.openFiles.push(file());
@@ -433,27 +448,100 @@ describe('IDE store getters', () => {
});
describe('canPushCodeStatus', () => {
- it.each`
- pushCode | rejectUnsignedCommits | expected
- ${true} | ${false} | ${{ isAllowed: true, message: '', messageShort: '' }}
- ${false} | ${false} | ${{ isAllowed: false, message: MSG_CANNOT_PUSH_CODE, messageShort: MSG_CANNOT_PUSH_CODE_SHORT }}
- ${false} | ${true} | ${{ isAllowed: false, message: MSG_CANNOT_PUSH_UNSIGNED, messageShort: MSG_CANNOT_PUSH_UNSIGNED_SHORT }}
- `(
- 'with pushCode="$pushCode" and rejectUnsignedCommits="$rejectUnsignedCommits"',
- ({ pushCode, rejectUnsignedCommits, expected }) => {
- localState.projects[TEST_PROJECT_ID] = {
- pushRules: {
- [PUSH_RULE_REJECT_UNSIGNED_COMMITS]: rejectUnsignedCommits,
+ it.each([
+ [
+ 'when can push code, and can push unsigned commits',
+ {
+ input: { pushCode: true, rejectUnsignedCommits: false },
+ output: { isAllowed: true, message: '', messageShort: '' },
+ },
+ ],
+ [
+ 'when cannot push code, and can push unsigned commits',
+ {
+ input: { pushCode: false, rejectUnsignedCommits: false },
+ output: {
+ isAllowed: false,
+ message: MSG_CANNOT_PUSH_CODE,
+ messageShort: MSG_CANNOT_PUSH_CODE,
},
- userPermissions: {
- [PERMISSION_PUSH_CODE]: pushCode,
+ },
+ ],
+ [
+ 'when cannot push code, and has ide_path in forkInfo',
+ {
+ input: {
+ pushCode: false,
+ rejectUnsignedCommits: false,
+ forkInfo: { ide_path: TEST_IDE_PATH },
},
- };
- localState.currentProjectId = TEST_PROJECT_ID;
+ output: {
+ isAllowed: false,
+ message: MSG_CANNOT_PUSH_CODE_GO_TO_FORK,
+ messageShort: MSG_CANNOT_PUSH_CODE,
+ action: { href: TEST_IDE_PATH, text: MSG_GO_TO_FORK },
+ },
+ },
+ ],
+ [
+ 'when cannot push code, and has fork_path in forkInfo',
+ {
+ input: {
+ pushCode: false,
+ rejectUnsignedCommits: false,
+ forkInfo: { fork_path: TEST_FORK_PATH },
+ },
+ output: {
+ isAllowed: false,
+ message: MSG_CANNOT_PUSH_CODE_SHOULD_FORK,
+ messageShort: MSG_CANNOT_PUSH_CODE,
+ action: { href: TEST_FORK_PATH, text: MSG_FORK, isForm: true },
+ },
+ },
+ ],
+ [
+ 'when can push code, but cannot push unsigned commits',
+ {
+ input: { pushCode: true, rejectUnsignedCommits: true },
+ output: {
+ isAllowed: false,
+ message: MSG_CANNOT_PUSH_UNSIGNED,
+ messageShort: MSG_CANNOT_PUSH_UNSIGNED_SHORT,
+ },
+ },
+ ],
+ [
+ 'when can push code, but cannot push unsigned commits, with reject_unsigned_commits_by_gitlab feature off',
+ {
+ input: {
+ pushCode: true,
+ rejectUnsignedCommits: true,
+ features: { rejectUnsignedCommitsByGitlab: false },
+ },
+ output: {
+ isAllowed: true,
+ message: '',
+ messageShort: '',
+ },
+ },
+ ],
+ ])('%s', (testName, { input, output }) => {
+ const { forkInfo, rejectUnsignedCommits, pushCode, features = {} } = input;
- expect(localStore.getters.canPushCodeStatus).toEqual(expected);
- },
- );
+ Object.assign(window.gon.features, features);
+ localState.links = { forkInfo };
+ localState.projects[TEST_PROJECT_ID] = {
+ pushRules: {
+ [PUSH_RULE_REJECT_UNSIGNED_COMMITS]: rejectUnsignedCommits,
+ },
+ userPermissions: {
+ [PERMISSION_PUSH_CODE]: pushCode,
+ },
+ };
+ localState.currentProjectId = TEST_PROJECT_ID;
+
+ expect(localStore.getters.canPushCodeStatus).toEqual(output);
+ });
});
describe('canPushCode', () => {