Skip to content

Commit

Permalink
CHE-5601: fix bug in change-memory-unit filter (#5732)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
  • Loading branch information
akurinnoy committed Jul 26, 2017
1 parent 8259f3e commit c4ce422
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {CheHttpBackend} from '../../api/test/che-http-backend';
* @author Oleksii Kurinnyi
*/
describe('ChangeMemoryUnitFilter', () => {
let $filter, unitFrom: string, unitTo: string;
let $filter, unitFrom: string;

/**
* Backend for handling http operations
Expand Down Expand Up @@ -110,4 +110,21 @@ describe('ChangeMemoryUnitFilter', () => {

});

describe(`bugfix https://github.com/eclipse/che/issues/5601 >`, () => {

it(`should round value in bytes >`, () => {
const number = 2.3,
unitFrom = 'GB',
unitTo = 'B',
notExpectedResult = 2469606195.2 + ' ' + unitTo,
expectedResult = 2469606195 + ' ' + unitTo;

const result = $filter('changeMemoryUnit')(number, [unitFrom, unitTo]);

expect(result).not.toEqual(notExpectedResult);
expect(result).toEqual(expectedResult);
});

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ChangeMemoryUnitFilter {

castToBytes(number: number, unitFrom: string): number {
const power = this.getPower(unitFrom);
number = this.castDown(number, power);
number = Math.round(this.castDown(number, power));
return number;
}

Expand Down

0 comments on commit c4ce422

Please sign in to comment.