refactor(GUI): get rid of drive-constraints Angular factory wrapper (#1250)

Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2017-04-04 13:44:03 -04:00 committed by GitHub
parent 71d5fad2b0
commit e16234e3e8
4 changed files with 4 additions and 70 deletions

View File

@ -18,6 +18,7 @@
const _ = require('lodash');
const messages = require('../../../../shared/messages');
const constraints = require('../../../../shared/drive-constraints');
module.exports = function(
$q,
@ -25,7 +26,6 @@ module.exports = function(
DrivesModel,
SelectionStateModel,
WarningModalService,
DriveConstraintsModel,
AnalyticsService
) {
@ -41,7 +41,7 @@ module.exports = function(
* @type {Object}
* @public
*/
this.constraints = DriveConstraintsModel;
this.constraints = constraints;
/**
* @summary The drives model
@ -71,11 +71,11 @@ module.exports = function(
* });
*/
const shouldChangeDriveSelectionState = (drive) => {
if (!DriveConstraintsModel.isDriveValid(drive, SelectionStateModel.getImage())) {
if (!constraints.isDriveValid(drive, SelectionStateModel.getImage())) {
return $q.resolve(false);
}
if (DriveConstraintsModel.isDriveSizeRecommended(drive, SelectionStateModel.getImage())) {
if (constraints.isDriveSizeRecommended(drive, SelectionStateModel.getImage())) {
return $q.resolve(true);
}

View File

@ -27,7 +27,6 @@ const DriveSelector = angular.module(MODULE_NAME, [
require('../warning-modal/warning-modal'),
require('../../models/drives'),
require('../../models/selection-state'),
require('../../models/drive-constraints'),
require('../../utils/byte-size/byte-size'),
require('../../modules/analytics')
]);

View File

@ -1,37 +0,0 @@
/*
* Copyright 2016 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
/**
* @summary Expose a CLI/GUI shared utility object as an AngularJS service
* @module Etcher.Models.DriveConstraints
*/
const angular = require('angular');
const MODULE_NAME = 'Etcher.Models.DriveConstraints';
const DriveConstraintsModel = angular.module(MODULE_NAME, []);
const DriveConstraints = require('../../shared/drive-constraints');
// `DriveConstraintsModel.service` expects a constructor as the second argument, but we want
// to expose an object. Calling `DriveConstraintsModel.factory` with a a function returning
// the object is the right way to do it.
DriveConstraintsModel.factory('DriveConstraintsModel', () => {
return DriveConstraints;
});
module.exports = MODULE_NAME;

View File

@ -1,28 +0,0 @@
'use strict';
const m = require('mochainon');
const angular = require('angular');
require('angular-mocks');
describe('Browser: DriveConstraints', function() {
beforeEach(angular.mock.module(
require('../../../lib/gui/models/drive-constraints')
));
describe('DriveConstraintsModel', function() {
let DriveConstraintsModel;
beforeEach(angular.mock.inject(function(_DriveConstraintsModel_) {
DriveConstraintsModel = _DriveConstraintsModel_;
}));
it('should be the `lib/shared/drive-constraints.js` object', function() {
const DriveConstraints = require('../../../lib/shared/drive-constraints');
m.chai.expect(Object.is(DriveConstraintsModel, DriveConstraints)).to.be.true;
});
});
});