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