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>2021-04-20 17:36:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 17:36:54 +0300
commitf61bb2a16a514b71bf33aabbbb999d6732016a24 (patch)
tree9548caa89e60b4f40b99bbd1dac030420b812aa8 /spec/frontend/ide
parent35fc54e5d261f8898e390aea7c2f5ec5fdf0539d (diff)
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc42
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r--spec/frontend/ide/components/cannot_push_code_alert_spec.js72
-rw-r--r--spec/frontend/ide/components/commit_sidebar/form_spec.js6
-rw-r--r--spec/frontend/ide/components/ide_spec.js28
-rw-r--r--spec/frontend/ide/stores/getters_spec.js126
4 files changed, 203 insertions, 29 deletions
diff --git a/spec/frontend/ide/components/cannot_push_code_alert_spec.js b/spec/frontend/ide/components/cannot_push_code_alert_spec.js
new file mode 100644
index 00000000000..ff659ecdf3f
--- /dev/null
+++ b/spec/frontend/ide/components/cannot_push_code_alert_spec.js
@@ -0,0 +1,72 @@
+import { GlButton, GlAlert } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import { stubComponent } from 'helpers/stub_component';
+import CannotPushCodeAlert from '~/ide/components/cannot_push_code_alert.vue';
+
+const TEST_MESSAGE = 'Hello test message!';
+const TEST_HREF = '/test/path/to/fork';
+const TEST_BUTTON_TEXT = 'Fork text';
+
+describe('ide/components/cannot_push_code_alert', () => {
+ let wrapper;
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ const createComponent = (props = {}) => {
+ wrapper = shallowMount(CannotPushCodeAlert, {
+ propsData: {
+ message: TEST_MESSAGE,
+ ...props,
+ },
+ stubs: {
+ GlAlert: {
+ ...stubComponent(GlAlert),
+ template: `<div><slot></slot><slot name="actions"></slot></div>`,
+ },
+ },
+ });
+ };
+
+ const findAlert = () => wrapper.findComponent(GlAlert);
+ const findButtonData = () => {
+ const button = findAlert().findComponent(GlButton);
+
+ if (!button.exists()) {
+ return null;
+ }
+
+ return {
+ href: button.attributes('href'),
+ method: button.attributes('data-method'),
+ text: button.text(),
+ };
+ };
+
+ describe('without actions', () => {
+ beforeEach(() => {
+ createComponent();
+ });
+
+ it('shows alert with message', () => {
+ expect(findAlert().props()).toMatchObject({ dismissible: false });
+ expect(findAlert().text()).toBe(TEST_MESSAGE);
+ });
+ });
+
+ describe.each`
+ action | buttonData
+ ${{}} | ${null}
+ ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT }} | ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT }}
+ ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT, isForm: true }} | ${{ href: TEST_HREF, text: TEST_BUTTON_TEXT, method: 'post' }}
+ `('with action=$action', ({ action, buttonData }) => {
+ beforeEach(() => {
+ createComponent({ action });
+ });
+
+ it(`show button=${JSON.stringify(buttonData)}`, () => {
+ expect(findButtonData()).toEqual(buttonData);
+ });
+ });
+});
diff --git a/spec/frontend/ide/components/commit_sidebar/form_spec.js b/spec/frontend/ide/components/commit_sidebar/form_spec.js
index 083a2a73b24..f5916b021aa 100644
--- a/spec/frontend/ide/components/commit_sidebar/form_spec.js
+++ b/spec/frontend/ide/components/commit_sidebar/form_spec.js
@@ -14,7 +14,7 @@ import {
createBranchChangedCommitError,
branchAlreadyExistsCommitError,
} from '~/ide/lib/errors';
-import { MSG_CANNOT_PUSH_CODE_SHORT } from '~/ide/messages';
+import { MSG_CANNOT_PUSH_CODE } from '~/ide/messages';
import { createStore } from '~/ide/stores';
import { COMMIT_TO_NEW_BRANCH } from '~/ide/stores/modules/commit/constants';
@@ -85,8 +85,8 @@ describe('IDE commit form', () => {
${'when there are no changes'} | ${[]} | ${{ pushCode: true }} | ${goToEditView} | ${findBeginCommitButtonData} | ${true} | ${''}
${'when there are changes'} | ${['test']} | ${{ pushCode: true }} | ${goToEditView} | ${findBeginCommitButtonData} | ${false} | ${''}
${'when there are changes'} | ${['test']} | ${{ pushCode: true }} | ${goToCommitView} | ${findCommitButtonData} | ${false} | ${''}
- ${'when user cannot push'} | ${['test']} | ${{ pushCode: false }} | ${goToEditView} | ${findBeginCommitButtonData} | ${true} | ${MSG_CANNOT_PUSH_CODE_SHORT}
- ${'when user cannot push'} | ${['test']} | ${{ pushCode: false }} | ${goToCommitView} | ${findCommitButtonData} | ${true} | ${MSG_CANNOT_PUSH_CODE_SHORT}
+ ${'when user cannot push'} | ${['test']} | ${{ pushCode: false }} | ${goToEditView} | ${findBeginCommitButtonData} | ${true} | ${MSG_CANNOT_PUSH_CODE}
+ ${'when user cannot push'} | ${['test']} | ${{ pushCode: false }} | ${goToCommitView} | ${findCommitButtonData} | ${true} | ${MSG_CANNOT_PUSH_CODE}
`('$desc', ({ stagedFiles, userPermissions, viewFn, buttonFn, disabled, tooltip }) => {
beforeEach(async () => {
store.state.stagedFiles = stagedFiles;
diff --git a/spec/frontend/ide/components/ide_spec.js b/spec/frontend/ide/components/ide_spec.js
index bd251f78654..b23a78a035d 100644
--- a/spec/frontend/ide/components/ide_spec.js
+++ b/spec/frontend/ide/components/ide_spec.js
@@ -1,10 +1,10 @@
-import { GlAlert } from '@gitlab/ui';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';
import waitForPromises from 'helpers/wait_for_promises';
+import CannotPushCodeAlert from '~/ide/components/cannot_push_code_alert.vue';
import ErrorMessage from '~/ide/components/error_message.vue';
import Ide from '~/ide/components/ide.vue';
-import { MSG_CANNOT_PUSH_CODE } from '~/ide/messages';
+import { MSG_CANNOT_PUSH_CODE_GO_TO_FORK, MSG_GO_TO_FORK } from '~/ide/messages';
import { createStore } from '~/ide/stores';
import { file } from '../helpers';
import { projectData } from '../mock_data';
@@ -12,14 +12,15 @@ import { projectData } from '../mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
+const TEST_FORK_IDE_PATH = '/test/ide/path';
+
describe('WebIDE', () => {
const emptyProjData = { ...projectData, empty_repo: true, branches: {} };
+ let store;
let wrapper;
const createComponent = ({ projData = emptyProjData, state = {} } = {}) => {
- const store = createStore();
-
store.state.currentProjectId = 'abcproject';
store.state.currentBranchId = 'master';
store.state.projects.abcproject = projData && { ...projData };
@@ -37,7 +38,11 @@ describe('WebIDE', () => {
});
};
- const findAlert = () => wrapper.find(GlAlert);
+ const findAlert = () => wrapper.findComponent(CannotPushCodeAlert);
+
+ beforeEach(() => {
+ store = createStore();
+ });
afterEach(() => {
wrapper.destroy();
@@ -148,6 +153,12 @@ describe('WebIDE', () => {
});
it('when user cannot push code, shows alert', () => {
+ store.state.links = {
+ forkInfo: {
+ ide_path: TEST_FORK_IDE_PATH,
+ },
+ };
+
createComponent({
projData: {
userPermissions: {
@@ -157,9 +168,12 @@ describe('WebIDE', () => {
});
expect(findAlert().props()).toMatchObject({
- dismissible: false,
+ message: MSG_CANNOT_PUSH_CODE_GO_TO_FORK,
+ action: {
+ href: TEST_FORK_IDE_PATH,
+ text: MSG_GO_TO_FORK,
+ },
});
- expect(findAlert().text()).toBe(MSG_CANNOT_PUSH_CODE);
});
it.each`
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', () => {