Unverified Commit 6cd76608 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #1173 from hypothesis/react-spinner

Convert loading spinner to Preact
parents a716d2dc 9711f1bd
'use strict'; 'use strict';
// @ngInject const { createElement } = require('preact');
function SpinnerController($animate, $element) {
// ngAnimate conflicts with the spinners own CSS
$animate.enabled(false, $element);
}
module.exports = { /**
controller: SpinnerController, * Loading indicator.
controllerAs: 'vm', */
template: ` function Spinner() {
<div class="spinner__container"> // The `spinner__container` div only exists to center the spinner within
<span class="spinner"> // the `<spinner>` Angular component element. Once consumers of this component
<span><span> // have been converted to Preact, we should be able to remove this.
</span></span> return (
<div className="spinner__container">
{/* See `.spinner` CSS definition for an explanation of the nested spans. */}
<span className="spinner">
<span>
<span />
</span>
</span> </span>
</div> </div>
`, );
}; }
Spinner.propTypes = {};
module.exports = Spinner;
'use strict'; 'use strict';
const angular = require('angular'); const { createElement } = require('preact');
const { mount } = require('enzyme');
const util = require('../../directive/test/util'); const Spinner = require('../spinner');
const module = angular.mock.module; describe('Spinner', function() {
const inject = angular.mock.inject; const createSpinner = (props = {}) => mount(<Spinner {...props} />);
describe('spinner', function() { // A spinner is a trivial component with no props. Just make sure it renders.
let $animate = null; it('renders', () => {
let $element = null; const wrapper = createSpinner();
let sandbox = null; assert.isTrue(wrapper.exists('.spinner'));
before(function() {
angular.module('h', []).component('spinner', require('../spinner'));
});
beforeEach(module('h'));
beforeEach(inject(function(_$animate_) {
sandbox = sinon.sandbox.create();
$animate = _$animate_;
sandbox.spy($animate, 'enabled');
$element = util.createDirective(document, 'spinner');
}));
afterEach(function() {
sandbox.restore();
});
it('disables ngAnimate animations for itself', function() {
assert.calledOnce($animate.enabled);
const [enabled, jqElement] = $animate.enabled.getCall(0).args;
assert.equal(enabled, false);
assert.equal(jqElement[0], $element[0]);
}); });
}); });
...@@ -191,7 +191,7 @@ function startAngularApp(config) { ...@@ -191,7 +191,7 @@ function startAngularApp(config) {
'sortMenu', 'sortMenu',
wrapReactComponent(require('./components/sort-menu')) wrapReactComponent(require('./components/sort-menu'))
) )
.component('spinner', require('./components/spinner')) .component('spinner', wrapReactComponent(require('./components/spinner')))
.component('streamContent', require('./components/stream-content')) .component('streamContent', require('./components/stream-content'))
.component('svgIcon', wrapReactComponent(require('./components/svg-icon'))) .component('svgIcon', wrapReactComponent(require('./components/svg-icon')))
.component('tagEditor', require('./components/tag-editor')) .component('tagEditor', require('./components/tag-editor'))
......
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