mirror of
https://github.com/gromlab-ru/svg-sprites.git
synced 2026-07-22 04:40:17 +03:00
feat: выпустить версию 1.0.0
- добавлены отдельные режимы генерации для React, Next.js и legacy - добавлены SpriteViewer, типизированные компоненты и безопасный codegen - перенесена сборка AI-скила и обновлена документация - добавлены migration guide, лицензии и проверки публикации
This commit is contained in:
71
test/react-viewer.test.mjs
Normal file
71
test/react-viewer.test.mjs
Normal file
@@ -0,0 +1,71 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import test from 'node:test'
|
||||
import { createElement } from 'react'
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
|
||||
import { SpriteViewer } from '../dist/react.js'
|
||||
|
||||
const manifest = {
|
||||
schemaVersion: 1,
|
||||
generator: '@gromlab/svg-sprites',
|
||||
name: 'controls',
|
||||
description: 'Control icons',
|
||||
componentName: 'ControlsIcon',
|
||||
target: 'vite',
|
||||
format: 'symbol',
|
||||
iconCount: 1,
|
||||
spriteUrl: '/assets/controls.svg',
|
||||
icons: [
|
||||
{
|
||||
name: 'check',
|
||||
id: 'check',
|
||||
viewBox: '0 0 16 16',
|
||||
colors: [{ variable: '--icon-color-1', fallback: 'currentColor' }],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
test('React entry is a Next.js client boundary', () => {
|
||||
const reactEntry = fs.readFileSync(path.resolve('dist/react.js'), 'utf-8')
|
||||
const coreEntry = fs.readFileSync(path.resolve('dist/index.js'), 'utf-8')
|
||||
assert.match(reactEntry, /^['"]use client['"];?/)
|
||||
assert.doesNotMatch(coreEntry, /from ["']react(?:\/jsx-runtime)?["']/)
|
||||
})
|
||||
|
||||
test('SpriteViewer renders direct sprite manifests', () => {
|
||||
const markup = renderToStaticMarkup(createElement(SpriteViewer, {
|
||||
sources: [manifest],
|
||||
title: 'Icon catalog',
|
||||
}))
|
||||
|
||||
assert.match(markup, /Icon catalog/)
|
||||
assert.match(markup, /controls/)
|
||||
assert.match(markup, /Control icons/)
|
||||
assert.match(markup, /check/)
|
||||
assert.match(markup, /\/assets\/controls\.svg#check/)
|
||||
assert.match(markup, /1 спрайт · 1 иконка/)
|
||||
assert.match(markup, /gromlab-sprite-viewer__icon-wrap/)
|
||||
assert.match(markup, /Открыть check/)
|
||||
})
|
||||
|
||||
test('SpriteViewer accepts a loader record from import.meta.glob', () => {
|
||||
const markup = renderToStaticMarkup(createElement(SpriteViewer, {
|
||||
sources: {
|
||||
'/src/controls/manifest.ts': async () => ({ default: manifest }),
|
||||
},
|
||||
}))
|
||||
|
||||
assert.match(markup, /Загрузка спрайтов/)
|
||||
})
|
||||
|
||||
test('SpriteViewer supports an externally controlled color theme', () => {
|
||||
const markup = renderToStaticMarkup(createElement(SpriteViewer, {
|
||||
sources: [manifest],
|
||||
colorTheme: 'dark',
|
||||
}))
|
||||
|
||||
assert.match(markup, /^<section[^>]*data-theme="dark"/)
|
||||
assert.doesNotMatch(markup, /<button[^>]*aria-label="Переключить тему"/)
|
||||
})
|
||||
Reference in New Issue
Block a user