| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | const { formatSize } = require("../lib/SizeFormatHelpers"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe("SizeFormatHelpers", () => { | 
					
						
							|  |  |  | 	describe("formatSize", () => { | 
					
						
							|  |  |  | 		it("should handle zero size", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(0)).toBe("0 bytes"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle bytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(1000)).toBe("1000 bytes"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle integer kibibytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(2048)).toBe("2 KiB"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle float kibibytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(2560)).toBe("2.5 KiB"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle integer mebibytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(10 * 1024 * 1024)).toBe("10 MiB"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle float mebibytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(12.5 * 1024 * 1024)).toBe("12.5 MiB"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle integer gibibytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(3 * 1024 * 1024 * 1024)).toBe("3 GiB"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle float gibibytes", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(1.2 * 1024 * 1024 * 1024)).toBe("1.2 GiB"); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-03-29 21:28:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it("should handle undefined/NaN", () => { | 
					
						
							| 
									
										
										
										
											2018-07-27 04:37:21 +08:00
										 |  |  | 			expect(formatSize(undefined)).toBe("unknown size"); | 
					
						
							|  |  |  | 			expect(formatSize(NaN)).toBe("unknown size"); | 
					
						
							| 
									
										
										
										
											2018-03-29 21:28:03 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-10-09 18:20:20 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }); |