Commit fb4c1efe authored by Robert Knight's avatar Robert Knight

Convert `spinner` Angular directive to a component

This is the last remaining directive which should be a component.
parent 8997d723
'use strict';
// @ngInject
function SpinnerController($animate, $element) {
// ngAnimate conflicts with the spinners own CSS
$animate.enabled(false, $element);
}
module.exports = {
controller: SpinnerController,
controllerAs: 'vm',
template: `
<span class="spinner">
<span><span>
</span></span>
</span>
`,
};
......@@ -46,13 +46,13 @@ describe('searchInput', function () {
describe('loading indicator', function () {
it('is hidden when there are no network requests in flight', function () {
const el = util.createDirective(document, 'search-input', {});
const spinner = el[0].querySelector('.spinner');
const spinner = el[0].querySelector('spinner');
assert.equal(util.isHidden(spinner), true);
});
it('is visible when there are network requests in flight', function () {
const el = util.createDirective(document, 'search-input', {});
const spinner = el[0].querySelector('.spinner');
const spinner = el[0].querySelector('spinner');
fakeHttp.pendingRequests.push([{}]);
el.scope.$digest();
assert.equal(util.isHidden(spinner), false);
......
......@@ -2,6 +2,8 @@
const angular = require('angular');
const util = require('../../directive/test/util');
const module = angular.mock.module;
const inject = angular.mock.inject;
......@@ -11,19 +13,18 @@ describe('spinner', function () {
let sandbox = null;
before(function () {
angular.module('h', []).directive('spinner', require('../spinner'));
angular.module('h', []).component('spinner', require('../spinner'));
});
beforeEach(module('h'));
beforeEach(inject(function (_$animate_, $compile, $rootScope) {
beforeEach(inject(function (_$animate_) {
sandbox = sinon.sandbox.create();
$animate = _$animate_;
sandbox.spy($animate, 'enabled');
$element = angular.element('<span class="spinner"></span>');
$compile($element)($rootScope.$new());
$element = util.createDirective(document, 'spinner');
}));
afterEach(function () {
......@@ -31,6 +32,10 @@ describe('spinner', function () {
});
it('disables ngAnimate animations for itself', function () {
assert.calledWith($animate.enabled, false, sinon.match($element));
assert.calledOnce($animate.enabled);
const [enabled, jqElement] = $animate.enabled.getCall(0).args;
assert.equal(enabled, false);
assert.equal(jqElement[0], $element[0]);
});
});
'use strict';
module.exports = ['$animate', function($animate) {
return {
link: function(scope, elem) {
// ngAnimate conflicts with the spinners own CSS
$animate.enabled(false, elem);
},
restrict: 'C',
template: '<span><span></span></span>',
};
}];
......@@ -160,6 +160,7 @@ function startAngularApp(config) {
.component('sidebarTutorial', require('./components/sidebar-tutorial'))
.component('shareDialog', require('./components/share-dialog'))
.component('sortDropdown', require('./components/sort-dropdown'))
.component('spinner', require('./components/spinner'))
.component('streamContent', require('./components/stream-content'))
.component('svgIcon', require('./components/svg-icon'))
.component('tagEditor', require('./components/tag-editor'))
......@@ -171,7 +172,6 @@ function startAngularApp(config) {
.directive('hBranding', require('./directive/h-branding'))
.directive('hOnTouch', require('./directive/h-on-touch'))
.directive('hTooltip', require('./directive/h-tooltip'))
.directive('spinner', require('./directive/spinner'))
.directive('windowScroll', require('./directive/window-scroll'))
.service('analytics', require('./services/analytics'))
......
......@@ -11,6 +11,6 @@
<i class="h-icon-search"></i>
</button>
<button type="button" class="simple-search-icon btn btn-clean" ng-show="vm.loading" disabled>
<span class="btn-icon"><span class="spinner"></span></span>
<span class="btn-icon"><spinner></spinner></span>
</button>
</form>
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