| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { formatByteSize, parseByteSize |
| 4 | |
| 5 | describe('parseByteSize', () |
| 6 | it('reads blank as no limit', |
| 7 | expect(parseByteSize(undefined, |
| 8 | expect(parseByteSize(' |
| 9 | }); |
| 10 | |
| 11 | it('reads plain bytes and binary units, ignoring case and spaces', |
| 12 | expect(parseByteSize('1073741824 |
| 13 | expect(parseByteSize('1gb |
| 14 | expect(parseByteSize('500 MB |
| 15 | expect(parseByteSize('1.5kb |
| 16 | expect(parseByteSize('0 |
| 17 | }); |
| 18 | |
| 19 | it('throws on anything else, naming the setting', |
| 20 | for (const value |
| 21 | '-1', |
| 22 | '1 gigabyte', |
| 23 | 'lots', |
| 24 | '1e9', |
| 25 | `${'9'.repeat |
| 26 | '9007199254740993', |
| 27 | ]) { |
| 28 | expect(() => |
| 29 | /STORAGE_QUOTA_BYTES/, |
| 30 | ); |
| 31 | } |
| 32 | }); |
| 33 | }); |
| 34 | |
| 35 | describe('formatByteSize', () |
| 36 | it('picks the largest whole unit', |
| 37 | expect(formatByteSize(0)) |
| 38 | expect(formatByteSize(512)) |
| 39 | expect(formatByteSize(1536)) |
| 40 | expect(formatByteSize(1024 |
| 41 | }); |
| 42 | }); |