Implement ImageWriterService.reset()

This function allows the client to easily reset the progress state
without breaking encapsulation.
This commit is contained in:
Juan Cruz Viotti 2016-01-01 16:41:14 -04:00
parent 3705d0fc3a
commit e30de45707
4 changed files with 39 additions and 2 deletions

View File

@ -52,7 +52,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
this.restart = function() {
console.debug('Restarting');
this.selection.clear();
this.writer.setProgress(0);
this.writer.reset();
this.scanner.start(2000).on('scan', function(drives) {
// Notice we only autoselect the drive if there is an image,
@ -374,6 +374,18 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
};
/**
* @summary Reset progress state
* @function
* @public
*
* @example
* ImageWriterService.reset();
*/
this.reset = function() {
self.setProgress(0);
};
/**
* @summary Check if currently burning
* @function

View File

@ -51,7 +51,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
this.restart = function() {
console.debug('Restarting');
this.selection.clear();
this.writer.setProgress(0);
this.writer.reset();
this.scanner.start(2000).on('scan', function(drives) {
// Notice we only autoselect the drive if there is an image,

View File

@ -66,6 +66,18 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
};
/**
* @summary Reset progress state
* @function
* @public
*
* @example
* ImageWriterService.reset();
*/
this.reset = function() {
self.setProgress(0);
};
/**
* @summary Check if currently burning
* @function

View File

@ -77,6 +77,19 @@ describe('Browser: ImageWriter', function() {
});
describe('.reset()', function() {
it('should reset progress percentage to 0', function() {
ImageWriterService.setProgress(50);
$timeout.flush();
m.chai.expect(ImageWriterService.state.progress).to.equal(50);
ImageWriterService.reset();
$timeout.flush();
m.chai.expect(ImageWriterService.state.progress).to.equal(0);
});
});
describe('.burn()', function() {
describe('given a succesful write', function() {