|
| 1 | +import { describe, expect, it } from 'bun:test'; |
| 2 | +import { SizableImageAction, checkIsSizableImageURL } from './checkIsSizableImageURL'; |
| 3 | + |
| 4 | +describe('checkIsSizableImageURL', () => { |
| 5 | + it('should return Skip for non-parsable URLs', () => { |
| 6 | + expect(checkIsSizableImageURL('not a url')).toBe(SizableImageAction.Skip); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should return Skip for non-http(s) URLs', () => { |
| 10 | + expect(checkIsSizableImageURL('data:image/png;base64,abc')).toBe(SizableImageAction.Skip); |
| 11 | + expect(checkIsSizableImageURL('file:///path/to/image.jpg')).toBe(SizableImageAction.Skip); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should return Skip for localhost URLs', () => { |
| 15 | + expect(checkIsSizableImageURL('http://localhost:3000/image.jpg')).toBe( |
| 16 | + SizableImageAction.Skip |
| 17 | + ); |
| 18 | + expect(checkIsSizableImageURL('https://localhost/image.png')).toBe(SizableImageAction.Skip); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should return Skip for GitBook image URLs', () => { |
| 22 | + expect(checkIsSizableImageURL('https://example.com/~gitbook/image/test.jpg')).toBe( |
| 23 | + SizableImageAction.Skip |
| 24 | + ); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return Resize for supported image extensions', () => { |
| 28 | + expect(checkIsSizableImageURL('https://example.com/image.jpg')).toBe( |
| 29 | + SizableImageAction.Resize |
| 30 | + ); |
| 31 | + expect(checkIsSizableImageURL('https://example.com/image.jpeg')).toBe( |
| 32 | + SizableImageAction.Resize |
| 33 | + ); |
| 34 | + expect(checkIsSizableImageURL('https://example.com/image.png')).toBe( |
| 35 | + SizableImageAction.Resize |
| 36 | + ); |
| 37 | + expect(checkIsSizableImageURL('https://example.com/image.gif')).toBe( |
| 38 | + SizableImageAction.Resize |
| 39 | + ); |
| 40 | + expect(checkIsSizableImageURL('https://example.com/image.webp')).toBe( |
| 41 | + SizableImageAction.Resize |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should return Resize for URLs without extensions', () => { |
| 46 | + expect(checkIsSizableImageURL('https://example.com/image')).toBe(SizableImageAction.Resize); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return Passthrough for unsupported image extensions', () => { |
| 50 | + expect(checkIsSizableImageURL('https://example.com/image.svg')).toBe( |
| 51 | + SizableImageAction.Passthrough |
| 52 | + ); |
| 53 | + expect(checkIsSizableImageURL('https://example.com/image.bmp')).toBe( |
| 54 | + SizableImageAction.Passthrough |
| 55 | + ); |
| 56 | + expect(checkIsSizableImageURL('https://example.com/image.tiff')).toBe( |
| 57 | + SizableImageAction.Passthrough |
| 58 | + ); |
| 59 | + expect(checkIsSizableImageURL('https://example.com/image.ico')).toBe( |
| 60 | + SizableImageAction.Passthrough |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should handle URLs with query parameters correctly', () => { |
| 65 | + expect(checkIsSizableImageURL('https://example.com/image.jpg?width=100')).toBe( |
| 66 | + SizableImageAction.Resize |
| 67 | + ); |
| 68 | + expect(checkIsSizableImageURL('https://example.com/image.svg?height=200')).toBe( |
| 69 | + SizableImageAction.Passthrough |
| 70 | + ); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should be case-insensitive for extensions', () => { |
| 74 | + expect(checkIsSizableImageURL('https://example.com/image.JPG')).toBe( |
| 75 | + SizableImageAction.Resize |
| 76 | + ); |
| 77 | + expect(checkIsSizableImageURL('https://example.com/image.PNG')).toBe( |
| 78 | + SizableImageAction.Resize |
| 79 | + ); |
| 80 | + }); |
| 81 | +}); |
0 commit comments