Add html test coverage
This commit is contained in:
parent
b48697288e
commit
bd187da8a5
17
__tests__/html.test.ts
Normal file
17
__tests__/html.test.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { htmlHasBrParagraphBreaks, safelyParseFormattedHtml } from '@/utility/html';
|
||||||
|
import { parameterize } from '@/utility/string';
|
||||||
|
|
||||||
|
describe('HTML', () => {
|
||||||
|
it('safely parses', () => {
|
||||||
|
expect(safelyParseFormattedHtml('<p>TEXT</p>')).toBe('TEXT');
|
||||||
|
expect(safelyParseFormattedHtml('<b>TEXT</b>')).toBe('<b>TEXT</b>');
|
||||||
|
});
|
||||||
|
it('detects br-style paragraph breaks', () => {
|
||||||
|
expect(htmlHasBrParagraphBreaks('TEXT<br><br>')).toBeTruthy();
|
||||||
|
expect(htmlHasBrParagraphBreaks('TEXT<br /><br />')).toBeTruthy();
|
||||||
|
expect(htmlHasBrParagraphBreaks('TEXT<br><br />')).toBeTruthy();
|
||||||
|
expect(htmlHasBrParagraphBreaks('TEXT')).toBeFalsy();
|
||||||
|
expect(htmlHasBrParagraphBreaks('TEXT<br/>')).toBeFalsy();
|
||||||
|
expect(htmlHasBrParagraphBreaks('TEXT<br />')).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -16,7 +16,7 @@ import { useAppState } from '@/state/AppState';
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import HiddenTag from '@/tag/HiddenTag';
|
import HiddenTag from '@/tag/HiddenTag';
|
||||||
import { SITE_ABOUT } from '@/site/config';
|
import { SITE_ABOUT } from '@/site/config';
|
||||||
import { htmlHasBrParagraphBreaks, safelyParseFormattedHTML } from '@/utility/html';
|
import { htmlHasBrParagraphBreaks, safelyParseFormattedHtml } from '@/utility/html';
|
||||||
import { clsx } from 'clsx/lite';
|
import { clsx } from 'clsx/lite';
|
||||||
|
|
||||||
export default function PhotoGridSidebar({
|
export default function PhotoGridSidebar({
|
||||||
@ -50,7 +50,7 @@ export default function PhotoGridSidebar({
|
|||||||
htmlHasBrParagraphBreaks(SITE_ABOUT) && 'pb-2',
|
htmlHasBrParagraphBreaks(SITE_ABOUT) && 'pb-2',
|
||||||
)}
|
)}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: safelyParseFormattedHTML(SITE_ABOUT),
|
__html: safelyParseFormattedHtml(SITE_ABOUT),
|
||||||
}}
|
}}
|
||||||
/>]}
|
/>]}
|
||||||
/>}
|
/>}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import sanitizeHtml from 'sanitize-html';
|
|||||||
|
|
||||||
const ALLOWED_FORMATTING_TAGS = ['b', 'strong', 'i', 'em', 'u', 'br'];
|
const ALLOWED_FORMATTING_TAGS = ['b', 'strong', 'i', 'em', 'u', 'br'];
|
||||||
|
|
||||||
export const safelyParseFormattedHTML = (text: string) =>
|
export const safelyParseFormattedHtml = (text: string) =>
|
||||||
sanitizeHtml(text, {
|
sanitizeHtml(text, {
|
||||||
allowedTags: ALLOWED_FORMATTING_TAGS,
|
allowedTags: ALLOWED_FORMATTING_TAGS,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user