From ebfdbb90071457e09cae76253da26a3d94dcc0da Mon Sep 17 00:00:00 2001 From: asimonok Date: Wed, 15 Nov 2023 17:27:40 +0300 Subject: [PATCH] Add wrap/no wrap tests --- src/helpers/{html.test.ts => html.test.tsx} | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) rename src/helpers/{html.test.ts => html.test.tsx} (65%) diff --git a/src/helpers/html.test.ts b/src/helpers/html.test.tsx similarity index 65% rename from src/helpers/html.test.ts rename to src/helpers/html.test.tsx index 11a1423..0b07023 100644 --- a/src/helpers/html.test.ts +++ b/src/helpers/html.test.tsx @@ -1,6 +1,8 @@ import Handlebars from 'handlebars'; +import React from 'react'; import { textUtil } from '@grafana/data'; import { config } from '@grafana/runtime'; +import { render, screen } from '@testing-library/react'; import { generateHtml } from './html'; /** @@ -32,6 +34,13 @@ jest.mock('@grafana/data', () => ({ })); describe('HTML helpers', () => { + /** + * Options + */ + const options = { + wrap: true, + }; + describe('Generate HTML', () => { beforeEach(() => { jest.mocked(textUtil.sanitize).mockClear(); @@ -42,10 +51,49 @@ describe('HTML helpers', () => { generateHtml({ content, + options, } as any); expect(textUtil.sanitize).toHaveBeenCalledWith(content); }); + + it('Should wrap lines', () => { + const content = ` + line 1 + + line 2 + `; + + const { html } = generateHtml({ + content, + options, + } as any); + + render(
); + + expect(screen.getByTestId('root').querySelector('pre')).toBeInTheDocument(); + }); + + it('Should wrap lines', () => { + const content = ` + line 1 + + line 2 + `; + + const { html } = generateHtml({ + content, + options: { + ...options, + wrap: false, + }, + } as any); + + render(
); + + expect(screen.getByTestId('root').querySelector('pre')).not.toBeInTheDocument(); + }); + it('Should not sanitize html if disabled', () => { const content = `
`; @@ -56,6 +104,7 @@ describe('HTML helpers', () => { generateHtml({ content, + options, } as any); expect(textUtil.sanitize).not.toHaveBeenCalled(); @@ -76,6 +125,7 @@ describe('HTML helpers', () => { generateHtml({ content: '
', replaceVariables: (str: string) => str, + options, } as any); expect(Handlebars.registerHelper).toHaveBeenCalledWith('variable', expect.any(Function));