X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d906ace112bcacfaa91cdcf49815a70bd572ac2e..5bfb2e1cb9f87c2e62aaae870a8789ed132eba50:/src/common/formatters.test.ts diff --git a/src/common/formatters.test.ts b/src/common/formatters.test.ts index 83177e2207..048779727e 100644 --- a/src/common/formatters.test.ts +++ b/src/common/formatters.test.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { formatUploadSpeed } from "./formatters"; +import { formatUploadSpeed, formatContainerCost } from "./formatters"; describe('formatUploadSpeed', () => { it('should show speed less than 1MB/s', () => { @@ -25,5 +25,21 @@ describe('formatUploadSpeed', () => { // then expect(result).toBe('5.23 MB/s'); - }); -}); \ No newline at end of file + }); +}); + +describe('formatContainerCost', () => { + it('should correctly round to tenth of a cent', () => { + expect(formatContainerCost(0.0)).toBe('$0'); + expect(formatContainerCost(0.125)).toBe('$0.125'); + expect(formatContainerCost(0.1254)).toBe('$0.125'); + expect(formatContainerCost(0.1255)).toBe('$0.126'); + }); + + it('should round up any smaller value to 0.001', () => { + expect(formatContainerCost(0.0)).toBe('$0'); + expect(formatContainerCost(0.001)).toBe('$0.001'); + expect(formatContainerCost(0.0001)).toBe('$0.001'); + expect(formatContainerCost(0.00001)).toBe('$0.001'); + }); +});