Skip to content

Commit

Permalink
feat(gui): Display image size when drive too small
Browse files Browse the repository at this point in the history
This adds a display of the determined image size to the
drive label when the drive has been determined to be too small.

Change-Type: patch
Changelog-Entry: Display image size for comparison if drive is too small
  • Loading branch information
jhermsmeier committed Jan 15, 2018
1 parent 759004e commit d94039a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/shared/drive-constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

const _ = require('lodash')
const pathIsInside = require('path-is-inside')
const prettyBytes = require('pretty-bytes')

/**
* @summary The default unknown size for things such as images and drives
Expand Down Expand Up @@ -305,7 +306,7 @@ exports.COMPATIBILITY_STATUS_MESSAGES = {
* @description
* The drive is too small for the image.
*/
TOO_SMALL: 'Too Small For Image',
TOO_SMALL: 'Insufficient space, additional XX required',

/**
* @property {String} LOCKED
Expand Down Expand Up @@ -406,9 +407,11 @@ exports.getDriveImageCompatibilityStatuses = (drive, image) => {
message: exports.COMPATIBILITY_STATUS_MESSAGES.LOCKED
})
} else if (!_.isNil(drive) && !_.isNil(drive.size) && !exports.isDriveLargeEnough(drive, image)) {
const imageSize = _.get(image, [ 'size', 'final', 'estimation' ]) ? image.size.original : image.size.final.value
const relativeBytes = imageSize - drive.size
statusList.push({
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
message: exports.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL
message: exports.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL.replace('XX', prettyBytes(relativeBytes))
})
} else {
if (exports.isSystemDrive(drive)) {
Expand Down
18 changes: 14 additions & 4 deletions tests/shared/drive-constraints.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,14 @@ describe('Shared: DriveConstraints', function () {
this.image.size.final.value = this.drive.size + 1

const result = constraints.getDriveImageCompatibilityStatuses(this.drive, this.image)
const expectedTuples = [ [ 'ERROR', 'TOO_SMALL' ] ]
const expected = [
{
message: `${constraints.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL} 1 B`,
type: constraints.COMPATIBILITY_STATUS_TYPES.ERROR
}
]

expectStatusTypesAndMessagesToBe(result, expectedTuples)
m.chai.expect(result).to.deep.equal(expected)
})
})

Expand Down Expand Up @@ -1147,9 +1152,14 @@ describe('Shared: DriveConstraints', function () {
this.drive.isSystem = true

const result = constraints.getDriveImageCompatibilityStatuses(this.drive, this.image)
const expectedTuples = [ [ 'ERROR', 'TOO_SMALL' ] ]
const expected = [
{
message: `${constraints.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL} 1 B`,
type: constraints.COMPATIBILITY_STATUS_TYPES.ERROR
}
]

expectStatusTypesAndMessagesToBe(result, expectedTuples)
m.chai.expect(result).to.deep.equal(expected)
})
})

Expand Down

0 comments on commit d94039a

Please sign in to comment.