16655: Fixed wrong speed indicator, added test 16655-Upload-speed-indicator-shows-wrong-information
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 14 Sep 2021 19:25:35 +0000 (21:25 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 14 Sep 2021 19:25:35 +0000 (21:25 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/common/formatters.test.ts [new file with mode: 0644]
src/common/formatters.ts

diff --git a/src/common/formatters.test.ts b/src/common/formatters.test.ts
new file mode 100644 (file)
index 0000000..83177e2
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { formatUploadSpeed } from "./formatters";
+
+describe('formatUploadSpeed', () => {
+    it('should show speed less than 1MB/s', () => {
+        // given
+        const speed = 900;
+
+        // when
+        const result = formatUploadSpeed(0, speed, 0, 1);
+
+        // then
+        expect(result).toBe('0.90 MB/s');
+    });
+
+    it('should show 5MB/s', () => {
+        // given
+        const speed = 5230;
+
+        // when
+        const result = formatUploadSpeed(0, speed, 0, 1);
+
+        // then
+        expect(result).toBe('5.23 MB/s');
+    }); 
+});
\ No newline at end of file
index 779809f1569494da93c599706fd1d977201df46a..6d0a7e491e4e508384ccbad42f66cc2eb3f8c195 100644 (file)
@@ -61,7 +61,8 @@ export function formatUploadSpeed(prevLoaded: number, loaded: number, prevTime:
     const speed = loaded > prevLoaded && currentTime > prevTime
         ? (loaded - prevLoaded) / (currentTime - prevTime)
         : 0;
-    return `${(speed / 1000).toFixed(2)} KB/s`;
+
+    return `${(speed / 1000).toFixed(2)} MB/s`;
 }
 
 const FILE_SIZES = [