Commit 7f35475b authored by Himanshu Kapoor's avatar Himanshu Kapoor

Migrate all specs in vue_mr_widget to Jest

Migrate all tests in spec/javascripts/vue_mr_widget to Jest.
parent 44938087
......@@ -6,7 +6,7 @@ import {
issuable3,
issuable4,
issuable5,
} from 'spec/vue_shared/components/issue/related_issuable_mock_data';
} from 'jest/vue_shared/components/issue/related_issuable_mock_data';
describe('RelatedIssuesStore', () => {
let store;
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import MrWidgetAuthor from '~/vue_merge_request_widget/components/mr_widget_author.vue';
describe('MrWidgetAuthor', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import MrWidgetAuthorTime from '~/vue_merge_request_widget/components/mr_widget_author_time.vue';
describe('MrWidgetAuthorTime', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import headerComponent from '~/vue_merge_request_widget/components/mr_widget_header.vue';
describe('MRWidgetHeader', () => {
......
import Vue from 'vue';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import MemoryUsage from '~/vue_merge_request_widget/components/deployment/memory_usage.vue';
import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service';
......@@ -59,12 +61,20 @@ const messages = {
describe('MemoryUsage', () => {
let vm;
let el;
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
mock.onGet(`${url}.json`).reply(200);
vm = createComponent();
el = vm.$el;
});
afterEach(() => {
mock.restore();
});
describe('data', () => {
it('should have default data', () => {
const data = MemoryUsage.data();
......@@ -127,6 +137,9 @@ describe('MemoryUsage', () => {
describe('computeGraphData', () => {
it('should populate sparkline graph', () => {
// ignore BoostrapVue warnings
jest.spyOn(console, 'warn').mockImplementation();
vm.computeGraphData(metrics, deployment_time);
const { hasMetrics, memoryMetrics, deploymentTime, memoryFrom, memoryTo } = vm;
......@@ -147,15 +160,15 @@ describe('MemoryUsage', () => {
});
it('should load metrics data using MRWidgetService', done => {
spyOn(MRWidgetService, 'fetchMetrics').and.returnValue(returnServicePromise(true));
spyOn(vm, 'computeGraphData');
jest.spyOn(MRWidgetService, 'fetchMetrics').mockReturnValue(returnServicePromise(true));
jest.spyOn(vm, 'computeGraphData').mockImplementation(() => {});
vm.loadMetrics();
setTimeout(() => {
setImmediate(() => {
expect(MRWidgetService.fetchMetrics).toHaveBeenCalledWith(url);
expect(vm.computeGraphData).toHaveBeenCalledWith(metrics, deployment_time);
done();
}, 333);
});
});
});
});
......@@ -182,6 +195,9 @@ describe('MemoryUsage', () => {
});
it('should show deployment memory usage when metrics are loaded', done => {
// ignore BoostrapVue warnings
jest.spyOn(console, 'warn').mockImplementation();
vm.loadingMetrics = false;
vm.hasMetrics = true;
vm.loadFailed = false;
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import mergeHelpComponent from '~/vue_merge_request_widget/components/mr_widget_merge_help.vue';
describe('MRWidgetMergeHelp', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { trimText } from 'spec/helpers/text_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { trimText } from 'helpers/text_helper';
import pipelineComponent from '~/vue_merge_request_widget/components/mr_widget_pipeline.vue';
import mockData from '../mock_data';
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import eventHub from '~/vue_merge_request_widget/event_hub';
import component from '~/vue_merge_request_widget/components/states/mr_widget_rebase.vue';
......@@ -105,7 +105,7 @@ describe('Merge request widget rebase component', () => {
describe('methods', () => {
it('checkRebaseStatus', done => {
spyOn(eventHub, '$emit');
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
vm = mountComponent(Component, {
mr: {},
service: {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import relatedLinksComponent from '~/vue_merge_request_widget/components/mr_widget_related_links.vue';
describe('MRWidgetRelatedLinks', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import mrStatusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon.vue';
describe('MR widget status icon component', () => {
......
import Vue from 'vue';
import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper';
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
import component from '~/vue_merge_request_widget/components/review_app_link.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
......@@ -42,7 +42,7 @@ describe('review app link', () => {
});
it('tracks an event when clicked', () => {
const spy = mockTracking('_category_', el, spyOn);
const spy = mockTracking('_category_', el, jest.spyOn);
triggerEvent(el);
expect(spy).toHaveBeenCalledWith('_category_', 'open_review_app', {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import archivedComponent from '~/vue_merge_request_widget/components/states/mr_widget_archived.vue';
describe('MRWidgetArchived', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { trimText } from 'spec/helpers/text_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { trimText } from 'helpers/text_helper';
import autoMergeEnabledComponent from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_enabled.vue';
import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service';
import eventHub from '~/vue_merge_request_widget/event_hub';
......@@ -14,7 +14,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
beforeEach(() => {
const Component = Vue.extend(autoMergeEnabledComponent);
spyOn(eventHub, '$emit');
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
vm = mountComponent(Component, {
mr: {
......@@ -103,7 +103,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
const mrObj = {
is_new_mr_data: true,
};
spyOn(vm.service, 'cancelAutomaticMerge').and.returnValue(
jest.spyOn(vm.service, 'cancelAutomaticMerge').mockReturnValue(
new Promise(resolve => {
resolve({
data: mrObj,
......@@ -112,17 +112,17 @@ describe('MRWidgetAutoMergeEnabled', () => {
);
vm.cancelAutomaticMerge();
setTimeout(() => {
setImmediate(() => {
expect(vm.isCancellingAutoMerge).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('UpdateWidgetData', mrObj);
done();
}, 333);
});
});
});
describe('removeSourceBranch', () => {
it('should set flag and call service then request main component to update the widget', done => {
spyOn(vm.service, 'merge').and.returnValue(
jest.spyOn(vm.service, 'merge').mockReturnValue(
Promise.resolve({
data: {
status: MWPS_MERGE_STRATEGY,
......@@ -131,7 +131,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
);
vm.removeSourceBranch();
setTimeout(() => {
setImmediate(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
expect(vm.service.merge).toHaveBeenCalledWith({
sha,
......@@ -139,7 +139,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
should_remove_source_branch: true,
});
done();
}, 333);
});
});
});
});
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import checkingComponent from '~/vue_merge_request_widget/components/states/mr_widget_checking.vue';
describe('MRWidgetChecking', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import closedComponent from '~/vue_merge_request_widget/components/states/mr_widget_closed.vue';
describe('MRWidgetClosed', () => {
......
import $ from 'jquery';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { removeBreakLine } from 'spec/helpers/text_helper';
import { removeBreakLine } from 'helpers/text_helper';
import ConflictsComponent from '~/vue_merge_request_widget/components/states/mr_widget_conflicts.vue';
import { TEST_HOST } from 'helpers/test_constants';
describe('MRWidgetConflicts', () => {
let vm;
......@@ -16,7 +17,7 @@ describe('MRWidgetConflicts', () => {
}
beforeEach(() => {
spyOn($.fn, 'popover').and.callThrough();
jest.spyOn($.fn, 'popover');
});
afterEach(() => {
......@@ -185,7 +186,7 @@ describe('MRWidgetConflicts', () => {
mr: {
canMerge: true,
canPushToSourceBranch: true,
conflictResolutionPath: gl.TEST_HOST,
conflictResolutionPath: TEST_HOST,
sourceBranchProtected: true,
conflictsDocsPath: '',
},
......@@ -207,7 +208,7 @@ describe('MRWidgetConflicts', () => {
mr: {
canMerge: true,
canPushToSourceBranch: true,
conflictResolutionPath: gl.TEST_HOST,
conflictResolutionPath: TEST_HOST,
sourceBranchProtected: false,
conflictsDocsPath: '',
},
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import failedToMergeComponent from '~/vue_merge_request_widget/components/states/mr_widget_failed_to_merge.vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
......@@ -11,9 +11,9 @@ describe('MRWidgetFailedToMerge', () => {
beforeEach(() => {
Component = Vue.extend(failedToMergeComponent);
spyOn(eventHub, '$emit');
spyOn(window, 'setInterval').and.returnValue(dummyIntervalId);
spyOn(window, 'clearInterval').and.stub();
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest.spyOn(window, 'setInterval').mockReturnValue(dummyIntervalId);
jest.spyOn(window, 'clearInterval').mockImplementation();
mr = {
mergeError: 'Merge error happened',
};
......@@ -83,7 +83,7 @@ describe('MRWidgetFailedToMerge', () => {
describe('updateTimer', () => {
it('should update timer and emit event when timer end', () => {
spyOn(vm, 'refresh');
jest.spyOn(vm, 'refresh').mockImplementation(() => {});
expect(vm.timer).toEqual(10);
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import mergedComponent from '~/vue_merge_request_widget/components/states/mr_widget_merged.vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
......@@ -52,7 +52,7 @@ describe('MRWidgetMerged', () => {
removeSourceBranch() {},
};
spyOn(eventHub, '$emit');
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
vm = mountComponent(Component, { mr, service });
});
......@@ -124,7 +124,7 @@ describe('MRWidgetMerged', () => {
describe('methods', () => {
describe('removeSourceBranch', () => {
it('should set flag and call service then request main component to update the widget', done => {
spyOn(vm.service, 'removeSourceBranch').and.returnValue(
jest.spyOn(vm.service, 'removeSourceBranch').mockReturnValue(
new Promise(resolve => {
resolve({
data: {
......@@ -135,14 +135,14 @@ describe('MRWidgetMerged', () => {
);
vm.removeSourceBranch();
setTimeout(() => {
const args = eventHub.$emit.calls.argsFor(0);
setImmediate(() => {
const args = eventHub.$emit.mock.calls[0];
expect(vm.isMakingRequest).toEqual(true);
expect(args[0]).toEqual('MRWidgetUpdateRequested');
expect(args[1]).not.toThrow();
done();
}, 333);
});
});
});
});
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import mergingComponent from '~/vue_merge_request_widget/components/states/mr_widget_merging.vue';
describe('MRWidgetMerging', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import missingBranchComponent from '~/vue_merge_request_widget/components/states/mr_widget_missing_branch.vue';
describe('MRWidgetMissingBranch', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import notAllowedComponent from '~/vue_merge_request_widget/components/states/mr_widget_not_allowed.vue';
describe('MRWidgetNotAllowed', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { removeBreakLine } from 'spec/helpers/text_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { removeBreakLine } from 'helpers/text_helper';
import pipelineBlockedComponent from '~/vue_merge_request_widget/components/states/mr_widget_pipeline_blocked.vue';
describe('MRWidgetPipelineBlocked', () => {
......
import Vue from 'vue';
import { removeBreakLine } from 'spec/helpers/text_helper';
import { removeBreakLine } from 'helpers/text_helper';
import PipelineFailed from '~/vue_merge_request_widget/components/states/pipeline_failed.vue';
describe('PipelineFailed', () => {
......
......@@ -7,6 +7,15 @@ import CommitEdit from '~/vue_merge_request_widget/components/states/commit_edit
import CommitMessageDropdown from '~/vue_merge_request_widget/components/states/commit_message_dropdown.vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
import { MWPS_MERGE_STRATEGY, MTWPS_MERGE_STRATEGY } from '~/vue_merge_request_widget/constants';
import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
import simplePoll from '~/lib/utils/simple_poll';
jest.mock('~/lib/utils/simple_poll', () =>
jest.fn().mockImplementation(jest.requireActual('~/lib/utils/simple_poll').default),
);
jest.mock('~/commons/nav/user_merge_requests', () => ({
refreshUserMergeRequestCounts: jest.fn(),
}));
const commitMessage = 'This is the commit message';
const squashCommitMessage = 'This is the squash commit message';
......@@ -33,6 +42,7 @@ const createTestMr = customConfig => {
targetBranch: 'master',
preferredAutoMergeStrategy: MWPS_MERGE_STRATEGY,
availableAutoMergeStrategies: [MWPS_MERGE_STRATEGY],
mergeImmediatelyDocsPath: 'path/to/merge/immediately/docs',
};
Object.assign(mr, customConfig.mr);
......@@ -41,8 +51,8 @@ const createTestMr = customConfig => {
};
const createTestService = () => ({
merge() {},
poll() {},
merge: jest.fn(),
poll: jest.fn().mockResolvedValue(),
});
const createComponent = (customConfig = {}) => {
......@@ -59,11 +69,9 @@ const createComponent = (customConfig = {}) => {
describe('ReadyToMerge', () => {
let vm;
let updateMrCountSpy;
beforeEach(() => {
vm = createComponent();
updateMrCountSpy = spyOnDependency(ReadyToMerge, 'refreshUserMergeRequestCounts');
});
afterEach(() => {
......@@ -347,19 +355,21 @@ describe('ReadyToMerge', () => {
});
it('should handle merge when pipeline succeeds', done => {
spyOn(eventHub, '$emit');
spyOn(vm.service, 'merge').and.returnValue(returnPromise('merge_when_pipeline_succeeds'));
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest
.spyOn(vm.service, 'merge')
.mockReturnValue(returnPromise('merge_when_pipeline_succeeds'));
vm.removeSourceBranch = false;
vm.handleMergeButtonClick(true);
setTimeout(() => {
setImmediate(() => {
expect(vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
const params = vm.service.merge.calls.argsFor(0)[0];
const params = vm.service.merge.mock.calls[0][0];
expect(params).toEqual(
jasmine.objectContaining({
expect.objectContaining({
sha: vm.mr.sha,
commit_message: vm.mr.commitMessage,
should_remove_source_branch: false,
......@@ -367,67 +377,56 @@ describe('ReadyToMerge', () => {
}),
);
done();
}, 333);
});
});
it('should handle merge failed', done => {
spyOn(eventHub, '$emit');
spyOn(vm.service, 'merge').and.returnValue(returnPromise('failed'));
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest.spyOn(vm.service, 'merge').mockReturnValue(returnPromise('failed'));
vm.handleMergeButtonClick(false, true);
setTimeout(() => {
setImmediate(() => {
expect(vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('FailedToMerge', undefined);
const params = vm.service.merge.calls.argsFor(0)[0];
const params = vm.service.merge.mock.calls[0][0];
expect(params.should_remove_source_branch).toBeTruthy();
expect(params.auto_merge_strategy).toBeUndefined();
done();
}, 333);
});
});
it('should handle merge action accepted case', done => {
spyOn(vm.service, 'merge').and.returnValue(returnPromise('success'));
spyOn(vm, 'initiateMergePolling');
jest.spyOn(vm.service, 'merge').mockReturnValue(returnPromise('success'));
jest.spyOn(vm, 'initiateMergePolling').mockImplementation(() => {});
vm.handleMergeButtonClick();
setTimeout(() => {
setImmediate(() => {
expect(vm.isMakingRequest).toBeTruthy();
expect(vm.initiateMergePolling).toHaveBeenCalled();
const params = vm.service.merge.calls.argsFor(0)[0];
const params = vm.service.merge.mock.calls[0][0];
expect(params.should_remove_source_branch).toBeTruthy();
expect(params.auto_merge_strategy).toBeUndefined();
done();
}, 333);
});
});
});
describe('initiateMergePolling', () => {
beforeEach(() => {
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('should call simplePoll', () => {
const simplePoll = spyOnDependency(ReadyToMerge, 'simplePoll');
vm.initiateMergePolling();
expect(simplePoll).toHaveBeenCalledWith(jasmine.any(Function), { timeout: 0 });
expect(simplePoll).toHaveBeenCalledWith(expect.any(Function), { timeout: 0 });
});
it('should call handleMergePolling', () => {
spyOn(vm, 'handleMergePolling');
jest.spyOn(vm, 'handleMergePolling').mockImplementation(() => {});
vm.initiateMergePolling();
jasmine.clock().tick(2000);
expect(vm.handleMergePolling).toHaveBeenCalled();
});
});
......@@ -448,9 +447,9 @@ describe('ReadyToMerge', () => {
});
it('should call start and stop polling when MR merged', done => {
spyOn(eventHub, '$emit');
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise('merged'));
jest.spyOn(vm, 'initiateRemoveSourceBranchPolling').mockImplementation(() => {});
let cpc = false; // continuePollingCalled
let spc = false; // stopPollingCalled
......@@ -463,26 +462,26 @@ describe('ReadyToMerge', () => {
spc = true;
},
);
setTimeout(() => {
setImmediate(() => {
expect(vm.service.poll).toHaveBeenCalled();
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
expect(eventHub.$emit).toHaveBeenCalledWith('FetchActionsContent');
expect(vm.initiateRemoveSourceBranchPolling).toHaveBeenCalled();
expect(updateMrCountSpy).toHaveBeenCalled();
expect(refreshUserMergeRequestCounts).toHaveBeenCalled();
expect(cpc).toBeFalsy();
expect(spc).toBeTruthy();
done();
}, 333);
});
});
it('updates status box', done => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise('merged'));
jest.spyOn(vm, 'initiateRemoveSourceBranchPolling').mockImplementation(() => {});
vm.handleMergePolling(() => {}, () => {});
setTimeout(() => {
setImmediate(() => {
const statusBox = document.querySelector('.status-box');
expect(statusBox.classList.contains('status-box-mr-merged')).toBeTruthy();
......@@ -493,12 +492,12 @@ describe('ReadyToMerge', () => {
});
it('hides close button', done => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise('merged'));
jest.spyOn(vm, 'initiateRemoveSourceBranchPolling').mockImplementation(() => {});
vm.handleMergePolling(() => {}, () => {});
setTimeout(() => {
setImmediate(() => {
expect(document.querySelector('.btn-close').classList.contains('hidden')).toBeTruthy();
done();
......@@ -506,12 +505,12 @@ describe('ReadyToMerge', () => {
});
it('updates merge request count badge', done => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise('merged'));
jest.spyOn(vm, 'initiateRemoveSourceBranchPolling').mockImplementation(() => {});
vm.handleMergePolling(() => {}, () => {});
setTimeout(() => {
setImmediate(() => {
expect(document.querySelector('.js-merge-counter').textContent).toBe('0');
done();
......@@ -519,8 +518,8 @@ describe('ReadyToMerge', () => {
});
it('should continue polling until MR is merged', done => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('some_other_state'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise('some_other_state'));
jest.spyOn(vm, 'initiateRemoveSourceBranchPolling').mockImplementation(() => {});
let cpc = false; // continuePollingCalled
let spc = false; // stopPollingCalled
......@@ -533,19 +532,18 @@ describe('ReadyToMerge', () => {
spc = true;
},
);
setTimeout(() => {
setImmediate(() => {
expect(cpc).toBeTruthy();
expect(spc).toBeFalsy();
done();
}, 333);
});
});
});
describe('initiateRemoveSourceBranchPolling', () => {
it('should emit event and call simplePoll', () => {
spyOn(eventHub, '$emit');
const simplePoll = spyOnDependency(ReadyToMerge, 'simplePoll');
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
vm.initiateRemoveSourceBranchPolling();
......@@ -565,8 +563,8 @@ describe('ReadyToMerge', () => {
});
it('should call start and stop polling when MR merged', done => {
spyOn(eventHub, '$emit');
spyOn(vm.service, 'poll').and.returnValue(returnPromise(false));
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise(false));
let cpc = false; // continuePollingCalled
let spc = false; // stopPollingCalled
......@@ -579,10 +577,10 @@ describe('ReadyToMerge', () => {
spc = true;
},
);
setTimeout(() => {
setImmediate(() => {
expect(vm.service.poll).toHaveBeenCalled();
const args = eventHub.$emit.calls.argsFor(0);
const args = eventHub.$emit.mock.calls[0];
expect(args[0]).toEqual('MRWidgetUpdateRequested');
expect(args[1]).toBeDefined();
......@@ -594,11 +592,11 @@ describe('ReadyToMerge', () => {
expect(spc).toBeTruthy();
done();
}, 333);
});
});
it('should continue polling until MR is merged', done => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise(true));
jest.spyOn(vm.service, 'poll').mockReturnValue(returnPromise(true));
let cpc = false; // continuePollingCalled
let spc = false; // stopPollingCalled
......@@ -611,12 +609,12 @@ describe('ReadyToMerge', () => {
spc = true;
},
);
setTimeout(() => {
setImmediate(() => {
expect(cpc).toBeTruthy();
expect(spc).toBeFalsy();
done();
}, 333);
});
});
});
});
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { removeBreakLine } from 'spec/helpers/text_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { removeBreakLine } from 'helpers/text_helper';
import ShaMismatch from '~/vue_merge_request_widget/components/states/sha_mismatch.vue';
describe('ShaMismatch', () => {
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import UnresolvedDiscussions from '~/vue_merge_request_widget/components/states/unresolved_discussions.vue';
import { TEST_HOST } from 'helpers/test_constants';
describe('UnresolvedDiscussions', () => {
const Component = Vue.extend(UnresolvedDiscussions);
......@@ -14,7 +15,7 @@ describe('UnresolvedDiscussions', () => {
beforeEach(() => {
vm = mountComponent(Component, {
mr: {
createIssueToResolveDiscussionsPath: gl.TEST_HOST,
createIssueToResolveDiscussionsPath: TEST_HOST,
},
});
});
......@@ -25,7 +26,7 @@ describe('UnresolvedDiscussions', () => {
);
expect(vm.$el.innerText).toContain('Create an issue to resolve them later');
expect(vm.$el.querySelector('.js-create-issue').getAttribute('href')).toEqual(gl.TEST_HOST);
expect(vm.$el.querySelector('.js-create-issue').getAttribute('href')).toEqual(TEST_HOST);
});
});
......
import Vue from 'vue';
import WorkInProgress from '~/vue_merge_request_widget/components/states/work_in_progress.vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
import createFlash from '~/flash';
jest.mock('~/flash');
const createComponent = () => {
const Component = Vue.extend(WorkInProgress);
......@@ -47,9 +50,8 @@ describe('Wip', () => {
it('should make a request to service and handle response', done => {
const vm = createComponent();
const flashSpy = spyOnDependency(WorkInProgress, 'createFlash').and.returnValue(true);
spyOn(eventHub, '$emit');
spyOn(vm.service, 'removeWIP').and.returnValue(
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest.spyOn(vm.service, 'removeWIP').mockReturnValue(
new Promise(resolve => {
resolve({
data: mrObj,
......@@ -58,12 +60,15 @@ describe('Wip', () => {
);
vm.handleRemoveWIP();
setTimeout(() => {
setImmediate(() => {
expect(vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('UpdateWidgetData', mrObj);
expect(flashSpy).toHaveBeenCalledWith('The merge request can now be merged.', 'notice');
expect(createFlash).toHaveBeenCalledWith(
'The merge request can now be merged.',
'notice',
);
done();
}, 333);
});
});
});
});
......
export { default } from '../../frontend/vue_mr_widget/mock_data';
export * from '../../frontend/vue_mr_widget/mock_data';
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