refactor(GUI): remove angular dependency from selection-state (#1509)

We remove the dependency on Angular from SelectionStateModel and rename
it to selectionState.
This commit is contained in:
Benedict Aas 2017-06-12 13:40:52 +01:00 committed by Juan Cruz Viotti
parent cff445b64b
commit ef739fb222
16 changed files with 1235 additions and 1284 deletions

View File

@ -41,6 +41,7 @@ const windowProgress = require('./os/window-progress');
const analytics = require('./modules/analytics');
const updateNotifier = require('./components/update-notifier');
const availableDrives = require('./models/available-drives');
const selectionState = require('./models/selection-state');
const Store = require('./models/store');
@ -53,9 +54,6 @@ const app = angular.module('Etcher', [
require('./modules/error'),
require('./modules/drive-scanner'),
// Models
require('./models/selection-state'),
// Components
require('./components/svg-icon/svg-icon'),
require('./components/warning-modal/warning-modal'),
@ -89,7 +87,7 @@ app.run(() => {
].join('\n'));
});
app.run((ErrorService, SelectionStateModel) => {
app.run((ErrorService) => {
analytics.logEvent('Application start');
const currentVersion = packageJSON.version;
@ -139,7 +137,7 @@ app.run((ErrorService, SelectionStateModel) => {
// the user about the new version if he didn't start the flash
// process (e.g: selected an image), otherwise such interruption
// might be annoying.
if (SelectionStateModel.hasImage()) {
if (selectionState.hasImage()) {
analytics.logEvent('Update notification skipped', {
reason: 'Image selected'
});
@ -278,7 +276,7 @@ app.config(($provide) => {
});
});
app.controller('HeaderController', function(SelectionStateModel, OSOpenExternalService) {
app.controller('HeaderController', function(OSOpenExternalService) {
/**
* @summary Open help page
@ -294,7 +292,7 @@ app.controller('HeaderController', function(SelectionStateModel, OSOpenExternalS
*/
this.openHelpPage = () => {
const DEFAULT_SUPPORT_URL = 'https://github.com/resin-io/etcher/blob/master/SUPPORT.md';
const supportUrl = SelectionStateModel.getImageSupportUrl() || DEFAULT_SUPPORT_URL;
const supportUrl = selectionState.getImageSupportUrl() || DEFAULT_SUPPORT_URL;
OSOpenExternalService.open(supportUrl);
};

View File

@ -22,11 +22,11 @@ const messages = require('../../../../shared/messages');
const constraints = require('../../../../shared/drive-constraints');
const analytics = require('../../../modules/analytics');
const availableDrives = require('../../../models/available-drives');
const selectionState = require('../../../models/selection-state');
module.exports = function(
$q,
$uibModalInstance,
SelectionStateModel,
WarningModalService
) {
@ -35,7 +35,7 @@ module.exports = function(
* @type {Object}
* @public
*/
this.state = SelectionStateModel;
this.state = selectionState;
/**
* @summary Static methods to check a drive's properties
@ -72,11 +72,11 @@ module.exports = function(
* });
*/
const shouldChangeDriveSelectionState = (drive) => {
if (!constraints.isDriveValid(drive, SelectionStateModel.getImage())) {
if (!constraints.isDriveValid(drive, selectionState.getImage())) {
return $q.resolve(false);
}
if (constraints.isDriveSizeRecommended(drive, SelectionStateModel.getImage())) {
if (constraints.isDriveSizeRecommended(drive, selectionState.getImage())) {
return $q.resolve(true);
}
@ -84,7 +84,7 @@ module.exports = function(
confirmationLabel: 'Yes, continue',
description: [
messages.warning.unrecommendedDriveSize({
image: SelectionStateModel.getImage(),
image: selectionState.getImage(),
drive
}),
'Are you sure you want to continue?'
@ -111,12 +111,12 @@ module.exports = function(
analytics.logEvent('Toggle drive', {
drive,
previouslySelected: SelectionStateModel.isCurrentDrive(drive.device)
previouslySelected: selectionState.isCurrentDrive(drive.device)
});
return shouldChangeDriveSelectionState(drive).then((canChangeDriveSelectionState) => {
if (canChangeDriveSelectionState) {
SelectionStateModel.toggleSetDrive(drive.device);
selectionState.toggleSetDrive(drive.device);
}
});
@ -131,7 +131,7 @@ module.exports = function(
* DriveSelectorController.closeModal();
*/
this.closeModal = () => {
const selectedDrive = SelectionStateModel.getDrive();
const selectedDrive = selectionState.getDrive();
// Sanity check to cover the case where a drive is selected,
// the drive is then unplugged from the computer and the modal
@ -162,7 +162,7 @@ module.exports = function(
this.selectDriveAndClose = (drive) => {
return shouldChangeDriveSelectionState(drive).then((canChangeDriveSelectionState) => {
if (canChangeDriveSelectionState) {
SelectionStateModel.setDrive(drive.device);
selectionState.setDrive(drive.device);
analytics.logEvent('Drive selected (double click)');

View File

@ -25,7 +25,6 @@ const MODULE_NAME = 'Etcher.Components.DriveSelector';
const DriveSelector = angular.module(MODULE_NAME, [
require('../modal/modal'),
require('../warning-modal/warning-modal'),
require('../../models/selection-state'),
require('../../utils/byte-size/byte-size')
]);

View File

@ -23,8 +23,7 @@
const angular = require('angular');
const MODULE_NAME = 'Etcher.Components.FlashErrorModal';
const FlashErrorModal = angular.module(MODULE_NAME, [
require('../warning-modal/warning-modal'),
require('../../models/selection-state')
require('../warning-modal/warning-modal')
]);
FlashErrorModal.service('FlashErrorModalService', require('./services/flash-error-modal'));

View File

@ -17,9 +17,10 @@
'use strict';
const flashState = require('../../../models/flash-state');
const selectionState = require('../../../models/selection-state');
const analytics = require('../../../modules/analytics');
module.exports = function(WarningModalService, SelectionStateModel) {
module.exports = function(WarningModalService) {
/**
* @summary Open the flash error modal
@ -42,7 +43,7 @@ module.exports = function(WarningModalService, SelectionStateModel) {
if (confirmed) {
analytics.logEvent('Restart after failure');
} else {
SelectionStateModel.clear();
selectionState.clear();
}
});
};

View File

@ -16,338 +16,325 @@
'use strict';
/**
* @module Etcher.Models.SelectionState
*/
const _ = require('lodash');
const angular = require('angular');
const Store = require('./store');
const availableDrives = require('./available-drives');
const MODULE_NAME = 'Etcher.Models.SelectionState';
const SelectionStateModel = angular.module(MODULE_NAME, []);
SelectionStateModel.service('SelectionStateModel', function() {
/**
* @summary Set a drive
* @function
* @public
*
* @param {String} drive - drive device
*
* @example
* selectionState.setDrive('/dev/disk2');
*/
exports.setDrive = (drive) => {
Store.dispatch({
type: Store.Actions.SELECT_DRIVE,
data: drive
});
};
/**
* @summary Set a drive
* @function
* @public
*
* @param {String} drive - drive device
*
* @example
* SelectionStateModel.setDrive('/dev/disk2');
*/
this.setDrive = (drive) => {
Store.dispatch({
type: Store.Actions.SELECT_DRIVE,
data: drive
});
};
/**
* @summary Toggle set drive
* @function
* @public
*
* @param {String} drive - drive device
*
* @example
* selectionState.toggleSetDrive('/dev/disk2');
*/
exports.toggleSetDrive = (drive) => {
if (exports.isCurrentDrive(drive)) {
exports.removeDrive();
} else {
exports.setDrive(drive);
}
};
/**
* @summary Toggle set drive
* @function
* @public
*
* @param {String} drive - drive device
*
* @example
* SelectionStateModel.toggleSetDrive('/dev/disk2');
*/
this.toggleSetDrive = (drive) => {
if (this.isCurrentDrive(drive)) {
this.removeDrive();
} else {
this.setDrive(drive);
}
};
/**
* @summary Set a image
* @function
* @public
*
* @param {Object} image - image
*
* @example
* selectionState.setImage({
* path: 'foo.img'
* });
*/
exports.setImage = (image) => {
Store.dispatch({
type: Store.Actions.SELECT_IMAGE,
data: image
});
};
/**
* @summary Set a image
* @function
* @public
*
* @param {Object} image - image
*
* @example
* SelectionStateModel.setImage({
* path: 'foo.img'
* });
*/
this.setImage = (image) => {
Store.dispatch({
type: Store.Actions.SELECT_IMAGE,
data: image
});
};
/**
* @summary Get drive
* @function
* @public
*
* @returns {Object} drive
*
* @example
* const drive = selectionState.getDrive();
*/
exports.getDrive = () => {
return _.find(availableDrives.getDrives(), {
device: Store.getState().getIn([ 'selection', 'drive' ])
});
};
/**
* @summary Get drive
* @function
* @public
*
* @returns {Object} drive
*
* @example
* const drive = SelectionStateModel.getDrive();
*/
this.getDrive = () => {
return _.find(availableDrives.getDrives(), {
device: Store.getState().getIn([ 'selection', 'drive' ])
});
};
/**
* @summary Get the selected image
* @function
* @public
*
* @returns {Object} image
*
* @example
* const image = selectionState.getImage();
*/
exports.getImage = () => {
return _.get(Store.getState().toJS(), [ 'selection', 'image' ]);
};
/**
* @summary Get the selected image
* @function
* @public
*
* @returns {Object} image
*
* @example
* const image = SelectionStateModel.getImage();
*/
this.getImage = () => {
return _.get(Store.getState().toJS(), [ 'selection', 'image' ]);
};
/**
* @summary Get image path
* @function
* @public
*
* @returns {String} image path
*
* @example
* const imagePath = selectionState.getImagePath();
*/
exports.getImagePath = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'path'
]);
};
/**
* @summary Get image path
* @function
* @public
*
* @returns {String} image path
*
* @example
* const imagePath = SelectionStateModel.getImagePath();
*/
this.getImagePath = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'path'
]);
};
/**
* @summary Get image size
* @function
* @public
*
* @returns {Number} image size
*
* @example
* const imageSize = selectionState.getImageSize();
*/
exports.getImageSize = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'size',
'final',
'value'
]);
};
/**
* @summary Get image size
* @function
* @public
*
* @returns {Number} image size
*
* @example
* const imageSize = SelectionStateModel.getImageSize();
*/
this.getImageSize = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'size',
'final',
'value'
]);
};
/**
* @summary Get image url
* @function
* @public
*
* @returns {String} image url
*
* @example
* const imageUrl = selectionState.getImageUrl();
*/
exports.getImageUrl = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'url'
]);
};
/**
* @summary Get image url
* @function
* @public
*
* @returns {String} image url
*
* @example
* const imageUrl = SelectionStateModel.getImageUrl();
*/
this.getImageUrl = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'url'
]);
};
/**
* @summary Get image name
* @function
* @public
*
* @returns {String} image name
*
* @example
* const imageName = selectionState.getImageName();
*/
exports.getImageName = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'name'
]);
};
/**
* @summary Get image name
* @function
* @public
*
* @returns {String} image name
*
* @example
* const imageName = SelectionStateModel.getImageName();
*/
this.getImageName = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'name'
]);
};
/**
* @summary Get image logo
* @function
* @public
*
* @returns {String} image logo
*
* @example
* const imageLogo = selectionState.getImageLogo();
*/
exports.getImageLogo = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'logo'
]);
};
/**
* @summary Get image logo
* @function
* @public
*
* @returns {String} image logo
*
* @example
* const imageLogo = SelectionStateModel.getImageLogo();
*/
this.getImageLogo = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'logo'
]);
};
/**
* @summary Get image support url
* @function
* @public
*
* @returns {String} image support url
*
* @example
* const imageSupportUrl = selectionState.getImageSupportUrl();
*/
exports.getImageSupportUrl = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'supportUrl'
]);
};
/**
* @summary Get image support url
* @function
* @public
*
* @returns {String} image support url
*
* @example
* const imageSupportUrl = SelectionStateModel.getImageSupportUrl();
*/
this.getImageSupportUrl = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'supportUrl'
]);
};
/**
* @summary Get image recommended drive size
* @function
* @public
*
* @returns {String} image recommended drive size
*
* @example
* const imageRecommendedDriveSize = selectionState.getImageRecommendedDriveSize();
*/
exports.getImageRecommendedDriveSize = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'recommendedDriveSize'
]);
};
/**
* @summary Get image recommended drive size
* @function
* @public
*
* @returns {String} image recommended drive size
*
* @example
* const imageRecommendedDriveSize = SelectionStateModel.getImageRecommendedDriveSize();
*/
this.getImageRecommendedDriveSize = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'recommendedDriveSize'
]);
};
/**
* @summary Check if there is a selected drive
* @function
* @public
*
* @returns {Boolean} whether there is a selected drive
*
* @example
* if (selectionState.hasDrive()) {
* console.log('There is a drive!');
* }
*/
exports.hasDrive = () => {
return Boolean(exports.getDrive());
};
/**
* @summary Check if there is a selected drive
* @function
* @public
*
* @returns {Boolean} whether there is a selected drive
*
* @example
* if (SelectionStateModel.hasDrive()) {
* console.log('There is a drive!');
* }
*/
this.hasDrive = () => {
return Boolean(this.getDrive());
};
/**
* @summary Check if there is a selected image
* @function
* @public
*
* @returns {Boolean} whether there is a selected image
*
* @example
* if (selectionState.hasImage()) {
* console.log('There is an image!');
* }
*/
exports.hasImage = () => {
return Boolean(exports.getImage());
};
/**
* @summary Check if there is a selected image
* @function
* @public
*
* @returns {Boolean} whether there is a selected image
*
* @example
* if (SelectionStateModel.hasImage()) {
* console.log('There is an image!');
* }
*/
this.hasImage = () => {
return Boolean(this.getImage());
};
/**
* @summary Remove drive
* @function
* @public
*
* @example
* selectionState.removeDrive();
*/
exports.removeDrive = () => {
Store.dispatch({
type: Store.Actions.REMOVE_DRIVE
});
};
/**
* @summary Remove drive
* @function
* @public
*
* @example
* SelectionStateModel.removeDrive();
*/
this.removeDrive = () => {
Store.dispatch({
type: Store.Actions.REMOVE_DRIVE
});
};
/**
* @summary Remove image
* @function
* @public
*
* @example
* selectionState.removeImage();
*/
exports.removeImage = () => {
Store.dispatch({
type: Store.Actions.REMOVE_IMAGE
});
};
/**
* @summary Remove image
* @function
* @public
*
* @example
* SelectionStateModel.removeImage();
*/
this.removeImage = () => {
/**
* @summary Clear selections
* @function
* @public
*
* @param {Object} options - options
* @param {Boolean} [options.preserveImage] - preserve image
*
* @example
* selectionState.clear();
*
* @example
* selectionState.clear({ preserveImage: true });
*/
exports.clear = (options = {}) => {
if (!options.preserveImage) {
Store.dispatch({
type: Store.Actions.REMOVE_IMAGE
});
};
}
/**
* @summary Clear selections
* @function
* @public
*
* @param {Object} options - options
* @param {Boolean} [options.preserveImage] - preserve image
*
* @example
* SelectionStateModel.clear();
*
* @example
* SelectionStateModel.clear({ preserveImage: true });
*/
this.clear = (options = {}) => {
if (!options.preserveImage) {
Store.dispatch({
type: Store.Actions.REMOVE_IMAGE
});
}
Store.dispatch({
type: Store.Actions.REMOVE_DRIVE
});
};
Store.dispatch({
type: Store.Actions.REMOVE_DRIVE
});
};
/**
* @summary Check if a drive is the current drive
* @function
* @public
*
* @param {String} drive - drive device
* @returns {Boolean} whether the drive is the current drive
*
* @example
* if (selectionState.isCurrentDrive('/dev/sdb')) {
* console.log('This is the current drive!');
* }
*/
exports.isCurrentDrive = (drive) => {
if (!drive) {
return false;
}
/**
* @summary Check if a drive is the current drive
* @function
* @public
*
* @param {String} drive - drive device
* @returns {Boolean} whether the drive is the current drive
*
* @example
* if (SelectionStateModel.isCurrentDrive('/dev/sdb')) {
* console.log('This is the current drive!');
* }
*/
this.isCurrentDrive = (drive) => {
if (!drive) {
return false;
}
return drive === _.get(this.getDrive(), [ 'device' ]);
};
});
module.exports = MODULE_NAME;
return drive === _.get(exports.getDrive(), [ 'device' ]);
};

View File

@ -18,9 +18,10 @@
const settings = require('../../../models/settings');
const flashState = require('../../../models/flash-state');
const selectionState = require('../../../models/selection-state');
const analytics = require('../../../modules/analytics');
module.exports = function($state, SelectionStateModel) {
module.exports = function($state) {
/**
* @summary Settings model
@ -48,7 +49,7 @@ module.exports = function($state, SelectionStateModel) {
* FinishController.restart({ preserveImage: true });
*/
this.restart = (options) => {
SelectionStateModel.clear(options);
selectionState.clear(options);
analytics.logEvent('Restart', options);
$state.go('main');
};

View File

@ -29,8 +29,7 @@
const angular = require('angular');
const MODULE_NAME = 'Etcher.Pages.Finish';
const FinishPage = angular.module(MODULE_NAME, [
require('angular-ui-router'),
require('../../models/selection-state')
require('angular-ui-router')
]);
FinishPage.controller('FinishController', require('./controllers/finish'));

View File

@ -17,9 +17,10 @@
'use strict';
const settings = require('../../../models/settings');
const selectionState = require('../../../models/selection-state');
const analytics = require('../../../modules/analytics');
module.exports = function(SelectionStateModel, ErrorService, DriveSelectorService) {
module.exports = function(ErrorService, DriveSelectorService) {
/**
* @summary Open drive selector
@ -35,7 +36,7 @@ module.exports = function(SelectionStateModel, ErrorService, DriveSelectorServic
return;
}
SelectionStateModel.setDrive(drive.device);
selectionState.setDrive(drive.device);
analytics.logEvent('Select drive', {
device: drive.device,

View File

@ -24,9 +24,9 @@ const errors = require('../../../../shared/errors');
const imageStream = require('../../../../image-stream');
const supportedFormats = require('../../../../shared/supported-formats');
const analytics = require('../../../modules/analytics');
const selectionState = require('../../../models/selection-state');
module.exports = function(
SelectionStateModel,
ErrorService,
OSDialogService,
WarningModalService
@ -100,7 +100,7 @@ module.exports = function(
return this.reselectImage();
}
SelectionStateModel.setImage(image);
selectionState.setImage(image);
// An easy way so we can quickly identify if we're making use of
// certain features without printing pages of text to DevTools.
@ -161,7 +161,7 @@ module.exports = function(
*/
this.reselectImage = () => {
analytics.logEvent('Reselect image', {
previousImage: SelectionStateModel.getImage()
previousImage: selectionState.getImage()
});
this.openImageSelector();
@ -178,11 +178,11 @@ module.exports = function(
* const imageBasename = ImageSelectionController.getImageBasename();
*/
this.getImageBasename = () => {
if (!SelectionStateModel.hasImage()) {
if (!selectionState.hasImage()) {
return '';
}
return path.basename(SelectionStateModel.getImagePath());
return path.basename(selectionState.getImagePath());
};
};

View File

@ -20,16 +20,16 @@ const settings = require('../../../models/settings');
const flashState = require('../../../models/flash-state');
const analytics = require('../../../modules/analytics');
const availableDrives = require('../../../models/available-drives');
const selectionState = require('../../../models/selection-state');
module.exports = function(
SelectionStateModel,
TooltipModalService,
ErrorService,
OSOpenExternalService
) {
// Expose several modules to the template for convenience
this.selection = SelectionStateModel;
this.selection = selectionState;
this.drives = availableDrives;
this.state = flashState;
this.settings = settings;
@ -48,7 +48,7 @@ module.exports = function(
* }
*/
this.shouldDriveStepBeDisabled = () => {
return !SelectionStateModel.hasImage();
return !selectionState.hasImage();
};
/**
@ -64,7 +64,7 @@ module.exports = function(
* }
*/
this.shouldFlashStepBeDisabled = () => {
return !SelectionStateModel.hasDrive() || this.shouldDriveStepBeDisabled();
return !selectionState.hasDrive() || this.shouldDriveStepBeDisabled();
};
/**
@ -79,12 +79,12 @@ module.exports = function(
*/
this.showSelectedImageDetails = () => {
analytics.logEvent('Show selected image tooltip', {
imagePath: SelectionStateModel.getImagePath()
imagePath: selectionState.getImagePath()
});
return TooltipModalService.show({
title: 'Image File Name',
message: SelectionStateModel.getImagePath()
message: selectionState.getImagePath()
}).catch(ErrorService.reportException);
};

View File

@ -46,7 +46,6 @@ const MainPage = angular.module(MODULE_NAME, [
require('../../modules/drive-scanner'),
require('../../modules/image-writer'),
require('../../modules/error'),
require('../../models/selection-state'),
require('../../utils/byte-size/byte-size')
]);

View File

@ -17,7 +17,6 @@ describe('Browser: DriveSelector', function() {
let $rootScope;
let $q;
let $uibModalInstance;
let SelectionStateModel;
let WarningModalService;
let controller;
@ -26,14 +25,12 @@ describe('Browser: DriveSelector', function() {
_$controller_,
_$rootScope_,
_$q_,
_SelectionStateModel_,
_WarningModalService_
) {
$controller = _$controller_;
$rootScope = _$rootScope_;
$q = _$q_;
$uibModalInstance = {};
SelectionStateModel = _SelectionStateModel_;
WarningModalService = _WarningModalService_;
}));
@ -42,7 +39,6 @@ describe('Browser: DriveSelector', function() {
$scope: $rootScope.$new(),
$q,
$uibModalInstance,
SelectionStateModel,
WarningModalService
});
});

View File

@ -2,24 +2,13 @@
const m = require('mochainon');
const path = require('path');
const angular = require('angular');
const availableDrives = require('../../../lib/gui/models/available-drives');
require('angular-mocks');
const selectionState = require('../../../lib/gui/models/selection-state');
describe('Browser: availableDrives', function() {
beforeEach(angular.mock.module(
require('../../../lib/gui/models/selection-state')
));
describe('availableDrives', function() {
let SelectionStateModel;
beforeEach(angular.mock.inject(function(_SelectionStateModel_) {
SelectionStateModel = _SelectionStateModel_;
}));
it('should have no drives by default', function() {
m.chai.expect(availableDrives.getDrives()).to.deep.equal([]);
});
@ -80,12 +69,12 @@ describe('Browser: availableDrives', function() {
describe('given no selected image and no selected drive', function() {
beforeEach(function() {
SelectionStateModel.removeDrive();
SelectionStateModel.removeImage();
selectionState.removeDrive();
selectionState.removeImage();
});
it('should auto-select a single valid available drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -98,8 +87,8 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
m.chai.expect(SelectionStateModel.getDrive().device).to.equal('/dev/sdb');
m.chai.expect(selectionState.hasDrive()).to.be.true;
m.chai.expect(selectionState.getDrive().device).to.equal('/dev/sdb');
});
});
@ -113,8 +102,8 @@ describe('Browser: availableDrives', function() {
this.imagePath = '/mnt/bar/foo.img';
}
SelectionStateModel.removeDrive();
SelectionStateModel.setImage({
selectionState.removeDrive();
selectionState.setImage({
path: this.imagePath,
extension: 'img',
size: {
@ -129,11 +118,11 @@ describe('Browser: availableDrives', function() {
});
afterEach(function() {
SelectionStateModel.removeImage();
selectionState.removeImage();
});
it('should not auto-select when there are multiple valid available drives', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -154,11 +143,11 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
it('should auto-select a single valid available drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -171,7 +160,7 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.getDrive()).to.deep.equal({
m.chai.expect(selectionState.getDrive()).to.deep.equal({
device: '/dev/sdb',
name: 'Foo',
size: 2000000000,
@ -182,7 +171,7 @@ describe('Browser: availableDrives', function() {
});
it('should not auto-select a single too small drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -195,11 +184,11 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
it('should not auto-select a single drive that doesn\'t meet the recommended size', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -212,11 +201,11 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
it('should not auto-select a single protected drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -229,11 +218,11 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
it('should not auto-select a source drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -250,11 +239,11 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
it('should not auto-select a single system drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
availableDrives.setDrives([
{
@ -267,7 +256,7 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
});
@ -315,15 +304,15 @@ describe('Browser: availableDrives', function() {
}
]);
SelectionStateModel.setDrive('/dev/sdc');
selectionState.setDrive('/dev/sdc');
});
afterEach(function() {
SelectionStateModel.removeDrive();
selectionState.removeDrive();
});
it('should be deleted if its not contained in the available drives anymore', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
m.chai.expect(selectionState.hasDrive()).to.be.true;
// We have to provide at least two drives, otherwise,
// if we only provide one, the single drive will be
@ -347,7 +336,7 @@ describe('Browser: availableDrives', function() {
}
]);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
});

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ const angular = require('angular');
const settings = require('../../../lib/gui/models/settings');
const flashState = require('../../../lib/gui/models/flash-state');
const availableDrives = require('../../../lib/gui/models/available-drives');
const selectionState = require('../../../lib/gui/models/selection-state');
require('angular-mocks');
describe('Browser: MainPage', function() {
@ -19,11 +20,9 @@ describe('Browser: MainPage', function() {
describe('MainController', function() {
let $controller;
let SelectionStateModel;
beforeEach(angular.mock.inject(function(_$controller_, _SelectionStateModel_) {
beforeEach(angular.mock.inject(function(_$controller_) {
$controller = _$controller_;
SelectionStateModel = _SelectionStateModel_;
}));
describe('.shouldDriveStepBeDisabled()', function() {
@ -33,7 +32,7 @@ describe('Browser: MainPage', function() {
$scope: {}
});
SelectionStateModel.clear();
selectionState.clear();
m.chai.expect(controller.shouldDriveStepBeDisabled()).to.be.true;
});
@ -43,7 +42,7 @@ describe('Browser: MainPage', function() {
$scope: {}
});
SelectionStateModel.setImage({
selectionState.setImage({
path: 'rpi.img',
extension: 'img',
size: {
@ -67,7 +66,7 @@ describe('Browser: MainPage', function() {
$scope: {}
});
SelectionStateModel.clear();
selectionState.clear();
m.chai.expect(controller.shouldFlashStepBeDisabled()).to.be.true;
});
@ -77,8 +76,8 @@ describe('Browser: MainPage', function() {
$scope: {}
});
SelectionStateModel.clear();
SelectionStateModel.setImage({
selectionState.clear();
selectionState.setImage({
path: 'rpi.img',
extension: 'img',
size: {
@ -108,8 +107,8 @@ describe('Browser: MainPage', function() {
}
]);
SelectionStateModel.clear();
SelectionStateModel.setDrive('/dev/disk2');
selectionState.clear();
selectionState.setDrive('/dev/disk2');
m.chai.expect(controller.shouldFlashStepBeDisabled()).to.be.true;
});
@ -129,10 +128,10 @@ describe('Browser: MainPage', function() {
}
]);
SelectionStateModel.clear();
SelectionStateModel.setDrive('/dev/disk2');
selectionState.clear();
selectionState.setDrive('/dev/disk2');
SelectionStateModel.setImage({
selectionState.setImage({
path: 'rpi.img',
extension: 'img',
size: {
@ -154,11 +153,9 @@ describe('Browser: MainPage', function() {
describe('ImageSelectionController', function() {
let $controller;
let SelectionStateModel;
beforeEach(angular.mock.inject(function(_$controller_, _SelectionStateModel_) {
beforeEach(angular.mock.inject(function(_$controller_) {
$controller = _$controller_;
SelectionStateModel = _SelectionStateModel_;
}));
it('should contain all available extensions in mainSupportedExtensions and extraSupportedExtensions', function() {
@ -178,7 +175,7 @@ describe('Browser: MainPage', function() {
$scope: {}
});
SelectionStateModel.setImage({
selectionState.setImage({
path: path.join(__dirname, 'foo', 'bar.img'),
extension: 'img',
size: {
@ -191,7 +188,7 @@ describe('Browser: MainPage', function() {
});
m.chai.expect(controller.getImageBasename()).to.equal('bar.img');
SelectionStateModel.removeImage();
selectionState.removeImage();
});
it('should return an empty string if no selected image', function() {
@ -199,7 +196,7 @@ describe('Browser: MainPage', function() {
$scope: {}
});
SelectionStateModel.removeImage();
selectionState.removeImage();
m.chai.expect(controller.getImageBasename()).to.equal('');
});