import { describe, expect, it, vi } from 'vitest' import type { TIconsStorageKeys } from '../components/icon/iconsStorage' import { IconsStorage } from './../components/icon/iconsStorage' import { parseContent, parseSvg, parseViewBox } from './svgUtils' describe('parseSvg()', () => { vi.mock('/icons/smile.svg?raw', () => ({ default: '...' })) it('should return correct svg when provided with a valid icon', async () => { const iconName = 'smile' const viewBox = [0, 0, 24, 24] const result = await parseSvg(iconName) expect(result).toEqual({ content: '...', viewBox }) expect(IconsStorage.has(iconName)).toBeTruthy() }) it('should throw an error when provided with an invalid icon', () => { const iconName = 'invalid' as TIconsStorageKeys const resultFn = () => parseSvg(iconName) expect(resultFn).rejects.toThrow('Invalid icon name!') }) }) describe('parseContent()', () => { it('should return correct content when provided with valid svg', () => { const validSvg = '...' const result = parseContent(validSvg) expect(result).toEqual('...') }) it('should return an empty string when provided with invalid svg', () => { const invalidSvg = 'invalid svg' const result = parseContent(invalidSvg) expect(result).toEqual('') }) }) describe('parseViewBox()', () => { it('should return correct viewBox when provided with valid svg', () => { const viewbox = '0 0 24 24' const result = parseViewBox(`...`) const expectedResult = viewbox.split(' ').map(viewbox => Number(viewbox)) expect(result).toEqual(expectedResult) }) it('should return an empty array when provided with invalid svg', () => { const result = parseViewBox('...') expect(result).toEqual([]) }) })