From 3ab1a7d281a082322e864508cc1dc04a235d7c98 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Thu, 25 Jan 2024 16:50:46 +0100 Subject: [PATCH] chore: add html tests Related to #1004 --- .../components/form-fields/Html.spec.js | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 packages/form-js-viewer/test/spec/render/components/form-fields/Html.spec.js diff --git a/packages/form-js-viewer/test/spec/render/components/form-fields/Html.spec.js b/packages/form-js-viewer/test/spec/render/components/form-fields/Html.spec.js new file mode 100644 index 000000000..810980531 --- /dev/null +++ b/packages/form-js-viewer/test/spec/render/components/form-fields/Html.spec.js @@ -0,0 +1,152 @@ +import { render } from '@testing-library/preact/pure'; + +import { Html } from '../../../../../src/render/components/form-fields/Html'; + +import { + createFormContainer, +} from '../../../../TestHelper'; + +import { MockFormContext } from '../helper'; + +let container; + +describe.only('Html', function() { + + beforeEach(function() { + container = createFormContainer(); + }); + + afterEach(function() { + container.remove(); + }); + + + it('should render', function() { + + // when + const { container } = createHtmlComponent(); + + // then + const formField = container.querySelector('.fjs-form-field'); + expect(formField).to.exist; + expect(formField.innerHTML).to.eql(`
${defaultField.content}
`); + }); + + + it('should render HTML content with inline styles', function() { + + // given + const content = '

Some styled content

'; + + // when + const { container } = createHtmlComponent({ + field: { ...defaultField, content } + }); + + // then + const formField = container.querySelector('.fjs-form-field'); + expect(formField).to.exist; + expect(formField.innerHTML).to.eql(`
${content}
`); + }); + + + it('should ignore style tags', function() { + + // given + const content = ` + +
Content with class style
+ `; + + // when + const { container } = createHtmlComponent({ + field: { ...defaultField, content } + }); + + // then + const formField = container.querySelector('.fjs-form-field'); + expect(formField).to.exist; + expect(formField.innerHTML).to.include('Content with class style'); + + const styledDiv = formField.querySelector('.test-style'); + expect(styledDiv).to.exist; + + // Checking that the style defined in