Commit 4d828eae authored by Mike Greiling's avatar Mike Greiling

convert remaining instances of import * to use spyOnDependency

parent 704e8661
/* eslint-disable comma-dangle, no-param-reassign, no-unused-expressions, max-len */ /* eslint-disable comma-dangle, no-param-reassign, no-unused-expressions, max-len */
import $ from 'jquery'; import $ from 'jquery';
import '~/gl_dropdown'; import GLDropdown from '~/gl_dropdown';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
import * as urlUtils from '~/lib/utils/url_utility';
describe('glDropdown', function describeDropdown() { describe('glDropdown', function describeDropdown() {
preloadFixtures('static/gl_dropdown.html.raw'); preloadFixtures('static/gl_dropdown.html.raw');
...@@ -138,13 +137,13 @@ describe('glDropdown', function describeDropdown() { ...@@ -138,13 +137,13 @@ describe('glDropdown', function describeDropdown() {
expect(this.dropdownContainerElement).toHaveClass('open'); expect(this.dropdownContainerElement).toHaveClass('open');
const randomIndex = Math.floor(Math.random() * (this.projectsData.length - 1)) + 0; const randomIndex = Math.floor(Math.random() * (this.projectsData.length - 1)) + 0;
navigateWithKeys('down', randomIndex, () => { navigateWithKeys('down', randomIndex, () => {
spyOn(urlUtils, 'visitUrl').and.stub(); const visitUrl = spyOnDependency(GLDropdown, 'visitUrl').and.stub();
navigateWithKeys('enter', null, () => { navigateWithKeys('enter', null, () => {
expect(this.dropdownContainerElement).not.toHaveClass('open'); expect(this.dropdownContainerElement).not.toHaveClass('open');
const link = $(`${ITEM_SELECTOR}:eq(${randomIndex}) a`, this.$dropdownMenuElement); const link = $(`${ITEM_SELECTOR}:eq(${randomIndex}) a`, this.$dropdownMenuElement);
expect(link).toHaveClass('is-active'); expect(link).toHaveClass('is-active');
const linkedLocation = link.attr('href'); const linkedLocation = link.attr('href');
if (linkedLocation && linkedLocation !== '#') expect(urlUtils.visitUrl).toHaveBeenCalledWith(linkedLocation); if (linkedLocation && linkedLocation !== '#') expect(visitUrl).toHaveBeenCalledWith(linkedLocation);
}); });
}); });
}); });
......
import $ from 'jquery'; import $ from 'jquery';
import Vue from 'vue'; import Vue from 'vue';
import * as utils from '~/lib/utils/url_utility';
import appComponent from '~/groups/components/app.vue'; import appComponent from '~/groups/components/app.vue';
import groupFolderComponent from '~/groups/components/group_folder.vue'; import groupFolderComponent from '~/groups/components/group_folder.vue';
import groupItemComponent from '~/groups/components/group_item.vue'; import groupItemComponent from '~/groups/components/group_item.vue';
...@@ -177,7 +176,7 @@ describe('AppComponent', () => { ...@@ -177,7 +176,7 @@ describe('AppComponent', () => {
it('should fetch groups for provided page details and update window state', (done) => { it('should fetch groups for provided page details and update window state', (done) => {
spyOn(vm, 'fetchGroups').and.returnValue(returnServicePromise(mockGroups)); spyOn(vm, 'fetchGroups').and.returnValue(returnServicePromise(mockGroups));
spyOn(vm, 'updateGroups').and.callThrough(); spyOn(vm, 'updateGroups').and.callThrough();
spyOn(utils, 'mergeUrlParams').and.callThrough(); const mergeUrlParams = spyOnDependency(appComponent, 'mergeUrlParams').and.callThrough();
spyOn(window.history, 'replaceState'); spyOn(window.history, 'replaceState');
spyOn($, 'scrollTo'); spyOn($, 'scrollTo');
...@@ -193,7 +192,7 @@ describe('AppComponent', () => { ...@@ -193,7 +192,7 @@ describe('AppComponent', () => {
setTimeout(() => { setTimeout(() => {
expect(vm.isLoading).toBe(false); expect(vm.isLoading).toBe(false);
expect($.scrollTo).toHaveBeenCalledWith(0); expect($.scrollTo).toHaveBeenCalledWith(0);
expect(utils.mergeUrlParams).toHaveBeenCalledWith({ page: 2 }, jasmine.any(String)); expect(mergeUrlParams).toHaveBeenCalledWith({ page: 2 }, jasmine.any(String));
expect(window.history.replaceState).toHaveBeenCalledWith({ expect(window.history.replaceState).toHaveBeenCalledWith({
page: jasmine.any(String), page: jasmine.any(String),
}, jasmine.any(String), jasmine.any(String)); }, jasmine.any(String), jasmine.any(String));
......
import Vue from 'vue'; import Vue from 'vue';
import * as urlUtils from '~/lib/utils/url_utility';
import groupItemComponent from '~/groups/components/group_item.vue'; import groupItemComponent from '~/groups/components/group_item.vue';
import groupFolderComponent from '~/groups/components/group_folder.vue'; import groupFolderComponent from '~/groups/components/group_folder.vue';
import eventHub from '~/groups/event_hub'; import eventHub from '~/groups/event_hub';
...@@ -135,13 +134,13 @@ describe('GroupItemComponent', () => { ...@@ -135,13 +134,13 @@ describe('GroupItemComponent', () => {
const group = Object.assign({}, mockParentGroupItem); const group = Object.assign({}, mockParentGroupItem);
group.childrenCount = 0; group.childrenCount = 0;
const newVm = createComponent(group); const newVm = createComponent(group);
spyOn(urlUtils, 'visitUrl').and.stub(); const visitUrl = spyOnDependency(groupItemComponent, 'visitUrl').and.stub();
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
newVm.onClickRowGroup(event); newVm.onClickRowGroup(event);
setTimeout(() => { setTimeout(() => {
expect(eventHub.$emit).not.toHaveBeenCalled(); expect(eventHub.$emit).not.toHaveBeenCalled();
expect(urlUtils.visitUrl).toHaveBeenCalledWith(newVm.group.relativePath); expect(visitUrl).toHaveBeenCalledWith(newVm.group.relativePath);
done(); done();
}, 0); }, 0);
}); });
......
import actions from '~/ide/stores/actions';
import store from '~/ide/stores'; import store from '~/ide/stores';
import service from '~/ide/services'; import service from '~/ide/services';
import router from '~/ide/ide_router'; import router from '~/ide/ide_router';
import * as urlUtils from '~/lib/utils/url_utility';
import eventHub from '~/ide/eventhub'; import eventHub from '~/ide/eventhub';
import * as consts from '~/ide/stores/modules/commit/constants'; import * as consts from '~/ide/stores/modules/commit/constants';
import { resetStore, file } from 'spec/ide/helpers'; import { resetStore, file } from 'spec/ide/helpers';
...@@ -307,8 +307,10 @@ describe('IDE commit module actions', () => { ...@@ -307,8 +307,10 @@ describe('IDE commit module actions', () => {
}); });
describe('commitChanges', () => { describe('commitChanges', () => {
let visitUrl;
beforeEach(() => { beforeEach(() => {
spyOn(urlUtils, 'visitUrl'); visitUrl = spyOnDependency(actions, 'visitUrl');
document.body.innerHTML += '<div class="flash-container"></div>'; document.body.innerHTML += '<div class="flash-container"></div>';
...@@ -461,7 +463,7 @@ describe('IDE commit module actions', () => { ...@@ -461,7 +463,7 @@ describe('IDE commit module actions', () => {
store store
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
.then(() => { .then(() => {
expect(urlUtils.visitUrl).toHaveBeenCalledWith( expect(visitUrl).toHaveBeenCalledWith(
`webUrl/merge_requests/new?merge_request[source_branch]=${ `webUrl/merge_requests/new?merge_request[source_branch]=${
store.getters['commit/newBranchName'] store.getters['commit/newBranchName']
}&merge_request[target_branch]=master`, }&merge_request[target_branch]=master`,
......
...@@ -2,7 +2,6 @@ import Vue from 'vue'; ...@@ -2,7 +2,6 @@ import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import * as urlUtils from '~/lib/utils/url_utility';
import issuableApp from '~/issue_show/components/app.vue'; import issuableApp from '~/issue_show/components/app.vue';
import eventHub from '~/issue_show/event_hub'; import eventHub from '~/issue_show/event_hub';
import setTimeoutPromise from 'spec/helpers/set_timeout_promise_helper'; import setTimeoutPromise from 'spec/helpers/set_timeout_promise_helper';
...@@ -174,7 +173,7 @@ describe('Issuable output', () => { ...@@ -174,7 +173,7 @@ describe('Issuable output', () => {
}); });
it('does not redirect if issue has not moved', (done) => { it('does not redirect if issue has not moved', (done) => {
spyOn(urlUtils, 'visitUrl'); const visitUrl = spyOnDependency(issuableApp, 'visitUrl');
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
data: { data: {
...@@ -187,16 +186,13 @@ describe('Issuable output', () => { ...@@ -187,16 +186,13 @@ describe('Issuable output', () => {
vm.updateIssuable(); vm.updateIssuable();
setTimeout(() => { setTimeout(() => {
expect( expect(visitUrl).not.toHaveBeenCalled();
urlUtils.visitUrl,
).not.toHaveBeenCalled();
done(); done();
}); });
}); });
it('redirects if returned web_url has changed', (done) => { it('redirects if returned web_url has changed', (done) => {
spyOn(urlUtils, 'visitUrl'); const visitUrl = spyOnDependency(issuableApp, 'visitUrl');
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
data: { data: {
...@@ -209,10 +205,7 @@ describe('Issuable output', () => { ...@@ -209,10 +205,7 @@ describe('Issuable output', () => {
vm.updateIssuable(); vm.updateIssuable();
setTimeout(() => { setTimeout(() => {
expect( expect(visitUrl).toHaveBeenCalledWith('/testing-issue-move');
urlUtils.visitUrl,
).toHaveBeenCalledWith('/testing-issue-move');
done(); done();
}); });
}); });
...@@ -340,7 +333,7 @@ describe('Issuable output', () => { ...@@ -340,7 +333,7 @@ describe('Issuable output', () => {
describe('deleteIssuable', () => { describe('deleteIssuable', () => {
it('changes URL when deleted', (done) => { it('changes URL when deleted', (done) => {
spyOn(urlUtils, 'visitUrl'); const visitUrl = spyOnDependency(issuableApp, 'visitUrl');
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
data: { data: {
...@@ -352,16 +345,13 @@ describe('Issuable output', () => { ...@@ -352,16 +345,13 @@ describe('Issuable output', () => {
vm.deleteIssuable(); vm.deleteIssuable();
setTimeout(() => { setTimeout(() => {
expect( expect(visitUrl).toHaveBeenCalledWith('/test');
urlUtils.visitUrl,
).toHaveBeenCalledWith('/test');
done(); done();
}); });
}); });
it('stops polling when deleting', (done) => { it('stops polling when deleting', (done) => {
spyOn(urlUtils, 'visitUrl'); spyOnDependency(issuableApp, 'visitUrl');
spyOn(vm.poll, 'stop').and.callThrough(); spyOn(vm.poll, 'stop').and.callThrough();
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
...@@ -377,7 +367,6 @@ describe('Issuable output', () => { ...@@ -377,7 +367,6 @@ describe('Issuable output', () => {
expect( expect(
vm.poll.stop, vm.poll.stop,
).toHaveBeenCalledWith(); ).toHaveBeenCalledWith();
done(); done();
}); });
}); });
......
import $ from 'jquery'; import $ from 'jquery';
import Vue from 'vue'; import Vue from 'vue';
import descriptionComponent from '~/issue_show/components/description.vue'; import Description from '~/issue_show/components/description.vue';
import * as taskList from '~/task_list';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('Description component', () => { describe('Description component', () => {
...@@ -17,7 +16,7 @@ describe('Description component', () => { ...@@ -17,7 +16,7 @@ describe('Description component', () => {
}; };
beforeEach(() => { beforeEach(() => {
DescriptionComponent = Vue.extend(descriptionComponent); DescriptionComponent = Vue.extend(Description);
if (!document.querySelector('.issuable-meta')) { if (!document.querySelector('.issuable-meta')) {
const metaData = document.createElement('div'); const metaData = document.createElement('div');
...@@ -82,18 +81,20 @@ describe('Description component', () => { ...@@ -82,18 +81,20 @@ describe('Description component', () => {
}); });
describe('TaskList', () => { describe('TaskList', () => {
let TaskList;
beforeEach(() => { beforeEach(() => {
vm = mountComponent(DescriptionComponent, Object.assign({}, props, { vm = mountComponent(DescriptionComponent, Object.assign({}, props, {
issuableType: 'issuableType', issuableType: 'issuableType',
})); }));
spyOn(taskList, 'default'); TaskList = spyOnDependency(Description, 'TaskList');
}); });
it('re-inits the TaskList when description changed', (done) => { it('re-inits the TaskList when description changed', (done) => {
vm.descriptionHtml = 'changed'; vm.descriptionHtml = 'changed';
setTimeout(() => { setTimeout(() => {
expect(taskList.default).toHaveBeenCalled(); expect(TaskList).toHaveBeenCalled();
done(); done();
}); });
}); });
...@@ -103,7 +104,7 @@ describe('Description component', () => { ...@@ -103,7 +104,7 @@ describe('Description component', () => {
vm.descriptionHtml = 'changed'; vm.descriptionHtml = 'changed';
setTimeout(() => { setTimeout(() => {
expect(taskList.default).not.toHaveBeenCalled(); expect(TaskList).not.toHaveBeenCalled();
done(); done();
}); });
}); });
...@@ -112,7 +113,7 @@ describe('Description component', () => { ...@@ -112,7 +113,7 @@ describe('Description component', () => {
vm.descriptionHtml = 'changed'; vm.descriptionHtml = 'changed';
setTimeout(() => { setTimeout(() => {
expect(taskList.default).toHaveBeenCalledWith({ expect(TaskList).toHaveBeenCalledWith({
dataType: 'issuableType', dataType: 'issuableType',
fieldName: 'description', fieldName: 'description',
selector: '.detail-page-description', selector: '.detail-page-description',
......
import findAndFollowLink from '~/shortcuts_dashboard_navigation'; import findAndFollowLink from '~/shortcuts_dashboard_navigation';
import * as urlUtility from '~/lib/utils/url_utility';
describe('findAndFollowLink', () => { describe('findAndFollowLink', () => {
it('visits a link when the selector exists', () => { it('visits a link when the selector exists', () => {
const href = '/some/path'; const href = '/some/path';
const locationSpy = spyOn(urlUtility, 'visitUrl'); const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl');
setFixtures(`<a class="my-shortcut" href="${href}">link</a>`); setFixtures(`<a class="my-shortcut" href="${href}">link</a>`);
findAndFollowLink('.my-shortcut'); findAndFollowLink('.my-shortcut');
expect(locationSpy).toHaveBeenCalledWith(href); expect(visitUrl).toHaveBeenCalledWith(href);
}); });
it('does not throw an exception when the selector does not exist', () => { it('does not throw an exception when the selector does not exist', () => {
const locationSpy = spyOn(urlUtility, 'visitUrl'); const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl');
// this should not throw an exception // this should not throw an exception
findAndFollowLink('.this-selector-does-not-exist'); findAndFollowLink('.this-selector-does-not-exist');
expect(locationSpy).not.toHaveBeenCalled(); expect(visitUrl).not.toHaveBeenCalled();
}); });
}); });
import Vue from 'vue'; import Vue from 'vue';
import ReadyToMerge from '~/vue_merge_request_widget/components/states/ready_to_merge.vue'; import ReadyToMerge from '~/vue_merge_request_widget/components/states/ready_to_merge.vue';
import eventHub from '~/vue_merge_request_widget/event_hub'; import eventHub from '~/vue_merge_request_widget/event_hub';
import * as simplePoll from '~/lib/utils/simple_poll';
const commitMessage = 'This is the commit message'; const commitMessage = 'This is the commit message';
const commitMessageWithDescription = 'This is the commit message description'; const commitMessageWithDescription = 'This is the commit message description';
...@@ -355,9 +354,9 @@ describe('ReadyToMerge', () => { ...@@ -355,9 +354,9 @@ describe('ReadyToMerge', () => {
describe('initiateMergePolling', () => { describe('initiateMergePolling', () => {
it('should call simplePoll', () => { it('should call simplePoll', () => {
spyOn(simplePoll, 'default'); const simplePoll = spyOnDependency(ReadyToMerge, 'simplePoll');
vm.initiateMergePolling(); vm.initiateMergePolling();
expect(simplePoll.default).toHaveBeenCalled(); expect(simplePoll).toHaveBeenCalled();
}); });
}); });
...@@ -457,11 +456,11 @@ describe('ReadyToMerge', () => { ...@@ -457,11 +456,11 @@ describe('ReadyToMerge', () => {
describe('initiateRemoveSourceBranchPolling', () => { describe('initiateRemoveSourceBranchPolling', () => {
it('should emit event and call simplePoll', () => { it('should emit event and call simplePoll', () => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
spyOn(simplePoll, 'default'); const simplePoll = spyOnDependency(ReadyToMerge, 'simplePoll');
vm.initiateRemoveSourceBranchPolling(); vm.initiateRemoveSourceBranchPolling();
expect(eventHub.$emit).toHaveBeenCalledWith('SetBranchRemoveFlag', [true]); expect(eventHub.$emit).toHaveBeenCalledWith('SetBranchRemoveFlag', [true]);
expect(simplePoll.default).toHaveBeenCalled(); expect(simplePoll).toHaveBeenCalled();
}); });
}); });
......
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