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