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,20 +16,11 @@
'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
@ -37,16 +28,16 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @param {String} drive - drive device
*
* @example
* SelectionStateModel.setDrive('/dev/disk2');
* selectionState.setDrive('/dev/disk2');
*/
this.setDrive = (drive) => {
exports.setDrive = (drive) => {
Store.dispatch({
type: Store.Actions.SELECT_DRIVE,
data: drive
});
};
};
/**
/**
* @summary Toggle set drive
* @function
* @public
@ -54,17 +45,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @param {String} drive - drive device
*
* @example
* SelectionStateModel.toggleSetDrive('/dev/disk2');
* selectionState.toggleSetDrive('/dev/disk2');
*/
this.toggleSetDrive = (drive) => {
if (this.isCurrentDrive(drive)) {
this.removeDrive();
exports.toggleSetDrive = (drive) => {
if (exports.isCurrentDrive(drive)) {
exports.removeDrive();
} else {
this.setDrive(drive);
exports.setDrive(drive);
}
};
};
/**
/**
* @summary Set a image
* @function
* @public
@ -72,18 +63,18 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @param {Object} image - image
*
* @example
* SelectionStateModel.setImage({
* selectionState.setImage({
* path: 'foo.img'
* });
*/
this.setImage = (image) => {
exports.setImage = (image) => {
Store.dispatch({
type: Store.Actions.SELECT_IMAGE,
data: image
});
};
};
/**
/**
* @summary Get drive
* @function
* @public
@ -91,15 +82,15 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {Object} drive
*
* @example
* const drive = SelectionStateModel.getDrive();
* const drive = selectionState.getDrive();
*/
this.getDrive = () => {
exports.getDrive = () => {
return _.find(availableDrives.getDrives(), {
device: Store.getState().getIn([ 'selection', 'drive' ])
});
};
};
/**
/**
* @summary Get the selected image
* @function
* @public
@ -107,13 +98,13 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {Object} image
*
* @example
* const image = SelectionStateModel.getImage();
* const image = selectionState.getImage();
*/
this.getImage = () => {
exports.getImage = () => {
return _.get(Store.getState().toJS(), [ 'selection', 'image' ]);
};
};
/**
/**
* @summary Get image path
* @function
* @public
@ -121,17 +112,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {String} image path
*
* @example
* const imagePath = SelectionStateModel.getImagePath();
* const imagePath = selectionState.getImagePath();
*/
this.getImagePath = () => {
exports.getImagePath = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'path'
]);
};
};
/**
/**
* @summary Get image size
* @function
* @public
@ -139,9 +130,9 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {Number} image size
*
* @example
* const imageSize = SelectionStateModel.getImageSize();
* const imageSize = selectionState.getImageSize();
*/
this.getImageSize = () => {
exports.getImageSize = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
@ -149,9 +140,9 @@ SelectionStateModel.service('SelectionStateModel', function() {
'final',
'value'
]);
};
};
/**
/**
* @summary Get image url
* @function
* @public
@ -159,17 +150,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {String} image url
*
* @example
* const imageUrl = SelectionStateModel.getImageUrl();
* const imageUrl = selectionState.getImageUrl();
*/
this.getImageUrl = () => {
exports.getImageUrl = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'url'
]);
};
};
/**
/**
* @summary Get image name
* @function
* @public
@ -177,17 +168,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {String} image name
*
* @example
* const imageName = SelectionStateModel.getImageName();
* const imageName = selectionState.getImageName();
*/
this.getImageName = () => {
exports.getImageName = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'name'
]);
};
};
/**
/**
* @summary Get image logo
* @function
* @public
@ -195,17 +186,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {String} image logo
*
* @example
* const imageLogo = SelectionStateModel.getImageLogo();
* const imageLogo = selectionState.getImageLogo();
*/
this.getImageLogo = () => {
exports.getImageLogo = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'logo'
]);
};
};
/**
/**
* @summary Get image support url
* @function
* @public
@ -213,17 +204,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {String} image support url
*
* @example
* const imageSupportUrl = SelectionStateModel.getImageSupportUrl();
* const imageSupportUrl = selectionState.getImageSupportUrl();
*/
this.getImageSupportUrl = () => {
exports.getImageSupportUrl = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'supportUrl'
]);
};
};
/**
/**
* @summary Get image recommended drive size
* @function
* @public
@ -231,17 +222,17 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {String} image recommended drive size
*
* @example
* const imageRecommendedDriveSize = SelectionStateModel.getImageRecommendedDriveSize();
* const imageRecommendedDriveSize = selectionState.getImageRecommendedDriveSize();
*/
this.getImageRecommendedDriveSize = () => {
exports.getImageRecommendedDriveSize = () => {
return _.get(Store.getState().toJS(), [
'selection',
'image',
'recommendedDriveSize'
]);
};
};
/**
/**
* @summary Check if there is a selected drive
* @function
* @public
@ -249,15 +240,15 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {Boolean} whether there is a selected drive
*
* @example
* if (SelectionStateModel.hasDrive()) {
* if (selectionState.hasDrive()) {
* console.log('There is a drive!');
* }
*/
this.hasDrive = () => {
return Boolean(this.getDrive());
};
exports.hasDrive = () => {
return Boolean(exports.getDrive());
};
/**
/**
* @summary Check if there is a selected image
* @function
* @public
@ -265,43 +256,43 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {Boolean} whether there is a selected image
*
* @example
* if (SelectionStateModel.hasImage()) {
* if (selectionState.hasImage()) {
* console.log('There is an image!');
* }
*/
this.hasImage = () => {
return Boolean(this.getImage());
};
exports.hasImage = () => {
return Boolean(exports.getImage());
};
/**
/**
* @summary Remove drive
* @function
* @public
*
* @example
* SelectionStateModel.removeDrive();
* selectionState.removeDrive();
*/
this.removeDrive = () => {
exports.removeDrive = () => {
Store.dispatch({
type: Store.Actions.REMOVE_DRIVE
});
};
};
/**
/**
* @summary Remove image
* @function
* @public
*
* @example
* SelectionStateModel.removeImage();
* selectionState.removeImage();
*/
this.removeImage = () => {
exports.removeImage = () => {
Store.dispatch({
type: Store.Actions.REMOVE_IMAGE
});
};
};
/**
/**
* @summary Clear selections
* @function
* @public
@ -310,12 +301,12 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @param {Boolean} [options.preserveImage] - preserve image
*
* @example
* SelectionStateModel.clear();
* selectionState.clear();
*
* @example
* SelectionStateModel.clear({ preserveImage: true });
* selectionState.clear({ preserveImage: true });
*/
this.clear = (options = {}) => {
exports.clear = (options = {}) => {
if (!options.preserveImage) {
Store.dispatch({
type: Store.Actions.REMOVE_IMAGE
@ -325,9 +316,9 @@ SelectionStateModel.service('SelectionStateModel', function() {
Store.dispatch({
type: Store.Actions.REMOVE_DRIVE
});
};
};
/**
/**
* @summary Check if a drive is the current drive
* @function
* @public
@ -336,18 +327,14 @@ SelectionStateModel.service('SelectionStateModel', function() {
* @returns {Boolean} whether the drive is the current drive
*
* @example
* if (SelectionStateModel.isCurrentDrive('/dev/sdb')) {
* if (selectionState.isCurrentDrive('/dev/sdb')) {
* console.log('This is the current drive!');
* }
*/
this.isCurrentDrive = (drive) => {
exports.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;
});
});

View File

@ -3,74 +3,61 @@
const m = require('mochainon');
const _ = require('lodash');
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: SelectionState', function() {
beforeEach(angular.mock.module(
require('../../../lib/gui/models/selection-state')
));
describe('SelectionStateModel', function() {
let SelectionStateModel;
beforeEach(angular.mock.inject(function(_SelectionStateModel_) {
SelectionStateModel = _SelectionStateModel_;
}));
describe('Browser: selectionState', function() {
describe('given a clean state', function() {
beforeEach(function() {
SelectionStateModel.clear();
selectionState.clear();
});
it('getDrive() should return undefined', function() {
const drive = SelectionStateModel.getDrive();
const drive = selectionState.getDrive();
m.chai.expect(drive).to.be.undefined;
});
it('getImage() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImage()).to.be.undefined;
m.chai.expect(selectionState.getImage()).to.be.undefined;
});
it('getImagePath() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImagePath()).to.be.undefined;
m.chai.expect(selectionState.getImagePath()).to.be.undefined;
});
it('getImageSize() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImageSize()).to.be.undefined;
m.chai.expect(selectionState.getImageSize()).to.be.undefined;
});
it('getImageUrl() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImageUrl()).to.be.undefined;
m.chai.expect(selectionState.getImageUrl()).to.be.undefined;
});
it('getImageName() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImageName()).to.be.undefined;
m.chai.expect(selectionState.getImageName()).to.be.undefined;
});
it('getImageLogo() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImageLogo()).to.be.undefined;
m.chai.expect(selectionState.getImageLogo()).to.be.undefined;
});
it('getImageSupportUrl() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImageSupportUrl()).to.be.undefined;
m.chai.expect(selectionState.getImageSupportUrl()).to.be.undefined;
});
it('getImageRecommendedDriveSize() should return undefined', function() {
m.chai.expect(SelectionStateModel.getImageRecommendedDriveSize()).to.be.undefined;
m.chai.expect(selectionState.getImageRecommendedDriveSize()).to.be.undefined;
});
it('hasDrive() should return false', function() {
const hasDrive = SelectionStateModel.hasDrive();
const hasDrive = selectionState.hasDrive();
m.chai.expect(hasDrive).to.be.false;
});
it('hasImage() should return false', function() {
const hasImage = SelectionStateModel.hasImage();
const hasImage = selectionState.hasImage();
m.chai.expect(hasImage).to.be.false;
});
@ -94,13 +81,13 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/disk2');
selectionState.setDrive('/dev/disk2');
});
describe('.getDrive()', function() {
it('should return the drive', function() {
const drive = SelectionStateModel.getDrive();
const drive = selectionState.getDrive();
m.chai.expect(drive).to.deep.equal({
device: '/dev/disk2',
name: 'USB Drive',
@ -114,7 +101,7 @@ describe('Browser: SelectionState', function() {
describe('.hasDrive()', function() {
it('should return true', function() {
const hasDrive = SelectionStateModel.hasDrive();
const hasDrive = selectionState.hasDrive();
m.chai.expect(hasDrive).to.be.true;
});
@ -123,8 +110,8 @@ describe('Browser: SelectionState', function() {
describe('.setDrive()', function() {
it('should override the drive', function() {
SelectionStateModel.setDrive('/dev/disk5');
const drive = SelectionStateModel.getDrive();
selectionState.setDrive('/dev/disk5');
const drive = selectionState.getDrive();
m.chai.expect(drive).to.deep.equal({
device: '/dev/disk5',
name: 'USB Drive',
@ -138,8 +125,8 @@ describe('Browser: SelectionState', function() {
describe('.removeDrive()', function() {
it('should clear the drive', function() {
SelectionStateModel.removeDrive();
const drive = SelectionStateModel.getDrive();
selectionState.removeDrive();
const drive = selectionState.getDrive();
m.chai.expect(drive).to.be.undefined;
});
@ -161,8 +148,8 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/disk5');
const drive = SelectionStateModel.getDrive();
selectionState.setDrive('/dev/disk5');
const drive = selectionState.getDrive();
m.chai.expect(drive).to.deep.equal({
device: '/dev/disk5',
name: 'USB Drive',
@ -182,7 +169,7 @@ describe('Browser: SelectionState', function() {
]);
m.chai.expect(function() {
SelectionStateModel.setDrive('/dev/disk1');
selectionState.setDrive('/dev/disk1');
}).to.throw('The drive is write-protected');
});
@ -197,13 +184,13 @@ describe('Browser: SelectionState', function() {
]);
m.chai.expect(function() {
SelectionStateModel.setDrive('/dev/disk5');
selectionState.setDrive('/dev/disk5');
}).to.throw('The drive is not available: /dev/disk5');
});
it('should throw if device is not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setDrive(123);
selectionState.setDrive(123);
}).to.throw('Invalid drive: 123');
});
@ -231,7 +218,7 @@ describe('Browser: SelectionState', function() {
logo: '<svg><text fill="red">Raspbian</text></svg>'
};
SelectionStateModel.setImage(this.image);
selectionState.setImage(this.image);
});
describe('.setDrive()', function() {
@ -247,7 +234,7 @@ describe('Browser: SelectionState', function() {
]);
m.chai.expect(function() {
SelectionStateModel.setDrive('/dev/disk2');
selectionState.setDrive('/dev/disk2');
}).to.throw('The drive is not large enough');
});
@ -256,7 +243,7 @@ describe('Browser: SelectionState', function() {
describe('.getImage()', function() {
it('should return the image', function() {
m.chai.expect(SelectionStateModel.getImage()).to.deep.equal(this.image);
m.chai.expect(selectionState.getImage()).to.deep.equal(this.image);
});
});
@ -264,7 +251,7 @@ describe('Browser: SelectionState', function() {
describe('.getImagePath()', function() {
it('should return the image path', function() {
const imagePath = SelectionStateModel.getImagePath();
const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.equal('foo.img');
});
@ -273,7 +260,7 @@ describe('Browser: SelectionState', function() {
describe('.getImageSize()', function() {
it('should return the image size', function() {
const imageSize = SelectionStateModel.getImageSize();
const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.equal(999999999);
});
@ -282,7 +269,7 @@ describe('Browser: SelectionState', function() {
describe('.getImageUrl()', function() {
it('should return the image url', function() {
const imageUrl = SelectionStateModel.getImageUrl();
const imageUrl = selectionState.getImageUrl();
m.chai.expect(imageUrl).to.equal('https://www.raspbian.org');
});
@ -291,7 +278,7 @@ describe('Browser: SelectionState', function() {
describe('.getImageName()', function() {
it('should return the image name', function() {
const imageName = SelectionStateModel.getImageName();
const imageName = selectionState.getImageName();
m.chai.expect(imageName).to.equal('Raspbian');
});
@ -300,7 +287,7 @@ describe('Browser: SelectionState', function() {
describe('.getImageLogo()', function() {
it('should return the image logo', function() {
const imageLogo = SelectionStateModel.getImageLogo();
const imageLogo = selectionState.getImageLogo();
m.chai.expect(imageLogo).to.equal('<svg><text fill="red">Raspbian</text></svg>');
});
@ -309,7 +296,7 @@ describe('Browser: SelectionState', function() {
describe('.getImageSupportUrl()', function() {
it('should return the image support url', function() {
const imageSupportUrl = SelectionStateModel.getImageSupportUrl();
const imageSupportUrl = selectionState.getImageSupportUrl();
m.chai.expect(imageSupportUrl).to.equal('https://www.raspbian.org/forums/');
});
@ -318,7 +305,7 @@ describe('Browser: SelectionState', function() {
describe('.getImageRecommendedDriveSize()', function() {
it('should return the image recommended drive size', function() {
const imageRecommendedDriveSize = SelectionStateModel.getImageRecommendedDriveSize();
const imageRecommendedDriveSize = selectionState.getImageRecommendedDriveSize();
m.chai.expect(imageRecommendedDriveSize).to.equal(1000000000);
});
@ -327,7 +314,7 @@ describe('Browser: SelectionState', function() {
describe('.hasImage()', function() {
it('should return true', function() {
const hasImage = SelectionStateModel.hasImage();
const hasImage = selectionState.hasImage();
m.chai.expect(hasImage).to.be.true;
});
@ -336,7 +323,7 @@ describe('Browser: SelectionState', function() {
describe('.setImage()', function() {
it('should override the image', function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'bar.img',
extension: 'img',
size: {
@ -348,9 +335,9 @@ describe('Browser: SelectionState', function() {
}
});
const imagePath = SelectionStateModel.getImagePath();
const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.equal('bar.img');
const imageSize = SelectionStateModel.getImageSize();
const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.equal(999999999);
});
@ -359,11 +346,11 @@ describe('Browser: SelectionState', function() {
describe('.removeImage()', function() {
it('should clear the image', function() {
SelectionStateModel.removeImage();
selectionState.removeImage();
const imagePath = SelectionStateModel.getImagePath();
const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.be.undefined;
const imageSize = SelectionStateModel.getImageSize();
const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.be.undefined;
});
@ -376,7 +363,7 @@ describe('Browser: SelectionState', function() {
describe('.setImage()', function() {
it('should be able to set an image', function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -388,14 +375,14 @@ describe('Browser: SelectionState', function() {
}
});
const imagePath = SelectionStateModel.getImagePath();
const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.equal('foo.img');
const imageSize = SelectionStateModel.getImageSize();
const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.equal(999999999);
});
it('should be able to set an image with an archive extension', function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.zip',
extension: 'img',
archiveExtension: 'zip',
@ -408,13 +395,13 @@ describe('Browser: SelectionState', function() {
}
});
const imagePath = SelectionStateModel.getImagePath();
const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.equal('foo.zip');
});
it('should throw if no path', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
extension: 'img',
size: {
original: 999999999,
@ -429,7 +416,7 @@ describe('Browser: SelectionState', function() {
it('should throw if path is not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 123,
extension: 'img',
size: {
@ -445,7 +432,7 @@ describe('Browser: SelectionState', function() {
it('should throw if no extension', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
size: {
original: 999999999,
@ -460,7 +447,7 @@ describe('Browser: SelectionState', function() {
it('should throw if extension is not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 1,
size: {
@ -476,7 +463,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the extension doesn\'t match the path and there is no archive extension', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'iso',
size: {
@ -492,7 +479,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the extension doesn\'t match the path and the archive extension is not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'iso',
archiveExtension: 1,
@ -509,7 +496,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the archive extension doesn\'t match the last path extension in a compressed image', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img.xz',
extension: 'img',
archiveExtension: 'gz',
@ -526,7 +513,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the extension is not recognised in an uncompressed image', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.ifg',
extension: 'ifg',
size: {
@ -542,7 +529,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the extension is not recognised in a compressed image', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.ifg.gz',
extension: 'ifg',
archiveExtension: 'gz',
@ -559,7 +546,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the archive extension is not recognised', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img.ifg',
extension: 'img',
archiveExtension: 'ifg',
@ -576,7 +563,7 @@ describe('Browser: SelectionState', function() {
it('should throw if no size', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img'
});
@ -585,7 +572,7 @@ describe('Browser: SelectionState', function() {
it('should throw if size is not a plain object', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: 999999999
@ -595,7 +582,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the original size is not a number', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -611,7 +598,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the original size is a float number', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -627,7 +614,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the original size is negative', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -643,7 +630,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the final size is not a number', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -659,7 +646,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the final size is a float number', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -675,7 +662,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the final size is negative', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -691,7 +678,7 @@ describe('Browser: SelectionState', function() {
it('should throw if the final size estimation flag is not a boolean', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -707,7 +694,7 @@ describe('Browser: SelectionState', function() {
it('should throw if url is defined but it\'s not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -724,7 +711,7 @@ describe('Browser: SelectionState', function() {
it('should throw if name is defined but it\'s not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -741,7 +728,7 @@ describe('Browser: SelectionState', function() {
it('should throw if logo is defined but it\'s not a string', function() {
m.chai.expect(function() {
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -766,10 +753,10 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/disk1');
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
selectionState.setDrive('/dev/disk1');
m.chai.expect(selectionState.hasDrive()).to.be.true;
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -781,8 +768,8 @@ describe('Browser: SelectionState', function() {
}
});
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
SelectionStateModel.removeImage();
m.chai.expect(selectionState.hasDrive()).to.be.false;
selectionState.removeImage();
});
it('should de-select a previously selected not-recommended drive', function() {
@ -795,10 +782,10 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/disk1');
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
selectionState.setDrive('/dev/disk1');
m.chai.expect(selectionState.hasDrive()).to.be.true;
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -811,8 +798,8 @@ describe('Browser: SelectionState', function() {
recommendedDriveSize: 1500000000
});
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
SelectionStateModel.removeImage();
m.chai.expect(selectionState.hasDrive()).to.be.false;
selectionState.removeImage();
});
it('should de-select a previously selected source drive', function() {
@ -838,10 +825,10 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/disk1');
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
selectionState.setDrive('/dev/disk1');
m.chai.expect(selectionState.hasDrive()).to.be.true;
SelectionStateModel.setImage({
selectionState.setImage({
path: imagePath,
extension: 'img',
size: {
@ -853,8 +840,8 @@ describe('Browser: SelectionState', function() {
}
});
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
SelectionStateModel.removeImage();
m.chai.expect(selectionState.hasDrive()).to.be.false;
selectionState.removeImage();
});
});
@ -873,9 +860,9 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/disk1');
selectionState.setDrive('/dev/disk1');
SelectionStateModel.setImage({
selectionState.setImage({
path: 'foo.img',
extension: 'img',
size: {
@ -891,13 +878,13 @@ describe('Browser: SelectionState', function() {
describe('.clear()', function() {
it('should clear all selections', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
m.chai.expect(SelectionStateModel.hasImage()).to.be.true;
m.chai.expect(selectionState.hasDrive()).to.be.true;
m.chai.expect(selectionState.hasImage()).to.be.true;
SelectionStateModel.clear();
selectionState.clear();
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(SelectionStateModel.hasImage()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasImage()).to.be.false;
});
});
@ -905,33 +892,33 @@ describe('Browser: SelectionState', function() {
describe('given the preserveImage option', function() {
beforeEach(function() {
SelectionStateModel.clear({
selectionState.clear({
preserveImage: true
});
});
it('getDrive() should return undefined', function() {
const drive = SelectionStateModel.getDrive();
const drive = selectionState.getDrive();
m.chai.expect(drive).to.be.undefined;
});
it('getImagePath() should return the image path', function() {
const imagePath = SelectionStateModel.getImagePath();
const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.equal('foo.img');
});
it('getImageSize() should return the image size', function() {
const imageSize = SelectionStateModel.getImageSize();
const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.equal(999999999);
});
it('hasDrive() should return false', function() {
const hasDrive = SelectionStateModel.hasDrive();
const hasDrive = selectionState.hasDrive();
m.chai.expect(hasDrive).to.be.false;
});
it('hasImage() should return true', function() {
const hasImage = SelectionStateModel.hasImage();
const hasImage = selectionState.hasImage();
m.chai.expect(hasImage).to.be.true;
});
@ -956,19 +943,19 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive('/dev/sdb');
selectionState.setDrive('/dev/sdb');
});
it('should return false if an undefined value is passed', function() {
m.chai.expect(SelectionStateModel.isCurrentDrive()).to.be.false;
m.chai.expect(selectionState.isCurrentDrive()).to.be.false;
});
it('should return true given the exact same drive', function() {
m.chai.expect(SelectionStateModel.isCurrentDrive('/dev/sdb')).to.be.true;
m.chai.expect(selectionState.isCurrentDrive('/dev/sdb')).to.be.true;
});
it('should return false if it is not the current drive', function() {
m.chai.expect(SelectionStateModel.isCurrentDrive('/dev/sdc')).to.be.false;
m.chai.expect(selectionState.isCurrentDrive('/dev/sdc')).to.be.false;
});
});
@ -976,15 +963,15 @@ describe('Browser: SelectionState', function() {
describe('given no selected drive', function() {
beforeEach(function() {
SelectionStateModel.removeDrive();
selectionState.removeDrive();
});
it('should return false if an undefined value is passed', function() {
m.chai.expect(SelectionStateModel.isCurrentDrive()).to.be.false;
m.chai.expect(selectionState.isCurrentDrive()).to.be.false;
});
it('should return false for anything', function() {
m.chai.expect(SelectionStateModel.isCurrentDrive('/dev/sdb')).to.be.false;
m.chai.expect(selectionState.isCurrentDrive('/dev/sdb')).to.be.false;
});
});
@ -1016,13 +1003,13 @@ describe('Browser: SelectionState', function() {
}
]);
SelectionStateModel.setDrive(this.drive.device);
selectionState.setDrive(this.drive.device);
});
it('should be able to remove the drive', function() {
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
SelectionStateModel.toggleSetDrive(this.drive.device);
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasDrive()).to.be.true;
selectionState.toggleSetDrive(this.drive.device);
m.chai.expect(selectionState.hasDrive()).to.be.false;
});
it('should be able to replace the drive', function() {
@ -1033,10 +1020,10 @@ describe('Browser: SelectionState', function() {
protected: false
};
m.chai.expect(SelectionStateModel.getDrive()).to.deep.equal(this.drive);
SelectionStateModel.toggleSetDrive(drive.device);
m.chai.expect(SelectionStateModel.getDrive()).to.deep.equal(drive);
m.chai.expect(SelectionStateModel.getDrive()).to.not.deep.equal(this.drive);
m.chai.expect(selectionState.getDrive()).to.deep.equal(this.drive);
selectionState.toggleSetDrive(drive.device);
m.chai.expect(selectionState.getDrive()).to.deep.equal(drive);
m.chai.expect(selectionState.getDrive()).to.not.deep.equal(this.drive);
});
});
@ -1044,7 +1031,7 @@ describe('Browser: SelectionState', function() {
describe('given no selected drive', function() {
beforeEach(function() {
SelectionStateModel.removeDrive();
selectionState.removeDrive();
});
it('should set the drive', function() {
@ -1055,11 +1042,9 @@ describe('Browser: SelectionState', function() {
protected: false
};
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
SelectionStateModel.toggleSetDrive(drive.device);
m.chai.expect(SelectionStateModel.getDrive()).to.deep.equal(drive);
});
m.chai.expect(selectionState.hasDrive()).to.be.false;
selectionState.toggleSetDrive(drive.device);
m.chai.expect(selectionState.getDrive()).to.deep.equal(drive);
});
});

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('');
});