|
|
@ -4,6 +4,8 @@ import Editor from '../../../src/editor'; |
|
|
import utils from '../../test_utils.js'; |
|
|
import utils from '../../test_utils.js'; |
|
|
import { Component } from '../../../src'; |
|
|
import { Component } from '../../../src'; |
|
|
import ComponentWrapper from '../../../src/dom_components/model/ComponentWrapper'; |
|
|
import ComponentWrapper from '../../../src/dom_components/model/ComponentWrapper'; |
|
|
|
|
|
import { flattenHTML, setupTestEditor } from '../../common'; |
|
|
|
|
|
import { ProjectData } from '../../../src/storage_manager'; |
|
|
|
|
|
|
|
|
describe('DOM Components', () => { |
|
|
describe('DOM Components', () => { |
|
|
describe('Main', () => { |
|
|
describe('Main', () => { |
|
|
@ -320,21 +322,12 @@ describe('DOM Components', () => { |
|
|
let fxt: HTMLElement; |
|
|
let fxt: HTMLElement; |
|
|
let root: ComponentWrapper; |
|
|
let root: ComponentWrapper; |
|
|
|
|
|
|
|
|
beforeEach((done) => { |
|
|
beforeEach(() => { |
|
|
fxt = document.createElement('div'); |
|
|
const testEditor = setupTestEditor(); |
|
|
document.body.appendChild(fxt); |
|
|
editor = testEditor.editor; |
|
|
editor = new Editor({ |
|
|
em = testEditor.em; |
|
|
el: fxt, |
|
|
fxt = testEditor.fixtures; |
|
|
avoidInlineStyle: true, |
|
|
root = testEditor.cmpRoot; |
|
|
storageManager: false, |
|
|
|
|
|
}); |
|
|
|
|
|
em = editor.getModel(); |
|
|
|
|
|
fxt.appendChild(em.Canvas.render()); |
|
|
|
|
|
em.loadOnStart(); |
|
|
|
|
|
editor.on('change:ready', () => { |
|
|
|
|
|
root = editor.Components.getWrapper()!; |
|
|
|
|
|
done(); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
afterEach(() => { |
|
|
afterEach(() => { |
|
|
@ -376,8 +369,8 @@ describe('DOM Components', () => { |
|
|
expect(docEl.get('htmlp')).toBe(true); |
|
|
expect(docEl.get('htmlp')).toBe(true); |
|
|
expect(root.get('bodyp')).toBe(true); |
|
|
expect(root.get('bodyp')).toBe(true); |
|
|
expect(root.doctype).toBe('<!DOCTYPE html>'); |
|
|
expect(root.doctype).toBe('<!DOCTYPE html>'); |
|
|
|
|
|
expect(root.toHTML()).toBe( |
|
|
const outputHtml = ` |
|
|
flattenHTML(` |
|
|
<!DOCTYPE html> |
|
|
<!DOCTYPE html> |
|
|
<html lang="en" class="cls-html"> |
|
|
<html lang="en" class="cls-html"> |
|
|
<head class="cls-head"> |
|
|
<head class="cls-head"> |
|
|
@ -390,8 +383,41 @@ describe('DOM Components', () => { |
|
|
<h1>H1</h1> |
|
|
<h1>H1</h1> |
|
|
</body> |
|
|
</body> |
|
|
</html> |
|
|
</html> |
|
|
`.replace(/>\s+|\s+</g, (m) => m.trim());
|
|
|
`),
|
|
|
expect(root.toHTML()).toBe(outputHtml); |
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('load with document components', () => { |
|
|
|
|
|
let projectData: ProjectData; |
|
|
|
|
|
const docHtml = ` |
|
|
|
|
|
<!DOCTYPE html> |
|
|
|
|
|
<html lang="en"> |
|
|
|
|
|
<head class="cls-head"> |
|
|
|
|
|
<title>ABC</title> |
|
|
|
|
|
</head> |
|
|
|
|
|
<body> |
|
|
|
|
|
<span>Test</span> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html> |
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
test('imports properly HTML with document data', () => { |
|
|
|
|
|
editor.setComponents(docHtml, { asDocument: true }); |
|
|
|
|
|
projectData = editor.getProjectData(); |
|
|
|
|
|
expect(root.toHTML()).toBe(flattenHTML(docHtml)); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/GrapesJS/grapesjs/issues/6116
|
|
|
|
|
|
test('editor loads properly document data from projectData', () => { |
|
|
|
|
|
editor.loadProjectData(projectData); |
|
|
|
|
|
const newRoot = editor.getWrapper()!; |
|
|
|
|
|
|
|
|
|
|
|
const { head, doctype } = newRoot; |
|
|
|
|
|
expect(head.components().length).toBe(1); |
|
|
|
|
|
expect(doctype).toBe('<!DOCTYPE html>'); |
|
|
|
|
|
|
|
|
|
|
|
expect(newRoot.toHTML()).toBe(flattenHTML(docHtml)); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|