mirror of
https://github.com/gavvvr/obsidian-imgur-plugin.git
synced 2026-07-22 05:10:27 +00:00
81 lines
3 KiB
TypeScript
81 lines
3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import ImgurSize from '../src/imgur/resizing/ImgurSize'
|
|
import imgurMarkdownImageRegexMatch from '../src/imgur/resizing/md-image-parsing'
|
|
import resizeTo from '../src/imgur/resizing/resizing'
|
|
|
|
describe('resizeTo', () => {
|
|
it.each([
|
|
{
|
|
input: '',
|
|
size: ImgurSize.SMALL_SQUARE,
|
|
output: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
},
|
|
{
|
|
input: '',
|
|
size: ImgurSize.BIG_SQUARE,
|
|
output: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
},
|
|
{
|
|
input: '',
|
|
size: ImgurSize.SMALL_THUMBNAIL,
|
|
output: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
},
|
|
{
|
|
input: '',
|
|
size: ImgurSize.MEDIUM_THUMBNAIL,
|
|
output: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
},
|
|
{
|
|
input: '',
|
|
size: ImgurSize.LARGE_THUMBNAIL,
|
|
output: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
},
|
|
{
|
|
input: '',
|
|
size: ImgurSize.HUGE_THUMBNAIL,
|
|
output: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
},
|
|
])("resizes an image to '$size' as expected", ({ input, size, output }) => {
|
|
const match = imgurMarkdownImageRegexMatch(input, 0)
|
|
const replacement = resizeTo(size)(match.mdImagePieces).content
|
|
|
|
expect(replacement).toBe(output)
|
|
})
|
|
|
|
it('can resize already resized image', () => {
|
|
const smallThumbnail =
|
|
'[](https://i.imgur.com/m3RpPCV.png)'
|
|
const match = imgurMarkdownImageRegexMatch(smallThumbnail, 0)
|
|
const replacement = resizeTo(ImgurSize.LARGE_THUMBNAIL)(match.mdImagePieces).content
|
|
|
|
expect(replacement).toBe(
|
|
'[](https://i.imgur.com/m3RpPCV.png)',
|
|
)
|
|
})
|
|
|
|
it('provides correct range to be replaced', () => {
|
|
const originalImage = ' '
|
|
const match = imgurMarkdownImageRegexMatch(originalImage, 3)
|
|
const replacement = resizeTo(ImgurSize.LARGE_THUMBNAIL)(match.mdImagePieces)
|
|
|
|
expect(replacement.from).toBe(3)
|
|
expect(replacement.to).toBe(39)
|
|
})
|
|
|
|
it.each([
|
|
{
|
|
input: '[](https://i.imgur.com/m3RpPCV.png)',
|
|
inputDescription: 'wrapped resized image',
|
|
},
|
|
{
|
|
input: '',
|
|
inputDescription: 'resized image',
|
|
},
|
|
])("resizes '$inputDescription' to original size", ({ input }) => {
|
|
const match = imgurMarkdownImageRegexMatch(input, 0)
|
|
const replacement = resizeTo(ImgurSize.ORIGINAL)(match.mdImagePieces).content
|
|
|
|
expect(replacement).toBe('')
|
|
})
|
|
})
|