uikit/tests/bi-image.chakra-style.test.mjs
Mohamadzadeh 78e073bffb
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 1m2s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 12s
uikit-v1.8.3-biimage-transparent-background-complete
2026-11-18 15:49:58 +03:30

47 lines
2.6 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { createImagePresentation, imagePresentationCSS } from '../src/remote/ui/BiImage/style-props.js';
const sample = {
w: { base: '60px', sm: '70px' },
h: { base: '60px', sm: '70px' },
objectFit: 'contain',
transition: 'transform 0.3s ease-in-out',
_hover: { transform: 'scale(1.3)' },
fallbackSrc: 'https://example.org/no-link.png',
};
const presentation = createImagePresentation(sample);
assert.equal(presentation.styles.base.width, '60px');
assert.equal(presentation.styles.base.height, '60px');
assert.equal(presentation.styles.sm.width, '70px');
assert.equal(presentation.styles.sm.height, '70px');
assert.equal(presentation.styles.base.objectFit, 'contain');
assert.equal(presentation.styles.base.transition, 'transform 0.3s ease-in-out');
assert.equal(presentation.styles.base.backgroundColor, undefined, 'a transparent logo must not get a gray backdrop');
assert.equal(createImagePresentation({ bg: '#123456' }).styles.base.background, '#123456');
assert.equal(createImagePresentation({ backgroundColor: 'transparent' }).styles.base.backgroundColor, 'transparent');
assert.equal(createImagePresentation({ style: { backgroundColor: '#abcdef' } }).styles.base.backgroundColor, '#abcdef');
assert.equal(presentation.pseudos._hover.base.transform, 'scale(1.3)');
const css = imagePresentationCSS(presentation, 'uikit-bi-image > img[data-bi-image="test"]');
assert.match(css, /@media \(min-width:30em\)/);
assert.match(css, /width:70px !important;/);
assert.match(css, /:hover\{transform:scale\(1\.3\) !important;/);
assert.doesNotMatch(css, /\[object Object\]/);
const array = createImagePresentation({ w: ['50px', null, '80px'], h: 'auto' });
assert.equal(array.styles.base.width, '50px');
assert.equal(array.styles.md.width, '80px');
assert.equal(array.styles.base.height, 'auto');
const box = createImagePresentation({ boxSize: '80px', w: '90px', rounded: 'full', p: 3, _focus: { opacity: 0.5 } });
assert.equal(box.styles.base.width, '90px');
assert.equal(box.styles.base.height, '80px');
assert.equal(box.styles.base.borderRadius, '9999px');
assert.equal(box.styles.base.padding, '0.75rem');
assert.equal(box.pseudos._focus.base.opacity, '0.5');
const source = readFileSync('src/remote/ui/BiImage/BiImage.remote.js', 'utf8');
const built = readFileSync('dist/remote/BiImage.js', 'utf8');
assert.ok(source.includes('createImagePresentation'));
assert.ok(built.includes('imagePresentationCSS'));
assert.doesNotMatch(built, /^import\s/m);
console.log('PASS: Chakra-like responsive props and pseudo styles, aliases, standalone remote build');