test: add unit test for parseHTML (#3870)

This commit is contained in:
Zeke Zhang 2024-03-29 14:52:20 +08:00 committed by GitHub
parent 868a487b2d
commit d0746b1155
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 1 deletions

View File

@ -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 },
),
}}

View 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);
});
});