Commit 704e8661 authored by Mike Greiling's avatar Mike Greiling

fix more instances of "import *" with spyOnDependency

parent 1f1af49a
import RecentSearchesRoot from '~/filtered_search/recent_searches_root'; import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
import * as vueSrc from 'vue';
describe('RecentSearchesRoot', () => { describe('RecentSearchesRoot', () => {
describe('render', () => { describe('render', () => {
let recentSearchesRoot; let recentSearchesRoot;
let data; let data;
let template; let template;
let VueSpy;
beforeEach(() => { beforeEach(() => {
recentSearchesRoot = { recentSearchesRoot = {
...@@ -14,7 +14,7 @@ describe('RecentSearchesRoot', () => { ...@@ -14,7 +14,7 @@ describe('RecentSearchesRoot', () => {
}, },
}; };
spyOn(vueSrc, 'default').and.callFake((options) => { VueSpy = spyOnDependency(RecentSearchesRoot, 'Vue').and.callFake((options) => {
data = options.data; data = options.data;
template = options.template; template = options.template;
}); });
...@@ -23,7 +23,7 @@ describe('RecentSearchesRoot', () => { ...@@ -23,7 +23,7 @@ describe('RecentSearchesRoot', () => {
}); });
it('should instantiate Vue', () => { it('should instantiate Vue', () => {
expect(vueSrc.default).toHaveBeenCalled(); expect(VueSpy).toHaveBeenCalled();
expect(data()).toBe(recentSearchesRoot.store.state); expect(data()).toBe(recentSearchesRoot.store.state);
expect(template).toContain(':is-local-storage-available="isLocalStorageAvailable"'); expect(template).toContain(':is-local-storage-available="isLocalStorageAvailable"');
}); });
......
import * as urlUtils from '~/lib/utils/url_utility'; import actions, { stageAllChanges, unstageAllChanges } from '~/ide/stores/actions';
import store from '~/ide/stores'; import store from '~/ide/stores';
import * as actions from '~/ide/stores/actions';
import * as types from '~/ide/stores/mutation_types'; import * as types from '~/ide/stores/mutation_types';
import router from '~/ide/ide_router'; import router from '~/ide/ide_router';
import { resetStore, file } from '../helpers'; import { resetStore, file } from '../helpers';
...@@ -17,12 +16,12 @@ describe('Multi-file store actions', () => { ...@@ -17,12 +16,12 @@ describe('Multi-file store actions', () => {
describe('redirectToUrl', () => { describe('redirectToUrl', () => {
it('calls visitUrl', done => { it('calls visitUrl', done => {
spyOn(urlUtils, 'visitUrl'); const visitUrl = spyOnDependency(actions, 'visitUrl');
store store
.dispatch('redirectToUrl', 'test') .dispatch('redirectToUrl', 'test')
.then(() => { .then(() => {
expect(urlUtils.visitUrl).toHaveBeenCalledWith('test'); expect(visitUrl).toHaveBeenCalledWith('test');
done(); done();
}) })
...@@ -298,7 +297,7 @@ describe('Multi-file store actions', () => { ...@@ -298,7 +297,7 @@ describe('Multi-file store actions', () => {
store.state.changedFiles.push(file(), file('new')); store.state.changedFiles.push(file(), file('new'));
testAction( testAction(
actions.stageAllChanges, stageAllChanges,
null, null,
store.state, store.state,
[ [
...@@ -316,7 +315,7 @@ describe('Multi-file store actions', () => { ...@@ -316,7 +315,7 @@ describe('Multi-file store actions', () => {
store.state.stagedFiles.push(file(), file('new')); store.state.stagedFiles.push(file(), file('new'));
testAction( testAction(
actions.unstageAllChanges, unstageAllChanges,
null, null,
store.state, store.state,
[ [
......
...@@ -2,7 +2,6 @@ import $ from 'jquery'; ...@@ -2,7 +2,6 @@ import $ from 'jquery';
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 { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import * as urlUtils from '~/lib/utils/url_utility';
import '~/lib/utils/datetime_utility'; import '~/lib/utils/datetime_utility';
import Job from '~/job'; import Job from '~/job';
import '~/breakpoints'; import '~/breakpoints';
...@@ -22,7 +21,7 @@ describe('Job', () => { ...@@ -22,7 +21,7 @@ describe('Job', () => {
beforeEach(() => { beforeEach(() => {
loadFixtures('builds/build-with-artifacts.html.raw'); loadFixtures('builds/build-with-artifacts.html.raw');
spyOn(urlUtils, 'visitUrl'); spyOnDependency(Job, 'visitUrl');
response = {}; response = {};
......
import * as imageUtility from '~/lib/utils/image_utility'; import { isImageLoaded } from '~/lib/utils/image_utility';
describe('imageUtility', () => { describe('imageUtility', () => {
describe('isImageLoaded', () => { describe('isImageLoaded', () => {
...@@ -8,7 +8,7 @@ describe('imageUtility', () => { ...@@ -8,7 +8,7 @@ describe('imageUtility', () => {
naturalHeight: 100, naturalHeight: 100,
}; };
expect(imageUtility.isImageLoaded(element)).toEqual(false); expect(isImageLoaded(element)).toEqual(false);
}); });
it('should return false when naturalHeight = 0', () => { it('should return false when naturalHeight = 0', () => {
...@@ -17,7 +17,7 @@ describe('imageUtility', () => { ...@@ -17,7 +17,7 @@ describe('imageUtility', () => {
naturalHeight: 0, naturalHeight: 0,
}; };
expect(imageUtility.isImageLoaded(element)).toEqual(false); expect(isImageLoaded(element)).toEqual(false);
}); });
it('should return true when image.complete and naturalHeight != 0', () => { it('should return true when image.complete and naturalHeight != 0', () => {
...@@ -26,7 +26,7 @@ describe('imageUtility', () => { ...@@ -26,7 +26,7 @@ describe('imageUtility', () => {
naturalHeight: 100, naturalHeight: 100,
}; };
expect(imageUtility.isImageLoaded(element)).toEqual(true); expect(isImageLoaded(element)).toEqual(true);
}); });
}); });
}); });
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import $ from 'jquery'; import $ from 'jquery';
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 * as urlUtils from '~/lib/utils/url_utility';
import MergeRequestTabs from '~/merge_request_tabs'; import MergeRequestTabs from '~/merge_request_tabs';
import '~/commit/pipelines/pipelines_bundle'; import '~/commit/pipelines/pipelines_bundle';
import '~/breakpoints'; import '~/breakpoints';
...@@ -356,7 +355,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -356,7 +355,7 @@ import 'vendor/jquery.scrollTo';
describe('with note fragment hash', () => { describe('with note fragment hash', () => {
it('should expand and scroll to linked fragment hash #note_xxx', function (done) { it('should expand and scroll to linked fragment hash #note_xxx', function (done) {
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteId); spyOnDependency(MergeRequestTabs, 'getLocationHash').and.returnValue(noteId);
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
setTimeout(() => { setTimeout(() => {
...@@ -372,7 +371,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -372,7 +371,7 @@ import 'vendor/jquery.scrollTo';
}); });
it('should gracefully ignore non-existant fragment hash', function (done) { it('should gracefully ignore non-existant fragment hash', function (done) {
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist'); spyOnDependency(MergeRequestTabs, 'getLocationHash').and.returnValue('note_something-that-does-not-exist');
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
setTimeout(() => { setTimeout(() => {
...@@ -385,7 +384,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -385,7 +384,7 @@ import 'vendor/jquery.scrollTo';
describe('with line number fragment hash', () => { describe('with line number fragment hash', () => {
it('should gracefully ignore line number fragment hash', function () { it('should gracefully ignore line number fragment hash', function () {
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteLineNumId); spyOnDependency(MergeRequestTabs, 'getLocationHash').and.returnValue(noteLineNumId);
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(noteLineNumId.length).toBeGreaterThan(0); expect(noteLineNumId.length).toBeGreaterThan(0);
...@@ -422,7 +421,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -422,7 +421,7 @@ import 'vendor/jquery.scrollTo';
describe('with note fragment hash', () => { describe('with note fragment hash', () => {
it('should expand and scroll to linked fragment hash #note_xxx', function (done) { it('should expand and scroll to linked fragment hash #note_xxx', function (done) {
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteId); spyOnDependency(MergeRequestTabs, 'getLocationHash').and.returnValue(noteId);
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
...@@ -439,7 +438,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -439,7 +438,7 @@ import 'vendor/jquery.scrollTo';
}); });
it('should gracefully ignore non-existant fragment hash', function (done) { it('should gracefully ignore non-existant fragment hash', function (done) {
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_something-that-does-not-exist'); spyOnDependency(MergeRequestTabs, 'getLocationHash').and.returnValue('note_something-that-does-not-exist');
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
setTimeout(() => { setTimeout(() => {
...@@ -451,7 +450,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -451,7 +450,7 @@ import 'vendor/jquery.scrollTo';
describe('with line number fragment hash', () => { describe('with line number fragment hash', () => {
it('should gracefully ignore line number fragment hash', function () { it('should gracefully ignore line number fragment hash', function () {
spyOn(urlUtils, 'getLocationHash').and.returnValue(noteLineNumId); spyOnDependency(MergeRequestTabs, 'getLocationHash').and.returnValue(noteLineNumId);
this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); this.class.loadDiff('/foo/bar/merge_requests/1/diffs');
expect(noteLineNumId.length).toBeGreaterThan(0); expect(noteLineNumId.length).toBeGreaterThan(0);
......
...@@ -3,7 +3,6 @@ import $ from 'jquery'; ...@@ -3,7 +3,6 @@ import $ from 'jquery';
import _ from 'underscore'; import _ from 'underscore';
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 * as urlUtils from '~/lib/utils/url_utility';
import 'autosize'; import 'autosize';
import '~/gl_form'; import '~/gl_form';
import '~/lib/utils/text_utility'; import '~/lib/utils/text_utility';
...@@ -222,7 +221,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper'; ...@@ -222,7 +221,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
}); });
it('sets target when hash matches', () => { it('sets target when hash matches', () => {
spyOn(urlUtils, 'getLocationHash').and.returnValue(hash); spyOnDependency(Notes, 'getLocationHash').and.returnValue(hash);
Notes.updateNoteTargetSelector($note); Notes.updateNoteTargetSelector($note);
...@@ -231,7 +230,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper'; ...@@ -231,7 +230,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
}); });
it('unsets target when hash does not match', () => { it('unsets target when hash does not match', () => {
spyOn(urlUtils, 'getLocationHash').and.returnValue('note_doesnotexist'); spyOnDependency(Notes, 'getLocationHash').and.returnValue('note_doesnotexist');
Notes.updateNoteTargetSelector($note); Notes.updateNoteTargetSelector($note);
...@@ -239,7 +238,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper'; ...@@ -239,7 +238,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
}); });
it('unsets target when there is not a hash fragment anymore', () => { it('unsets target when there is not a hash fragment anymore', () => {
spyOn(urlUtils, 'getLocationHash').and.returnValue(null); spyOnDependency(Notes, 'getLocationHash').and.returnValue(null);
Notes.updateNoteTargetSelector($note); Notes.updateNoteTargetSelector($note);
......
/* global fixture */
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 * as utils from '~/lib/utils/url_utility';
import Pager from '~/pager'; import Pager from '~/pager';
describe('pager', () => { describe('pager', () => {
...@@ -25,7 +23,7 @@ describe('pager', () => { ...@@ -25,7 +23,7 @@ describe('pager', () => {
it('should use current url if data-href attribute not provided', () => { it('should use current url if data-href attribute not provided', () => {
const href = `${gl.TEST_HOST}/some_list`; const href = `${gl.TEST_HOST}/some_list`;
spyOn(utils, 'removeParams').and.returnValue(href); spyOnDependency(Pager, 'removeParams').and.returnValue(href);
Pager.init(); Pager.init();
expect(Pager.url).toBe(href); expect(Pager.url).toBe(href);
}); });
...@@ -39,9 +37,9 @@ describe('pager', () => { ...@@ -39,9 +37,9 @@ describe('pager', () => {
it('keeps extra query parameters from url', () => { it('keeps extra query parameters from url', () => {
window.history.replaceState({}, null, '?filter=test&offset=100'); window.history.replaceState({}, null, '?filter=test&offset=100');
const href = `${gl.TEST_HOST}/some_list?filter=test`; const href = `${gl.TEST_HOST}/some_list?filter=test`;
spyOn(utils, 'removeParams').and.returnValue(href); const removeParams = spyOnDependency(Pager, 'removeParams').and.returnValue(href);
Pager.init(); Pager.init();
expect(utils.removeParams).toHaveBeenCalledWith(['limit', 'offset']); expect(removeParams).toHaveBeenCalledWith(['limit', 'offset']);
expect(Pager.url).toEqual(href); expect(Pager.url).toEqual(href);
}); });
}); });
......
...@@ -4,7 +4,6 @@ import $ from 'jquery'; ...@@ -4,7 +4,6 @@ import $ from 'jquery';
import '~/gl_dropdown'; import '~/gl_dropdown';
import SearchAutocomplete from '~/search_autocomplete'; import SearchAutocomplete from '~/search_autocomplete';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
import * as urlUtils from '~/lib/utils/url_utility';
describe('Search autocomplete dropdown', () => { describe('Search autocomplete dropdown', () => {
var assertLinks, var assertLinks,
...@@ -129,9 +128,6 @@ describe('Search autocomplete dropdown', () => { ...@@ -129,9 +128,6 @@ describe('Search autocomplete dropdown', () => {
beforeEach(function() { beforeEach(function() {
loadFixtures('static/search_autocomplete.html.raw'); loadFixtures('static/search_autocomplete.html.raw');
// Prevent turbolinks from triggering within gl_dropdown
spyOn(urlUtils, 'visitUrl').and.returnValue(true);
window.gon = {}; window.gon = {};
window.gon.current_user_id = userId; window.gon.current_user_id = userId;
window.gon.current_username = userName; window.gon.current_username = userName;
......
import _ from 'underscore'; import _ from 'underscore';
import Vue from 'vue'; import Vue from 'vue';
import * as urlUtils from '~/lib/utils/url_utility';
import SidebarMediator from '~/sidebar/sidebar_mediator'; import SidebarMediator from '~/sidebar/sidebar_mediator';
import SidebarStore from '~/sidebar/stores/sidebar_store'; import SidebarStore from '~/sidebar/stores/sidebar_store';
import SidebarService from '~/sidebar/services/sidebar_service'; import SidebarService from '~/sidebar/services/sidebar_service';
import Mock from './mock_data'; import Mock from './mock_data';
describe('Sidebar mediator', () => { describe('Sidebar mediator', function() {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(Mock.sidebarMockInterceptor); Vue.http.interceptors.push(Mock.sidebarMockInterceptor);
this.mediator = new SidebarMediator(Mock.mediator); this.mediator = new SidebarMediator(Mock.mediator);
...@@ -87,12 +86,12 @@ describe('Sidebar mediator', () => { ...@@ -87,12 +86,12 @@ describe('Sidebar mediator', () => {
const moveToProjectId = 7; const moveToProjectId = 7;
this.mediator.store.setMoveToProjectId(moveToProjectId); this.mediator.store.setMoveToProjectId(moveToProjectId);
spyOn(this.mediator.service, 'moveIssue').and.callThrough(); spyOn(this.mediator.service, 'moveIssue').and.callThrough();
spyOn(urlUtils, 'visitUrl'); const visitUrl = spyOnDependency(SidebarMediator, 'visitUrl');
this.mediator.moveIssue() this.mediator.moveIssue()
.then(() => { .then(() => {
expect(this.mediator.service.moveIssue).toHaveBeenCalledWith(moveToProjectId); expect(this.mediator.service.moveIssue).toHaveBeenCalledWith(moveToProjectId);
expect(urlUtils.visitUrl).toHaveBeenCalledWith('/root/some-project/issues/5'); expect(visitUrl).toHaveBeenCalledWith('/root/some-project/issues/5');
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
import $ from 'jquery'; import $ from 'jquery';
import * as urlUtils from '~/lib/utils/url_utility';
import Todos from '~/pages/dashboard/todos/index/todos'; import Todos from '~/pages/dashboard/todos/index/todos';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
...@@ -18,7 +17,7 @@ describe('Todos', () => { ...@@ -18,7 +17,7 @@ describe('Todos', () => {
it('opens the todo url', (done) => { it('opens the todo url', (done) => {
const todoLink = todoItem.dataset.url; const todoLink = todoItem.dataset.url;
spyOn(urlUtils, 'visitUrl').and.callFake((url) => { spyOnDependency(Todos, 'visitUrl').and.callFake((url) => {
expect(url).toEqual(todoLink); expect(url).toEqual(todoLink);
done(); done();
}); });
...@@ -33,7 +32,7 @@ describe('Todos', () => { ...@@ -33,7 +32,7 @@ describe('Todos', () => {
beforeEach(() => { beforeEach(() => {
metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true }); metakeyEvent = $.Event('click', { keyCode: 91, ctrlKey: true });
visitUrlSpy = spyOn(urlUtils, 'visitUrl').and.callFake(() => {}); visitUrlSpy = spyOnDependency(Todos, 'visitUrl').and.callFake(() => {});
windowOpenSpy = spyOn(window, 'open').and.callFake(() => {}); windowOpenSpy = spyOn(window, 'open').and.callFake(() => {});
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import * as urlUtils from '~/lib/utils/url_utility';
import deploymentComponent from '~/vue_merge_request_widget/components/deployment.vue'; import deploymentComponent from '~/vue_merge_request_widget/components/deployment.vue';
import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service'; import MRWidgetService from '~/vue_merge_request_widget/services/mr_widget_service';
import { getTimeago } from '~/lib/utils/datetime_utility'; import { getTimeago } from '~/lib/utils/datetime_utility';
...@@ -117,13 +116,13 @@ describe('Deployment component', () => { ...@@ -117,13 +116,13 @@ describe('Deployment component', () => {
it('should show a confirm dialog and call service.stopEnvironment when confirmed', (done) => { it('should show a confirm dialog and call service.stopEnvironment when confirmed', (done) => {
spyOn(window, 'confirm').and.returnValue(true); spyOn(window, 'confirm').and.returnValue(true);
spyOn(MRWidgetService, 'stopEnvironment').and.returnValue(returnPromise(true)); spyOn(MRWidgetService, 'stopEnvironment').and.returnValue(returnPromise(true));
spyOn(urlUtils, 'visitUrl').and.returnValue(true); const visitUrl = spyOnDependency(deploymentComponent, 'visitUrl').and.returnValue(true);
vm = mockStopEnvironment(); vm = mockStopEnvironment();
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(MRWidgetService.stopEnvironment).toHaveBeenCalledWith(deploymentMockData.stop_url); expect(MRWidgetService.stopEnvironment).toHaveBeenCalledWith(deploymentMockData.stop_url);
setTimeout(() => { setTimeout(() => {
expect(urlUtils.visitUrl).toHaveBeenCalledWith(url); expect(visitUrl).toHaveBeenCalledWith(url);
done(); done();
}, 333); }, 333);
}); });
......
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