diff --git a/test/specs/grapesjs/headless.js b/test/specs/grapesjs/headless.js
index 95f32fd12..ef053f81a 100644
--- a/test/specs/grapesjs/headless.js
+++ b/test/specs/grapesjs/headless.js
@@ -11,8 +11,19 @@ describe('GrapesJS Headless', () => {
});
describe('Headless operations', () => {
+ const cmpObj = {
+ attributes: { class: 'cls', test: 'value' },
+ components: { type: 'textnode', content: 'Test' }
+ };
+ const cmpStr = '
Test
';
+ const styleObj = {
+ selectors: [{ name: 'cls' }],
+ style: { color: 'red' }
+ };
+ const styleStr = '.cls{color:red;}';
+
beforeEach(() => {
- editor = grapesjs.init({ headless: true });
+ editor = grapesjs.init({ headless: true, protectedCss: '' });
});
afterEach(() => {
@@ -20,30 +31,32 @@ describe('GrapesJS Headless', () => {
});
test('Add components', () => {
- const res = editor.addComponents({
- attributes: { class: 'cls', test: 'value' },
- components: { type: 'textnode', content: 'Test' }
- });
+ const res = editor.addComponents(cmpObj);
expect(res.length).toBe(1);
const comp = res[0];
- const resultHTML = 'Test
';
- expect(comp.toHTML()).toBe(resultHTML);
+ expect(comp.toHTML()).toBe(cmpStr);
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
+ expect(editor.getHtml()).toBe(cmpStr);
+ expect(editor.getCss()).toBe(''); // same as default
});
test('Add styles', () => {
- const res = editor.addStyle({
- selectors: [{ name: 'gjs-row' }],
- style: { color: 'red' }
- });
+ const res = editor.addStyle(styleObj);
expect(res.length).toBe(1);
const rule = res[0];
- const result = '.gjs-row{color:red;}';
- expect(rule.toCSS()).toBe(result);
+ expect(rule.toCSS()).toBe(styleStr);
expect(editor.Selectors.getAll().length).toBe(1); // 1 selector is created
});
+
+ test('Load data', () => {
+ editor.loadData({
+ components: [cmpObj],
+ styles: [styleObj]
+ });
+ expect(editor.Selectors.getAll().length).toBe(1);
+ expect(editor.getHtml()).toBe(cmpStr);
+ expect(editor.getCss()).toBe(styleStr);
+ });
});
});