|
| 1 | +import ChannelMap from "./channelMap"; |
| 2 | + |
| 3 | +describe("ChannelMap", () => { |
| 4 | + describe("formatSize", () => { |
| 5 | + let channelMap: ChannelMap; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + // Create a minimal DOM structure for ChannelMap initialization |
| 9 | + document.body.innerHTML = ` |
| 10 | + <div data-js="channel-map"></div> |
| 11 | + <div class="p-channel-map-overlay" data-js="close-channel-map"></div> |
| 12 | + <script type="text/template" id="channel-map-row-template"></script> |
| 13 | + <script type="text/template" id="channel-map-security-table-row-template"></script> |
| 14 | + `; |
| 15 | + channelMap = new ChannelMap( |
| 16 | + '[data-js="channel-map"]', |
| 17 | + "test-snap", |
| 18 | + "test-snap-id", |
| 19 | + {}, |
| 20 | + "latest", |
| 21 | + false, |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + document.body.innerHTML = ""; |
| 27 | + }); |
| 28 | + |
| 29 | + it("should format 0 bytes correctly", () => { |
| 30 | + expect(channelMap.formatSize(0)).toBe("0 B"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should format bytes correctly", () => { |
| 34 | + expect(channelMap.formatSize(500)).toBe("500 B"); |
| 35 | + expect(channelMap.formatSize(999)).toBe("999 B"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should format kilobytes correctly", () => { |
| 39 | + expect(channelMap.formatSize(1000)).toBe("1 kB"); |
| 40 | + expect(channelMap.formatSize(1500)).toBe("1.5 kB"); |
| 41 | + expect(channelMap.formatSize(50000)).toBe("50 kB"); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should format megabytes correctly", () => { |
| 45 | + expect(channelMap.formatSize(1000000)).toBe("1 MB"); |
| 46 | + expect(channelMap.formatSize(1500000)).toBe("1.5 MB"); |
| 47 | + expect(channelMap.formatSize(52428800)).toBe("52.4 MB"); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should format gigabytes correctly", () => { |
| 51 | + expect(channelMap.formatSize(1000000000)).toBe("1 GB"); |
| 52 | + expect(channelMap.formatSize(1500000000)).toBe("1.5 GB"); |
| 53 | + expect(channelMap.formatSize(5000000000)).toBe("5 GB"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should format terabytes correctly", () => { |
| 57 | + expect(channelMap.formatSize(1000000000000)).toBe("1 TB"); |
| 58 | + expect(channelMap.formatSize(1500000000000)).toBe("1.5 TB"); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should round to 1 decimal place", () => { |
| 62 | + expect(channelMap.formatSize(1234567)).toBe("1.2 MB"); |
| 63 | + expect(channelMap.formatSize(1567890)).toBe("1.6 MB"); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments