Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / common / formatters.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { formatUploadSpeed, formatContainerCost } from "./formatters";
6
7 describe('formatUploadSpeed', () => {
8     it('should show speed less than 1MB/s', () => {
9         // given
10         const speed = 900;
11
12         // when
13         const result = formatUploadSpeed(0, speed, 0, 1);
14
15         // then
16         expect(result).toBe('0.90 MB/s');
17     });
18
19     it('should show 5MB/s', () => {
20         // given
21         const speed = 5230;
22
23         // when
24         const result = formatUploadSpeed(0, speed, 0, 1);
25
26         // then
27         expect(result).toBe('5.23 MB/s');
28     });
29 });
30
31 describe('formatContainerCost', () => {
32     it('should correctly round to tenth of a cent', () => {
33         expect(formatContainerCost(0.0)).toBe('$0');
34         expect(formatContainerCost(0.125)).toBe('$0.125');
35         expect(formatContainerCost(0.1254)).toBe('$0.125');
36         expect(formatContainerCost(0.1255)).toBe('$0.126');
37     });
38
39     it('should round up any smaller value to 0.001', () => {
40         expect(formatContainerCost(0.0)).toBe('$0');
41         expect(formatContainerCost(0.001)).toBe('$0.001');
42         expect(formatContainerCost(0.0001)).toBe('$0.001');
43         expect(formatContainerCost(0.00001)).toBe('$0.001');
44     });
45 });