Merge pull request #120 from resin-io/fix/96/then-of-undefined

Fix sporadic Cannot read property 'then' of undefined
This commit is contained in:
Juan Cruz Viotti 2016-01-22 13:25:36 -04:00
commit 0b0c3dc9fa
4 changed files with 20 additions and 5 deletions

View File

@ -114,10 +114,8 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* }); * });
*/ */
this.burn = function(image, drive, onProgress) { this.burn = function(image, drive, onProgress) {
// Avoid writing more than once
if (self.isBurning()) { if (self.isBurning()) {
return; return $q.reject(new Error('There is already a burn in progress'));
} }
self.setBurning(true); self.setBurning(true);

View File

@ -5,7 +5,7 @@
<dom-module id="hero-progress-button"> <dom-module id="hero-progress-button">
<template> <template>
<style> <style>
:host:not([percentage="0"]) { :host[active="true"] {
pointer-events: none; pointer-events: none;
} }
@ -39,6 +39,9 @@
Polymer({ Polymer({
is: 'hero-progress-button', is: 'hero-progress-button',
properties: { properties: {
active: {
type: Boolean
},
disabled: { disabled: {
type: String type: String
}, },

View File

@ -78,7 +78,7 @@
<hero-badge class="block space-vertical-medium" ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()">3</hero-badge> <hero-badge class="block space-vertical-medium" ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()">3</hero-badge>
<div class="space-vertical-large"> <div class="space-vertical-large">
<hero-progress-button percentage="{{ app.state.progress }}" active="{{ app.writer.isBurning() }}" <hero-progress-button percentage="{{ app.state.progress }}" ng-attr-active="{{ app.writer.isBurning() }}"
ng-click="app.burn(app.selection.getImage(), app.selection.getDrive())" ng-click="app.burn(app.selection.getImage(), app.selection.getDrive())"
ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()"> ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()">
<span ng-show="app.state.progress == 100 && app.writer.isBurning()">Finishing...</span> <span ng-show="app.state.progress == 100 && app.writer.isBurning()">Finishing...</span>

View File

@ -84,6 +84,20 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(this.performWriteStub).to.have.been.calledOnce; m.chai.expect(this.performWriteStub).to.have.been.calledOnce;
}); });
it('should reject the second burn attempt', function() {
ImageWriterService.burn('foo.img', '/dev/disk2');
let rejectError = null;
ImageWriterService.burn('foo.img', '/dev/disk2').catch(function(error) {
rejectError = error;
});
$rootScope.$apply();
m.chai.expect(rejectError).to.be.an.instanceof(Error);
m.chai.expect(rejectError.message).to.equal('There is already a burn in progress');
});
}); });
describe('given an unsuccesful write', function() { describe('given an unsuccesful write', function() {