mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 12:06:47 +00:00
test: add unit test for parseHTML (#3870)
This commit is contained in:
parent
868a487b2d
commit
d0746b1155
@ -33,7 +33,7 @@ export const PoweredBy = () => {
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: parseHTML(
|
||||
customBrandPlugin?.options?.options?.brand ||
|
||||
`Powered by <a href="${urls[i18n.language] || urls['en-US']}">NocoBase</a>`,
|
||||
`Powered by <a href="${urls[i18n.language] || urls['en-US']}" target="__blank">NocoBase</a>`,
|
||||
{ appVersion },
|
||||
),
|
||||
}}
|
||||
|
41
packages/core/utils/src/__tests__/parseHTML.test.ts
Normal file
41
packages/core/utils/src/__tests__/parseHTML.test.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { parseHTML } from '../parseHTML';
|
||||
|
||||
describe('parseHTML', () => {
|
||||
it('should replace variables in HTML with their corresponding values', () => {
|
||||
const html = '<h1>{{title}}</h1><p>{{content}}</p>';
|
||||
const variables = {
|
||||
title: 'Hello',
|
||||
content: 'World',
|
||||
};
|
||||
const expected = '<h1>Hello</h1><p>World</p>';
|
||||
|
||||
const result = parseHTML(html, variables);
|
||||
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not replace variables that are not present in the variables object', () => {
|
||||
const html = '<h1>{{title}}</h1><p>{{content}}</p>';
|
||||
const variables = {
|
||||
title: 'Hello',
|
||||
};
|
||||
const expected = '<h1>Hello</h1><p>{{content}}</p>';
|
||||
|
||||
const result = parseHTML(html, variables);
|
||||
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not replace variables that have undefined values', () => {
|
||||
const html = '<h1>{{title}}</h1><p>{{content}}</p>';
|
||||
const variables = {
|
||||
title: 'Hello',
|
||||
content: undefined,
|
||||
};
|
||||
const expected = '<h1>Hello</h1><p>{{content}}</p>';
|
||||
|
||||
const result = parseHTML(html, variables);
|
||||
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user