Commit c4c5b043 authored by Robert Knight's avatar Robert Knight

Convert uses of proxyquire in src/sidebar/components to mockable-imports

parent 3cdeb195
'use strict'; 'use strict';
const angular = require('angular'); const angular = require('angular');
const proxyquire = require('proxyquire');
const fixtures = require('../../test/annotation-fixtures'); const fixtures = require('../../test/annotation-fixtures');
const annotationHeader = require('../annotation-header');
const fakeDocumentMeta = { const fakeDocumentMeta = {
domain: 'docs.io', domain: 'docs.io',
...@@ -27,7 +27,7 @@ describe('sidebar.components.annotation-header', function() { ...@@ -27,7 +27,7 @@ describe('sidebar.components.annotation-header', function() {
}); });
beforeEach('Import and register the annotationHeader component', function() { beforeEach('Import and register the annotationHeader component', function() {
const annotationHeader = proxyquire('../annotation-header', { annotationHeader.$imports.$mock({
'../annotation-metadata': { '../annotation-metadata': {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
domainAndTitle: function(ann) { domainAndTitle: function(ann) {
...@@ -35,12 +35,14 @@ describe('sidebar.components.annotation-header', function() { ...@@ -35,12 +35,14 @@ describe('sidebar.components.annotation-header', function() {
}, },
}, },
'../util/account-id': fakeAccountID, '../util/account-id': fakeAccountID,
'@noCallThru': true,
}); });
angular.module('app', []).component('annotationHeader', annotationHeader); angular.module('app', []).component('annotationHeader', annotationHeader);
}); });
afterEach(() => {
annotationHeader.$imports.$restore();
});
beforeEach('Initialize and register fake AngularJS dependencies', function() { beforeEach('Initialize and register fake AngularJS dependencies', function() {
fakeFeatures = { fakeFeatures = {
flagEnabled: sinon.stub().returns(false), flagEnabled: sinon.stub().returns(false),
......
'use strict'; 'use strict';
const angular = require('angular'); const angular = require('angular');
const proxyquire = require('proxyquire');
const events = require('../../events'); const events = require('../../events');
const fixtures = require('../../test/annotation-fixtures'); const fixtures = require('../../test/annotation-fixtures');
const testUtil = require('../../../shared/test/util'); const testUtil = require('../../../shared/test/util');
const util = require('../../directive/test/util'); const util = require('../../directive/test/util');
const annotationComponent = require('../annotation');
const inject = angular.mock.inject; const inject = angular.mock.inject;
const unroll = testUtil.unroll; const unroll = testUtil.unroll;
...@@ -100,9 +101,6 @@ describe('annotation', function() { ...@@ -100,9 +101,6 @@ describe('annotation', function() {
let $scope; let $scope;
let $timeout; let $timeout;
let $window; let $window;
// Unfortunately fakeAccountID needs to be initialised here because it
// gets passed into proxyquire() _before_ the beforeEach() that initializes
// the rest of the fakes runs.
const fakeAccountID = { const fakeAccountID = {
isThirdPartyUser: sinon.stub(), isThirdPartyUser: sinon.stub(),
}; };
...@@ -120,16 +118,15 @@ describe('annotation', function() { ...@@ -120,16 +118,15 @@ describe('annotation', function() {
let fakeStreamer; let fakeStreamer;
let sandbox; let sandbox;
/** beforeEach(() => {
* Returns the annotation directive with helpers stubbed out. annotationComponent.$imports.$mock({
*/
function annotationComponent() {
return proxyquire('../annotation', {
angular: testUtil.noCallThru(angular),
'../util/account-id': fakeAccountID, '../util/account-id': fakeAccountID,
'@noCallThru': true,
}); });
} });
afterEach(() => {
annotationComponent.$imports.$restore();
});
function createDirective(annotation) { function createDirective(annotation) {
annotation = annotation || fixtures.defaultAnnotation(); annotation = annotation || fixtures.defaultAnnotation();
...@@ -153,7 +150,7 @@ describe('annotation', function() { ...@@ -153,7 +150,7 @@ describe('annotation', function() {
before(function() { before(function() {
angular angular
.module('h', []) .module('h', [])
.component('annotation', annotationComponent()) .component('annotation', annotationComponent)
.component('annotationActionButton', { .component('annotationActionButton', {
bindings: { bindings: {
icon: '<', icon: '<',
......
'use strict'; 'use strict';
const angular = require('angular'); const angular = require('angular');
const proxyquire = require('proxyquire');
const EventEmitter = require('tiny-emitter'); const EventEmitter = require('tiny-emitter');
const events = require('../../events'); const events = require('../../events');
const noCallThru = require('../../../shared/test/util').noCallThru; const sidebarContent = require('../sidebar-content');
const uiConstants = require('../../ui-constants'); const uiConstants = require('../../ui-constants');
let searchClients; let searchClients;
...@@ -64,21 +63,12 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -64,21 +63,12 @@ describe('sidebar.components.sidebar-content', function() {
angular angular
.module('h', []) .module('h', [])
.service('store', require('../../store')) .service('store', require('../../store'))
.component( .component('sidebarContent', sidebarContent);
'sidebarContent',
proxyquire(
'../sidebar-content',
noCallThru({
angular: angular,
'../search-client': FakeSearchClient,
})
)
);
}); });
beforeEach(angular.mock.module('h')); beforeEach(angular.mock.module('h'));
beforeEach( beforeEach(() => {
angular.mock.module(function($provide) { angular.mock.module(function($provide) {
searchClients = []; searchClients = [];
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
...@@ -142,8 +132,16 @@ describe('sidebar.components.sidebar-content', function() { ...@@ -142,8 +132,16 @@ describe('sidebar.components.sidebar-content', function() {
$provide.value('streamFilter', fakeStreamFilter); $provide.value('streamFilter', fakeStreamFilter);
$provide.value('groups', fakeGroups); $provide.value('groups', fakeGroups);
$provide.value('settings', fakeSettings); $provide.value('settings', fakeSettings);
}) });
);
sidebarContent.$imports.$mock({
'../search-client': FakeSearchClient,
});
});
afterEach(() => {
sidebarContent.$imports.$restore();
});
function setFrames(frames) { function setFrames(frames) {
frames.forEach(function(frame) { frames.forEach(function(frame) {
......
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