From ae8435c381a19df4ed1e2819655fe6c4b3ee591e Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 4 Aug 2021 09:11:57 +0200 Subject: [PATCH] Add headless test for components --- test/specs/grapesjs/headless.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/specs/grapesjs/headless.js b/test/specs/grapesjs/headless.js index 3d33a3896..462438ef5 100644 --- a/test/specs/grapesjs/headless.js +++ b/test/specs/grapesjs/headless.js @@ -1,11 +1,39 @@ /** * @jest-environment node */ +let editor; describe('GrapesJS Headless', () => { - test('Can init editor', () => { + test('Can init and destroy an editor', () => { const editor = grapesjs.init({ headless: true }); expect(editor).toBeTruthy(); editor.destroy(); }); + + describe('Headless operations', () => { + beforeEach(() => { + editor = grapesjs.init({ headless: true }); + }); + + afterEach(() => { + editor.destroy(); + }); + + test('Add components', () => { + const res = editor.addComponents({ + attributes: { class: 'cls', test: 'value' }, + components: { type: 'textnode', content: 'Test' } + }); + expect(res.length).toBe(1); + const comp = res[0]; + const resultHTML = '
Test
'; + expect(comp.toHTML()).toBe(resultHTML); + expect(editor.Selectors.getAll().length).toBe(1); // 1 selector is created + expect(editor.Css.getAll().length).toBe(0); // No CSS + expect(editor.getHtml()).toBe(resultHTML); + expect(editor.getCss()).toBe(editor.getConfig().protectedCss); // same as default + }); + + test('Add styles', () => {}); + }); });