Skip to content

Commit 19c73e6

Browse files
committed
Added tests for UFM parsing
1 parent a0243b1 commit 19c73e6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/packages/ufm/components/ufm-render/ufm-render.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ UmbDomPurify.addHook('afterSanitizeAttributes', function (node) {
2828
}
2929
});
3030

31-
const UmbMarked = new Marked({
31+
export const UmbMarked = new Marked({
3232
async: true,
3333
gfm: true,
3434
breaks: true,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect } from '@open-wc/testing';
2+
import { ufm } from './marked-ufm.plugin.js';
3+
import { UmbMarked } from '../index.js';
4+
import { UmbUfmLabelValueComponent } from '../ufm-components/label-value.component.js';
5+
import { UmbUfmLocalizeComponent } from '../ufm-components/localize.component.js';
6+
7+
describe('UmbMarkedUfm', () => {
8+
describe('UFM parsing', () => {
9+
const runs = [
10+
{ ufm: '{=prop1}', expected: '<ufm-label-value alias="prop1"></ufm-label-value>' },
11+
{ ufm: '{= prop1}', expected: '<ufm-label-value alias="prop1"></ufm-label-value>' },
12+
{ ufm: '{= prop1 }', expected: '<ufm-label-value alias="prop1"></ufm-label-value>' },
13+
{ ufm: '{{=prop1}}', expected: '{<ufm-label-value alias="prop1"></ufm-label-value>}' },
14+
{ ufm: '{#general_add}', expected: '<umb-localize key="general_add"></umb-localize>' },
15+
];
16+
17+
// Manually configuring the UFM components for testing.
18+
UmbMarked.use(
19+
ufm([
20+
{ alias: 'Umb.Markdown.LabelValue', marker: '=', render: new UmbUfmLabelValueComponent().render },
21+
{ alias: 'Umb.Markdown.Localize', marker: '#', render: new UmbUfmLocalizeComponent().render },
22+
]),
23+
);
24+
25+
runs.forEach((run) => {
26+
it(`Parsing "${run.ufm}"`, async () => {
27+
const markup = await UmbMarked.parseInline(run.ufm);
28+
expect(markup).to.equal(run.expected);
29+
});
30+
});
31+
});
32+
});

0 commit comments

Comments
 (0)