2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-27 14:45:03 +03:00
Files
Nikolay Kost 40041a0680 fix(293): [color] tag doesn't work in React (#294)
* fix: react color preset

* chore: changeset great-beds-shop.md

* fix: tests

* chore: text fixes
2025-10-05 15:38:17 +02:00

52 lines
1.5 KiB
TypeScript

import bbob from '@bbob/core';
import preset from '../src'
const instance = bbob(preset())
const createTag = (content: string[], style: Record<string, string>) => {
return {
"attrs": { "style": style },
"content": content,
"tag": "span",
"end": undefined,
"start": undefined,
}
}
describe('@bbob/preset-react', () => {
test('is a function', () => {
expect(preset).toBeInstanceOf(Function)
})
test('is parses [b] tag correctly', () => {
const res = instance.process('[b]bold[/b]')
const tags = [...res.tree]
expect(tags).toEqual([createTag(["bold"], { fontWeight: 'bold' })]);
});
test('is parses [i] tag correctly', () => {
const res = instance.process('[i]italic[/i]')
const tags = [...res.tree]
expect(tags).toEqual([createTag(["italic"], { fontStyle: 'italic' })]);
});
test('is parses [u] tag correctly', () => {
const res = instance.process('[u]underline[/u]')
const tags = [...res.tree]
expect(tags).toEqual([createTag(["underline"], { textDecoration: 'underline' })]);
});
test('is parses [s] tag correctly', () => {
const res = instance.process('[s]strike[/s]')
const tags = [...res.tree]
expect(tags).toEqual([createTag(["strike"], { textDecoration: 'line-through' })]);
});
test('is parses [color] tag correctly', () => {
const res = instance.process('[color=#ff0000]This text should be red[/color]')
const tags = [...res.tree]
expect(tags).toEqual([createTag(["This", " ", "text", " ", "should", " ", "be", " ", "red"], { color: '#ff0000' })]);
});
});