|
|
|
@ -3,6 +3,7 @@ import EditorModel from '../../../src/editor/model/Editor'; |
|
|
|
import Editor from '../../../src/editor'; |
|
|
|
import utils from './../../test_utils.js'; |
|
|
|
import { Component } from '../../../src'; |
|
|
|
import ComponentWrapper from '../../../src/dom_components/model/ComponentWrapper'; |
|
|
|
|
|
|
|
describe('DOM Components', () => { |
|
|
|
describe('Main', () => { |
|
|
|
@ -312,4 +313,86 @@ describe('DOM Components', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Rendered components', () => { |
|
|
|
let editor: Editor; |
|
|
|
let em: EditorModel; |
|
|
|
let fxt: HTMLElement; |
|
|
|
let root: ComponentWrapper; |
|
|
|
|
|
|
|
beforeEach(done => { |
|
|
|
fxt = document.createElement('div'); |
|
|
|
document.body.appendChild(fxt); |
|
|
|
editor = new Editor({ |
|
|
|
el: fxt, |
|
|
|
avoidInlineStyle: true, |
|
|
|
storageManager: false, |
|
|
|
}); |
|
|
|
em = editor.getModel(); |
|
|
|
fxt.appendChild(em.Canvas.render()); |
|
|
|
em.loadOnStart(); |
|
|
|
editor.on('change:ready', () => { |
|
|
|
root = editor.Components.getWrapper()!; |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
editor.destroy(); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('render components with asDocument', () => { |
|
|
|
const docHtml = ` |
|
|
|
<!DOCTYPE html> |
|
|
|
<html lang="en" class="cls-html" data-gjs-htmlp="true"> |
|
|
|
<head class="cls-head" data-gjs-headp="true"> |
|
|
|
<meta charset="utf-8"> |
|
|
|
<title>Test</title> |
|
|
|
<link rel="stylesheet" href="/noop.css"> |
|
|
|
<!-- comment --> |
|
|
|
</head> |
|
|
|
<body class="cls-body" data-gjs-bodyp="true"> |
|
|
|
<h1>H1</h1> |
|
|
|
</body> |
|
|
|
</html> |
|
|
|
`;
|
|
|
|
|
|
|
|
test('initial setup', () => { |
|
|
|
expect(root.head.components().length).toBe(0); |
|
|
|
expect(root.get('doctype')).toBe(''); |
|
|
|
}); |
|
|
|
|
|
|
|
test('import HTML document without option', () => { |
|
|
|
root.components(docHtml); |
|
|
|
expect(root.head.components().length).toBe(0); |
|
|
|
expect(root.get('doctype')).toBe(''); |
|
|
|
}); |
|
|
|
|
|
|
|
test('import HTML document with asDocument', () => { |
|
|
|
root.components(docHtml, { asDocument: true }); |
|
|
|
const { head, docEl } = root; |
|
|
|
expect(head.components().length).toBe(4); |
|
|
|
expect(head.get('headp')).toBe(true); |
|
|
|
expect(docEl.get('htmlp')).toBe(true); |
|
|
|
expect(root.get('bodyp')).toBe(true); |
|
|
|
expect(root.get('doctype')).toBe('<!DOCTYPE html>'); |
|
|
|
|
|
|
|
const outputHtml = ` |
|
|
|
<!DOCTYPE html> |
|
|
|
<html lang="en" class="cls-html"> |
|
|
|
<head class="cls-head"> |
|
|
|
<meta charset="utf-8"/> |
|
|
|
<title>Test</title> |
|
|
|
<link rel="stylesheet" href="/noop.css"/> |
|
|
|
<!-- comment --> |
|
|
|
</head> |
|
|
|
<body class="cls-body"> |
|
|
|
<h1>H1</h1> |
|
|
|
</body> |
|
|
|
</html> |
|
|
|
`.replace(/>\s+|\s+</g, m => m.trim());
|
|
|
|
expect(root.toHTML()).toBe(outputHtml); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|