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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 21:06:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 21:06:28 +0300
commited3b1698883bd4ac2c4faf6c05c3a8155748bf91 (patch)
treee4725e36aaee9141e9ac4da66faf8a19edd74c2a /spec
parent05f4b2fb34dbb051b2ce5ddbc801ec42998c019c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/discussions_controller_spec.rb2
-rw-r--r--spec/frontend/ide/components/branches/search_list_spec.js81
-rw-r--r--spec/frontend/ide/mock_data.js228
-rw-r--r--spec/javascripts/ide/components/branches/search_list_spec.js80
-rw-r--r--spec/javascripts/ide/mock_data.js229
-rw-r--r--spec/lib/gitlab/experimentation_spec.rb156
-rw-r--r--spec/services/projects/after_import_service_spec.rb2
7 files changed, 469 insertions, 309 deletions
diff --git a/spec/controllers/projects/discussions_controller_spec.rb b/spec/controllers/projects/discussions_controller_spec.rb
index e30b28a4bd5..6ed822bbb10 100644
--- a/spec/controllers/projects/discussions_controller_spec.rb
+++ b/spec/controllers/projects/discussions_controller_spec.rb
@@ -189,7 +189,7 @@ describe Projects::DiscussionsController do
context "when vue_mr_discussions cookie is present" do
before do
- allow(controller).to receive(:cookies).and_return({ vue_mr_discussions: 'true' })
+ cookies[:vue_mr_discussions] = 'true'
end
it "renders discussion with serializer" do
diff --git a/spec/frontend/ide/components/branches/search_list_spec.js b/spec/frontend/ide/components/branches/search_list_spec.js
new file mode 100644
index 00000000000..5cfe1c25c6b
--- /dev/null
+++ b/spec/frontend/ide/components/branches/search_list_spec.js
@@ -0,0 +1,81 @@
+import { shallowMount, createLocalVue } from '@vue/test-utils';
+import Vuex from 'vuex';
+import { __ } from '~/locale';
+import List from '~/ide/components/branches/search_list.vue';
+import Item from '~/ide/components/branches/item.vue';
+import { GlLoadingIcon } from '@gitlab/ui';
+import { branches } from '../../mock_data';
+
+const localVue = createLocalVue();
+localVue.use(Vuex);
+
+describe('IDE branches search list', () => {
+ let wrapper;
+ const fetchBranchesMock = jest.fn();
+
+ const createComponent = (state, currentBranchId = 'branch') => {
+ const fakeStore = new Vuex.Store({
+ state: {
+ currentBranchId,
+ currentProjectId: 'project',
+ },
+ modules: {
+ branches: {
+ namespaced: true,
+ state: { isLoading: false, branches: [], ...state },
+ actions: {
+ fetchBranches: fetchBranchesMock,
+ },
+ },
+ },
+ });
+
+ wrapper = shallowMount(List, {
+ localVue,
+ store: fakeStore,
+ sync: false,
+ });
+ };
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ it('calls fetch on mounted', () => {
+ createComponent();
+ expect(fetchBranchesMock).toHaveBeenCalled();
+ });
+
+ it('renders loading icon when `isLoading` is true', () => {
+ createComponent({ isLoading: true });
+ expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
+ });
+
+ it('renders branches not found when search is not empty and branches list is empty', () => {
+ createComponent({ branches: [] });
+ wrapper.find('input[type="search"]').setValue('something');
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(wrapper.text()).toContain(__('No branches found'));
+ });
+ });
+
+ describe('with branches', () => {
+ it('renders list', () => {
+ createComponent({ branches });
+ const items = wrapper.findAll(Item);
+
+ expect(items.length).toBe(branches.length);
+ });
+
+ it('renders check next to active branch', () => {
+ const activeBranch = 'regular';
+ createComponent({ branches }, activeBranch);
+ const items = wrapper.findAll(Item).filter(w => w.props('isActive'));
+
+ expect(items.length).toBe(1);
+ expect(items.at(0).props('item').name).toBe(activeBranch);
+ });
+ });
+});
diff --git a/spec/frontend/ide/mock_data.js b/spec/frontend/ide/mock_data.js
new file mode 100644
index 00000000000..80eb15fe5a6
--- /dev/null
+++ b/spec/frontend/ide/mock_data.js
@@ -0,0 +1,228 @@
+import { TEST_HOST } from 'spec/test_constants';
+
+export const projectData = {
+ id: 1,
+ name: 'abcproject',
+ web_url: '',
+ avatar_url: '',
+ path: '',
+ name_with_namespace: 'namespace/abcproject',
+ branches: {
+ master: {
+ treeId: 'abcproject/master',
+ can_push: true,
+ commit: {
+ id: '123',
+ },
+ },
+ },
+ mergeRequests: {},
+ merge_requests_enabled: true,
+ default_branch: 'master',
+};
+
+export const pipelines = [
+ {
+ id: 1,
+ ref: 'master',
+ sha: '123',
+ details: {
+ status: {
+ icon: 'status_failed',
+ group: 'failed',
+ text: 'Failed',
+ },
+ },
+ commit: { id: '123' },
+ },
+ {
+ id: 2,
+ ref: 'master',
+ sha: '213',
+ details: {
+ status: {
+ icon: 'status_failed',
+ group: 'failed',
+ text: 'Failed',
+ },
+ },
+ commit: { id: '213' },
+ },
+];
+
+export const stages = [
+ {
+ dropdown_path: `${TEST_HOST}/testing`,
+ name: 'build',
+ status: {
+ icon: 'status_failed',
+ group: 'failed',
+ text: 'failed',
+ },
+ },
+ {
+ dropdown_path: 'testing',
+ name: 'test',
+ status: {
+ icon: 'status_failed',
+ group: 'failed',
+ text: 'failed',
+ },
+ },
+];
+
+export const jobs = [
+ {
+ id: 1,
+ name: 'test',
+ path: 'testing',
+ status: {
+ icon: 'status_success',
+ text: 'passed',
+ },
+ stage: 'test',
+ duration: 1,
+ started: new Date(),
+ },
+ {
+ id: 2,
+ name: 'test 2',
+ path: 'testing2',
+ status: {
+ icon: 'status_success',
+ text: 'passed',
+ },
+ stage: 'test',
+ duration: 1,
+ started: new Date(),
+ },
+ {
+ id: 3,
+ name: 'test 3',
+ path: 'testing3',
+ status: {
+ icon: 'status_success',
+ text: 'passed',
+ },
+ stage: 'test',
+ duration: 1,
+ started: new Date(),
+ },
+ {
+ id: 4,
+ name: 'test 4',
+ path: 'testing4',
+ status: {
+ icon: 'status_failed',
+ text: 'failed',
+ },
+ stage: 'build',
+ duration: 1,
+ started: new Date(),
+ },
+];
+
+export const fullPipelinesResponse = {
+ data: {
+ count: {
+ all: 2,
+ },
+ pipelines: [
+ {
+ id: '51',
+ path: 'test',
+ commit: {
+ id: '123',
+ },
+ details: {
+ status: {
+ icon: 'status_failed',
+ text: 'failed',
+ },
+ stages: [...stages],
+ },
+ },
+ {
+ id: '50',
+ commit: {
+ id: 'abc123def456ghi789jkl',
+ },
+ details: {
+ status: {
+ icon: 'status_success',
+ text: 'passed',
+ },
+ stages: [...stages],
+ },
+ },
+ ],
+ },
+};
+
+export const mergeRequests = [
+ {
+ id: 1,
+ iid: 1,
+ title: 'Test merge request',
+ project_id: 1,
+ web_url: `${TEST_HOST}/namespace/project-path/merge_requests/1`,
+ },
+];
+
+export const branches = [
+ {
+ id: 1,
+ name: 'master',
+ commit: {
+ message: 'Update master branch',
+ committed_date: '2018-08-01T00:20:05Z',
+ },
+ can_push: true,
+ protected: true,
+ default: true,
+ },
+ {
+ id: 2,
+ name: 'protected/no-access',
+ commit: {
+ message: 'Update some stuff',
+ committed_date: '2018-08-02T00:00:05Z',
+ },
+ can_push: false,
+ protected: true,
+ default: false,
+ },
+ {
+ id: 3,
+ name: 'protected/access',
+ commit: {
+ message: 'Update some stuff',
+ committed_date: '2018-08-02T00:00:05Z',
+ },
+ can_push: true,
+ protected: true,
+ default: false,
+ },
+ {
+ id: 4,
+ name: 'regular',
+ commit: {
+ message: 'Update some more stuff',
+ committed_date: '2018-06-30T00:20:05Z',
+ },
+ can_push: true,
+ protected: false,
+ default: false,
+ },
+ {
+ id: 5,
+ name: 'regular/no-access',
+ commit: {
+ message: 'Update some more stuff',
+ committed_date: '2018-06-30T00:20:05Z',
+ },
+ can_push: false,
+ protected: false,
+ default: false,
+ },
+];
diff --git a/spec/javascripts/ide/components/branches/search_list_spec.js b/spec/javascripts/ide/components/branches/search_list_spec.js
deleted file mode 100644
index 72a3c2d5dcd..00000000000
--- a/spec/javascripts/ide/components/branches/search_list_spec.js
+++ /dev/null
@@ -1,80 +0,0 @@
-import Vue from 'vue';
-import store from '~/ide/stores';
-import * as types from '~/ide/stores/modules/branches/mutation_types';
-import List from '~/ide/components/branches/search_list.vue';
-import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
-import { branches as testBranches } from '../../mock_data';
-import { resetStore } from '../../helpers';
-
-describe('IDE branches search list', () => {
- const Component = Vue.extend(List);
- let vm;
-
- beforeEach(() => {
- vm = createComponentWithStore(Component, store, {});
-
- spyOn(vm, 'fetchBranches');
-
- vm.$mount();
- });
-
- afterEach(() => {
- vm.$destroy();
-
- resetStore(store);
- });
-
- it('calls fetch on mounted', () => {
- expect(vm.fetchBranches).toHaveBeenCalledWith({
- search: '',
- });
- });
-
- it('renders loading icon', done => {
- vm.$store.state.branches.isLoading = true;
-
- vm.$nextTick()
- .then(() => {
- expect(vm.$el).toContainElement('.loading-container');
- })
- .then(done)
- .catch(done.fail);
- });
-
- it('renders branches not found when search is not empty', done => {
- vm.search = 'testing';
-
- vm.$nextTick(() => {
- expect(vm.$el).toContainText('No branches found');
-
- done();
- });
- });
-
- describe('with branches', () => {
- const currentBranch = testBranches[1];
-
- beforeEach(done => {
- vm.$store.state.currentBranchId = currentBranch.name;
- vm.$store.commit(`branches/${types.RECEIVE_BRANCHES_SUCCESS}`, testBranches);
-
- vm.$nextTick(done);
- });
-
- it('renders list', () => {
- const elementText = Array.from(vm.$el.querySelectorAll('li strong')).map(x =>
- x.textContent.trim(),
- );
-
- expect(elementText).toEqual(testBranches.map(x => x.name));
- });
-
- it('renders check next to active branch', () => {
- const checkedText = Array.from(vm.$el.querySelectorAll('li'))
- .filter(x => x.querySelector('.ide-search-list-current-icon svg'))
- .map(x => x.querySelector('strong').textContent.trim());
-
- expect(checkedText).toEqual([currentBranch.name]);
- });
- });
-});
diff --git a/spec/javascripts/ide/mock_data.js b/spec/javascripts/ide/mock_data.js
index 1c2e082489e..27f0ad01f54 100644
--- a/spec/javascripts/ide/mock_data.js
+++ b/spec/javascripts/ide/mock_data.js
@@ -1,228 +1 @@
-import { TEST_HOST } from '../test_constants';
-
-export const projectData = {
- id: 1,
- name: 'abcproject',
- web_url: '',
- avatar_url: '',
- path: '',
- name_with_namespace: 'namespace/abcproject',
- branches: {
- master: {
- treeId: 'abcproject/master',
- can_push: true,
- commit: {
- id: '123',
- },
- },
- },
- mergeRequests: {},
- merge_requests_enabled: true,
- default_branch: 'master',
-};
-
-export const pipelines = [
- {
- id: 1,
- ref: 'master',
- sha: '123',
- details: {
- status: {
- icon: 'status_failed',
- group: 'failed',
- text: 'Failed',
- },
- },
- commit: { id: '123' },
- },
- {
- id: 2,
- ref: 'master',
- sha: '213',
- details: {
- status: {
- icon: 'status_failed',
- group: 'failed',
- text: 'Failed',
- },
- },
- commit: { id: '213' },
- },
-];
-
-export const stages = [
- {
- dropdown_path: `${TEST_HOST}/testing`,
- name: 'build',
- status: {
- icon: 'status_failed',
- group: 'failed',
- text: 'failed',
- },
- },
- {
- dropdown_path: 'testing',
- name: 'test',
- status: {
- icon: 'status_failed',
- group: 'failed',
- text: 'failed',
- },
- },
-];
-
-export const jobs = [
- {
- id: 1,
- name: 'test',
- path: 'testing',
- status: {
- icon: 'status_success',
- text: 'passed',
- },
- stage: 'test',
- duration: 1,
- started: new Date(),
- },
- {
- id: 2,
- name: 'test 2',
- path: 'testing2',
- status: {
- icon: 'status_success',
- text: 'passed',
- },
- stage: 'test',
- duration: 1,
- started: new Date(),
- },
- {
- id: 3,
- name: 'test 3',
- path: 'testing3',
- status: {
- icon: 'status_success',
- text: 'passed',
- },
- stage: 'test',
- duration: 1,
- started: new Date(),
- },
- {
- id: 4,
- name: 'test 4',
- path: 'testing4',
- status: {
- icon: 'status_failed',
- text: 'failed',
- },
- stage: 'build',
- duration: 1,
- started: new Date(),
- },
-];
-
-export const fullPipelinesResponse = {
- data: {
- count: {
- all: 2,
- },
- pipelines: [
- {
- id: '51',
- path: 'test',
- commit: {
- id: '123',
- },
- details: {
- status: {
- icon: 'status_failed',
- text: 'failed',
- },
- stages: [...stages],
- },
- },
- {
- id: '50',
- commit: {
- id: 'abc123def456ghi789jkl',
- },
- details: {
- status: {
- icon: 'status_success',
- text: 'passed',
- },
- stages: [...stages],
- },
- },
- ],
- },
-};
-
-export const mergeRequests = [
- {
- id: 1,
- iid: 1,
- title: 'Test merge request',
- project_id: 1,
- web_url: `${TEST_HOST}/namespace/project-path/merge_requests/1`,
- },
-];
-
-export const branches = [
- {
- id: 1,
- name: 'master',
- commit: {
- message: 'Update master branch',
- committed_date: '2018-08-01T00:20:05Z',
- },
- can_push: true,
- protected: true,
- default: true,
- },
- {
- id: 2,
- name: 'protected/no-access',
- commit: {
- message: 'Update some stuff',
- committed_date: '2018-08-02T00:00:05Z',
- },
- can_push: false,
- protected: true,
- default: false,
- },
- {
- id: 3,
- name: 'protected/access',
- commit: {
- message: 'Update some stuff',
- committed_date: '2018-08-02T00:00:05Z',
- },
- can_push: true,
- protected: true,
- default: false,
- },
- {
- id: 4,
- name: 'regular',
- commit: {
- message: 'Update some more stuff',
- committed_date: '2018-06-30T00:20:05Z',
- },
- can_push: true,
- protected: false,
- default: false,
- },
- {
- id: 5,
- name: 'regular/no-access',
- commit: {
- message: 'Update some more stuff',
- committed_date: '2018-06-30T00:20:05Z',
- },
- can_push: false,
- protected: false,
- default: false,
- },
-];
+export * from '../../frontend/ide/mock_data';
diff --git a/spec/lib/gitlab/experimentation_spec.rb b/spec/lib/gitlab/experimentation_spec.rb
new file mode 100644
index 00000000000..4d473731f39
--- /dev/null
+++ b/spec/lib/gitlab/experimentation_spec.rb
@@ -0,0 +1,156 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Experimentation::ControllerConcern, type: :controller do
+ controller(ApplicationController) do
+ include Gitlab::Experimentation::ControllerConcern
+
+ def index
+ head :ok
+ end
+ end
+
+ describe '#set_experimentation_subject_id_cookie' do
+ before do
+ get :index
+ end
+
+ context 'cookie is present' do
+ before do
+ cookies[:experimentation_subject_id] = 'test'
+ end
+
+ it 'does not change the cookie' do
+ expect(cookies[:experimentation_subject_id]).to eq 'test'
+ end
+ end
+
+ context 'cookie is not present' do
+ it 'sets a permanent signed cookie' do
+ expect(cookies.permanent.signed[:experimentation_subject_id]).to be_present
+ end
+ end
+ end
+
+ describe '#experiment_enabled?' do
+ context 'cookie is not present' do
+ it 'calls Gitlab::Experimentation.enabled? with the name of the experiment and an experimentation_subject_index of nil' do
+ expect(Gitlab::Experimentation).to receive(:enabled?).with(:test_experiment, nil)
+ controller.experiment_enabled?(:test_experiment)
+ end
+ end
+
+ context 'cookie is present' do
+ before do
+ cookies.permanent.signed[:experimentation_subject_id] = 'abcd-1234'
+ get :index
+ end
+
+ it 'calls Gitlab::Experimentation.enabled? with the name of the experiment and an experimentation_subject_index of the modulo 100 of the hex value of the uuid' do
+ # 'abcd1234'.hex % 100 = 76
+ expect(Gitlab::Experimentation).to receive(:enabled?).with(:test_experiment, 76)
+ controller.experiment_enabled?(:test_experiment)
+ end
+ end
+ end
+end
+
+describe Gitlab::Experimentation do
+ before do
+ stub_const('Gitlab::Experimentation::EXPERIMENTS', {
+ test_experiment: {
+ feature_toggle: feature_toggle,
+ environment: environment,
+ enabled_ratio: enabled_ratio
+ }
+ })
+
+ stub_feature_flags(feature_toggle => true)
+ end
+
+ let(:feature_toggle) { :test_experiment_toggle }
+ let(:environment) { Rails.env.test? }
+ let(:enabled_ratio) { 0.1 }
+
+ describe '.enabled?' do
+ subject { described_class.enabled?(:test_experiment, experimentation_subject_index) }
+ let(:experimentation_subject_index) { 9 }
+
+ context 'feature toggle is enabled, we are on the right environment and we are selected' do
+ it { is_expected.to be_truthy }
+ end
+
+ describe 'experiment is not defined' do
+ it 'returns false' do
+ expect(described_class.enabled?(:missing_experiment, experimentation_subject_index)).to be_falsey
+ end
+ end
+
+ describe 'feature toggle' do
+ context 'feature toggle is not set' do
+ let(:feature_toggle) { nil }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'feature toggle is not set, but a feature with the experiment key as name does exist' do
+ before do
+ stub_feature_flags(test_experiment: false)
+ end
+
+ let(:feature_toggle) { nil }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'feature toggle is disabled' do
+ before do
+ stub_feature_flags(feature_toggle => false)
+ end
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe 'environment' do
+ context 'environment is not set' do
+ let(:environment) { nil }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'we are on the wrong environment' do
+ let(:environment) { ::Gitlab.com? }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe 'enabled ratio' do
+ context 'enabled ratio is not set' do
+ let(:enabled_ratio) { nil }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'experimentation_subject_index is not set' do
+ let(:experimentation_subject_index) { nil }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'experimentation_subject_index is an empty string' do
+ let(:experimentation_subject_index) { '' }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'experimentation_subject_index outside enabled ratio' do
+ let(:experimentation_subject_index) { 11 }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+ end
+end
diff --git a/spec/services/projects/after_import_service_spec.rb b/spec/services/projects/after_import_service_spec.rb
index 51d3fd18881..27e8f3c45ba 100644
--- a/spec/services/projects/after_import_service_spec.rb
+++ b/spec/services/projects/after_import_service_spec.rb
@@ -19,6 +19,8 @@ describe Projects::AfterImportService do
allow(housekeeping_service)
.to receive(:execute).and_yield
+
+ expect(housekeeping_service).to receive(:increment!)
end
it 'performs housekeeping' do