Commit d7525c0e authored by Phil Hughes's avatar Phil Hughes

FIxes karma and EE entity specs

Fixes the JS tests by setting the mrData as a prop
Also fixes some tests by adding in the mock on the
network call
parent ad80dd6d
......@@ -80,10 +80,12 @@ export default {
},
},
data() {
const store = this.mrData ? new MRWidgetStore(this.mrData) : null;
return {
mr: null,
state: null,
service: null,
mr: store,
state: store && store.state,
service: store && this.createService(store),
};
},
computed: {
......@@ -131,12 +133,21 @@ export default {
}
},
},
created() {},
mounted() {
return MRWidgetService.fetchInitialData().then(({ data }) => {
this.mr = new MRWidgetStore({ ...window.gl.mrWidgetData, ...data });
this.state = this.mr.state;
this.service = this.createService(this.mr);
if (this.mr) {
this.mr.setData({ ...window.gl.mrWidgetData, ...data });
} else {
this.mr = new MRWidgetStore({ ...window.gl.mrWidgetData, ...data });
}
if (!this.state) {
this.state = this.mr.state;
}
if (!this.service) {
this.service = this.createService(this.mr);
}
this.setFaviconHelper();
this.initDeploymentsPolling();
......@@ -152,8 +163,13 @@ export default {
},
beforeDestroy() {
eventHub.$off('mr.discussion.updated', this.checkStatus);
this.pollingInterval.destroy();
this.deploymentsInterval.destroy();
if (this.pollingInterval) {
this.pollingInterval.destroy();
}
if (this.deploymentsInterval) {
this.deploymentsInterval.destroy();
}
if (this.postMergeDeploymentsInterval) {
this.postMergeDeploymentsInterval.destroy();
......
......@@ -3,6 +3,7 @@
class MergeRequestWidgetEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :iid
expose :source_project_full_path do |merge_request|
......
# frozen_string_literal: true
require 'spec_helper'
describe MergeRequestPollWidgetEntity do
include ProjectForksHelper
set(:user) { create(:user) }
set(:project) { create :project, :repository }
set(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:request) { double('request', current_user: user) }
before do
project.add_developer(user)
end
subject(:entity) do
described_class.new(merge_request, current_user: user, request: request)
end
describe 'Merge Trains' do
let!(:merge_train) { create(:merge_train, merge_request: merge_request) }
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true)
end
it 'has merge train entity' do
expect(subject.as_json).to include(:merge_trains_count)
expect(subject.as_json).to include(:merge_train_index)
end
context 'when the merge train feature is disabled' do
before do
stub_feature_flags(merge_trains_enabled: false)
end
it 'does not have merge trains count' do
expect(subject.as_json).not_to include(:merge_trains_count)
end
end
context 'when the merge request is not on a merge train' do
let!(:merge_train) { }
it 'does not have merge train index' do
expect(subject.as_json).not_to include(:merge_train_index)
end
end
end
end
......@@ -198,38 +198,6 @@ describe MergeRequestWidgetEntity do
expect(subject.as_json).to include(:pipeline_id)
end
describe 'Merge Trains' do
let!(:merge_train) { create(:merge_train, merge_request: merge_request) }
before do
stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.update!(merge_pipelines_enabled: true)
end
it 'has merge train entity' do
expect(subject.as_json).to include(:merge_trains_count)
expect(subject.as_json).to include(:merge_train_index)
end
context 'when the merge train feature is disabled' do
before do
stub_feature_flags(merge_trains_enabled: false)
end
it 'does not have merge trains count' do
expect(subject.as_json).not_to include(:merge_trains_count)
end
end
context 'when the merge request is not on a merge train' do
let!(:merge_train) { }
it 'does not have merge train index' do
expect(subject.as_json).not_to include(:merge_train_index)
end
end
end
describe 'blocking merge requests' do
set(:merge_request_block) { create(:merge_request_block, blocked_merge_request: merge_request) }
......
......@@ -1073,7 +1073,7 @@ describe Projects::MergeRequestsController do
end
it 'renders MergeRequest as JSON' do
expect(json_response.keys).to include('id', 'iid', 'description')
expect(json_response.keys).to include('id', 'iid')
end
end
......@@ -1107,7 +1107,7 @@ describe Projects::MergeRequestsController do
it 'renders MergeRequest as JSON' do
subject
expect(json_response.keys).to include('id', 'iid', 'description')
expect(json_response.keys).to include('id', 'iid')
end
end
......
......@@ -220,6 +220,7 @@ export default {
plain_diff_path: '/root/acets-app/merge_requests/22.diff',
merge_request_basic_path: '/root/acets-app/merge_requests/22.json?serializer=basic',
merge_request_widget_path: '/root/acets-app/merge_requests/22/widget.json',
merge_request_cached_widget_path: '/cached.json',
merge_check_path: '/root/acets-app/merge_requests/22/merge_check',
ci_environments_status_url: '/root/acets-app/merge_requests/22/ci_environments_status',
project_archived: false,
......
import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
import notify from '~/lib/utils/notify';
......@@ -16,6 +18,7 @@ const returnPromise = data =>
describe('mrWidgetOptions', () => {
let vm;
let mock;
let MrWidgetOptions;
const COLLABORATION_MESSAGE = 'Allows commits from members who can merge to the target branch';
......@@ -24,6 +27,12 @@ describe('mrWidgetOptions', () => {
// Prevent component mounting
delete mrWidgetOptions.el;
gl.mrWidgetData = { ...mockData };
mock = new MockAdapter(axios);
mock.onGet(mockData.merge_request_widget_path).reply(() => [200, { ...mockData }]);
mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, { ...mockData }]);
MrWidgetOptions = Vue.extend(mrWidgetOptions);
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
......@@ -32,6 +41,8 @@ describe('mrWidgetOptions', () => {
afterEach(() => {
vm.$destroy();
mock.restore();
gl.mrWidgetData = {};
});
describe('data', () => {
......@@ -305,59 +316,61 @@ describe('mrWidgetOptions', () => {
});
describe('bindEventHubListeners', () => {
it('should bind eventHub listeners', () => {
it('should bind eventHub listeners', done => {
spyOn(vm, 'checkStatus').and.returnValue(() => {});
spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData));
spyOn(vm, 'fetchActionsContent');
spyOn(vm.mr, 'setData');
spyOn(vm, 'resumePolling');
spyOn(vm, 'stopPolling');
spyOn(eventHub, '$on');
spyOn(eventHub, '$on').and.callThrough();
vm.bindEventHubListeners();
setTimeout(() => {
eventHub.$emit('SetBranchRemoveFlag', ['flag']);
eventHub.$emit('SetBranchRemoveFlag', ['flag']);
expect(vm.mr.isRemovingSourceBranch).toEqual('flag');
expect(vm.mr.isRemovingSourceBranch).toEqual('flag');
eventHub.$emit('FailedToMerge');
eventHub.$emit('FailedToMerge');
expect(vm.mr.state).toEqual('failedToMerge');
expect(vm.mr.state).toEqual('failedToMerge');
eventHub.$emit('UpdateWidgetData', mockData);
eventHub.$emit('UpdateWidgetData', mockData);
expect(vm.mr.setData).toHaveBeenCalledWith(mockData);
expect(vm.mr.setData).toHaveBeenCalledWith(mockData);
eventHub.$emit('EnablePolling');
eventHub.$emit('EnablePolling');
expect(vm.resumePolling).toHaveBeenCalled();
expect(vm.resumePolling).toHaveBeenCalled();
eventHub.$emit('DisablePolling');
eventHub.$emit('DisablePolling');
expect(vm.stopPolling).toHaveBeenCalled();
expect(vm.stopPolling).toHaveBeenCalled();
const listenersWithServiceRequest = {
MRWidgetUpdateRequested: true,
FetchActionsContent: true,
};
const listenersWithServiceRequest = {
MRWidgetUpdateRequested: true,
FetchActionsContent: true,
};
const allArgs = eventHub.$on.calls.allArgs();
allArgs.forEach(params => {
const eventName = params[0];
const callback = params[1];
const allArgs = eventHub.$on.calls.allArgs();
allArgs.forEach(params => {
const eventName = params[0];
const callback = params[1];
if (listenersWithServiceRequest[eventName]) {
listenersWithServiceRequest[eventName] = callback;
}
});
if (listenersWithServiceRequest[eventName]) {
listenersWithServiceRequest[eventName] = callback;
}
});
listenersWithServiceRequest.MRWidgetUpdateRequested();
listenersWithServiceRequest.MRWidgetUpdateRequested();
expect(vm.checkStatus).toHaveBeenCalled();
expect(vm.checkStatus).toHaveBeenCalled();
listenersWithServiceRequest.FetchActionsContent();
listenersWithServiceRequest.FetchActionsContent();
expect(vm.fetchActionsContent).toHaveBeenCalled();
expect(vm.fetchActionsContent).toHaveBeenCalled();
done();
});
});
});
......@@ -448,22 +461,30 @@ describe('mrWidgetOptions', () => {
});
describe('resumePolling', () => {
it('should call stopTimer on pollingInterval', () => {
spyOn(vm.pollingInterval, 'resume');
it('should call stopTimer on pollingInterval', done => {
setTimeout(() => {
spyOn(vm.pollingInterval, 'resume');
vm.resumePolling();
vm.resumePolling();
expect(vm.pollingInterval.resume).toHaveBeenCalled();
expect(vm.pollingInterval.resume).toHaveBeenCalled();
done();
});
});
});
describe('stopPolling', () => {
it('should call stopTimer on pollingInterval', () => {
spyOn(vm.pollingInterval, 'stopTimer');
it('should call stopTimer on pollingInterval', done => {
setTimeout(() => {
spyOn(vm.pollingInterval, 'stopTimer');
vm.stopPolling();
vm.stopPolling();
expect(vm.pollingInterval.stopTimer).toHaveBeenCalled();
expect(vm.pollingInterval.stopTimer).toHaveBeenCalled();
done();
});
});
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment