diff --git a/src/parser/model/ParserCss.js b/src/parser/model/ParserCss.js
index 4a4f195ea..15a34a836 100644
--- a/src/parser/model/ParserCss.js
+++ b/src/parser/model/ParserCss.js
@@ -12,7 +12,7 @@ export default (config = {}) => ({
*/
parse(str) {
let result = [];
- const { parserCss, em = {} } = config;
+ const { parserCss, em } = config;
const editor = em && em.get && em.get('Editor');
const nodes = parserCss ? parserCss(str, editor) : BrowserCssParser(str);
nodes.forEach(node => (result = result.concat(this.checkNode(node))));
diff --git a/test/specs/parser/model/ParserCss.js b/test/specs/parser/model/ParserCss.js
index 30c96efc9..c9049e582 100644
--- a/test/specs/parser/model/ParserCss.js
+++ b/test/specs/parser/model/ParserCss.js
@@ -9,7 +9,8 @@ describe('ParserCss', () => {
beforeEach(() => {
config = {
em: {
- getCustomParserCss: () => customParser
+ getCustomParserCss: () => customParser,
+ trigger: () => {}
}
};
obj = new ParserCss(config);
diff --git a/test/specs/parser/model/ParserHtml.js b/test/specs/parser/model/ParserHtml.js
index 19096edc9..44a5ebef0 100644
--- a/test/specs/parser/model/ParserHtml.js
+++ b/test/specs/parser/model/ParserHtml.js
@@ -20,28 +20,30 @@ describe('ParserHtml', () => {
test('Simple div node', () => {
var str = '
';
- var result = { tagName: 'div' };
+ var result = [{ tagName: 'div' }];
expect(obj.parse(str).html).toEqual(result);
});
test('Simple article node', () => {
var str = '';
- var result = { tagName: 'article' };
+ var result = [{ tagName: 'article' }];
expect(obj.parse(str).html).toEqual(result);
});
test('Node with attributes', () => {
var str =
'';
- var result = {
- tagName: 'div',
- classes: ['test2', 'test3'],
- attributes: {
- 'data-one': 'test4',
- id: 'test1',
- strange: 'test5'
+ var result = [
+ {
+ tagName: 'div',
+ classes: ['test2', 'test3'],
+ attributes: {
+ 'data-one': 'test4',
+ id: 'test1',
+ strange: 'test5'
+ }
}
- };
+ ];
expect(obj.parse(str).html).toEqual(result);
});
@@ -79,261 +81,279 @@ describe('ParserHtml', () => {
test('Style attribute is isolated', () => {
var str =
'';
- var result = {
- tagName: 'div',
- attributes: { id: 'test1' },
- style: {
- color: 'black',
- width: '100px',
- test: 'value'
+ var result = [
+ {
+ tagName: 'div',
+ attributes: { id: 'test1' },
+ style: {
+ color: 'black',
+ width: '100px',
+ test: 'value'
+ }
}
- };
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Class attribute is isolated', () => {
var str = '';
- var result = {
- tagName: 'div',
- attributes: { id: 'test1' },
- classes: ['test2', 'test3', 'test4']
- };
+ var result = [
+ {
+ tagName: 'div',
+ attributes: { id: 'test1' },
+ classes: ['test2', 'test3', 'test4']
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse images nodes', () => {
var str = '
';
- var result = {
- tagName: 'img',
- type: 'image',
- attributes: {
- id: 'test1',
- src: './index.html'
+ var result = [
+ {
+ tagName: 'img',
+ type: 'image',
+ attributes: {
+ id: 'test1',
+ src: './index.html'
+ }
}
- };
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse text nodes', () => {
var str = 'test2
';
- var result = {
- tagName: 'div',
- attributes: { id: 'test1' },
- type: 'text',
- content: 'test2 '
- };
+ var result = [
+ {
+ tagName: 'div',
+ attributes: { id: 'test1' },
+ type: 'text',
+ content: 'test2 '
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse text with few text tags', () => {
var str =
'
test2
a b b i u test
';
- var result = {
- tagName: 'div',
- attributes: { id: 'test1' },
- type: 'text',
- components: [
- { tagName: 'br' },
- {
- content: ' test2 ',
- type: 'textnode',
- tagName: ''
- },
- { tagName: 'br' },
- {
- content: ' a b ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'b',
- type: 'text',
- tagName: 'b'
- },
- {
- content: ' ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'i',
- tagName: 'i',
- type: 'text'
- },
- {
- content: ' ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'u',
- tagName: 'u',
- type: 'text'
- },
- {
- content: ' test ',
- type: 'textnode',
- tagName: ''
- }
- ]
- };
+ var result = [
+ {
+ tagName: 'div',
+ attributes: { id: 'test1' },
+ type: 'text',
+ components: [
+ { tagName: 'br' },
+ {
+ content: ' test2 ',
+ type: 'textnode',
+ tagName: ''
+ },
+ { tagName: 'br' },
+ {
+ content: ' a b ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'b',
+ type: 'text',
+ tagName: 'b'
+ },
+ {
+ content: ' ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'i',
+ tagName: 'i',
+ type: 'text'
+ },
+ {
+ content: ' ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'u',
+ tagName: 'u',
+ type: 'text'
+ },
+ {
+ content: ' test ',
+ type: 'textnode',
+ tagName: ''
+ }
+ ]
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse text with few text tags and nested node', () => {
var str =
'';
- var result = {
- tagName: 'div',
- attributes: { id: 'test1' },
- type: 'text',
- components: [
- {
- content: 'a b ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'b',
- tagName: 'b',
- type: 'text'
- },
- {
- content: ' ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'i',
- tagName: 'i',
- type: 'text'
- },
- {
- content: 'c ',
- type: 'textnode',
- tagName: ''
- },
- {
- tagName: 'div',
- type: 'text',
- content: 'ABC'
- },
- {
- content: ' ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'i',
- tagName: 'i',
- type: 'text'
- },
- {
- content: ' ',
- type: 'textnode',
- tagName: ''
- },
- {
- content: 'u',
- tagName: 'u',
- type: 'text'
- },
- {
- content: ' test ',
- type: 'textnode',
- tagName: ''
- }
- ]
- };
+ var result = [
+ {
+ tagName: 'div',
+ attributes: { id: 'test1' },
+ type: 'text',
+ components: [
+ {
+ content: 'a b ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'b',
+ tagName: 'b',
+ type: 'text'
+ },
+ {
+ content: ' ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'i',
+ tagName: 'i',
+ type: 'text'
+ },
+ {
+ content: 'c ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ tagName: 'div',
+ type: 'text',
+ content: 'ABC'
+ },
+ {
+ content: ' ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'i',
+ tagName: 'i',
+ type: 'text'
+ },
+ {
+ content: ' ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ content: 'u',
+ tagName: 'u',
+ type: 'text'
+ },
+ {
+ content: ' test ',
+ type: 'textnode',
+ tagName: ''
+ }
+ ]
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse nested nodes', () => {
var str =
' Text mid ';
- var result = {
- tagName: 'article',
- attributes: { id: 'test1' },
- components: [
- {
- tagName: 'div'
- },
- {
- content: ' ',
- type: 'textnode',
- tagName: ''
- },
- {
- tagName: 'footer',
- attributes: { id: 'test2' }
- },
- {
- tagName: '',
- type: 'textnode',
- content: ' Text mid '
- },
- {
- tagName: 'div',
- attributes: { id: 'last' }
- }
- ]
- };
+ var result = [
+ {
+ tagName: 'article',
+ attributes: { id: 'test1' },
+ components: [
+ {
+ tagName: 'div'
+ },
+ {
+ content: ' ',
+ type: 'textnode',
+ tagName: ''
+ },
+ {
+ tagName: 'footer',
+ attributes: { id: 'test2' }
+ },
+ {
+ tagName: '',
+ type: 'textnode',
+ content: ' Text mid '
+ },
+ {
+ tagName: 'div',
+ attributes: { id: 'last' }
+ }
+ ]
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse nested text nodes', () => {
var str = '';
- var result = {
- tagName: 'div',
- type: 'text',
- components: [
- {
- tagName: '',
- type: 'textnode',
- content: 'content1 '
- },
- {
- tagName: 'div',
- type: 'text',
- content: 'nested'
- },
- {
- tagName: '',
- type: 'textnode',
- content: ' content2'
- }
- ]
- };
+ var result = [
+ {
+ tagName: 'div',
+ type: 'text',
+ components: [
+ {
+ tagName: '',
+ type: 'textnode',
+ content: 'content1 '
+ },
+ {
+ tagName: 'div',
+ type: 'text',
+ content: 'nested'
+ },
+ {
+ tagName: '',
+ type: 'textnode',
+ content: ' content2'
+ }
+ ]
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse nested span text nodes', () => {
var str = '';
- var result = {
- tagName: 'div',
- components: [
- {
- tagName: '',
- type: 'textnode',
- content: 'content1 '
- },
- {
- tagName: 'div',
- components: [
- {
- tagName: 'span',
- type: 'text',
- content: 'nested'
- }
- ]
- },
- {
- tagName: '',
- type: 'textnode',
- content: ' content2'
- }
- ]
- };
+ var result = [
+ {
+ tagName: 'div',
+ components: [
+ {
+ tagName: '',
+ type: 'textnode',
+ content: 'content1 '
+ },
+ {
+ tagName: 'div',
+ components: [
+ {
+ tagName: 'span',
+ type: 'text',
+ content: 'nested'
+ }
+ ]
+ },
+ {
+ tagName: '',
+ type: 'textnode',
+ content: ' content2'
+ }
+ ]
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
@@ -415,89 +435,99 @@ describe('ParserHtml', () => {
test('Parse nested div with text and spaces', () => {
var str = '';
- var result = {
- tagName: 'div',
- type: 'text',
- components: [
- {
- tagName: '',
- type: 'textnode',
- content: ' '
- },
- {
- tagName: 'p',
- content: 'TestText',
- type: 'text'
- },
- {
- tagName: '',
- type: 'textnode',
- content: ' '
- }
- ]
- };
+ var result = [
+ {
+ tagName: 'div',
+ type: 'text',
+ components: [
+ {
+ tagName: '',
+ type: 'textnode',
+ content: ' '
+ },
+ {
+ tagName: 'p',
+ content: 'TestText',
+ type: 'text'
+ },
+ {
+ tagName: '',
+ type: 'textnode',
+ content: ' '
+ }
+ ]
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse node with model attributes to fetch', () => {
var str =
'test2
';
- var result = {
- tagName: 'div',
- draggable: '.myselector',
- stuff: 'test',
- attributes: {
- id: 'test1',
- 'data-test': 'test-value'
- },
- type: 'text',
- content: 'test2 '
- };
+ var result = [
+ {
+ tagName: 'div',
+ draggable: '.myselector',
+ stuff: 'test',
+ attributes: {
+ id: 'test1',
+ 'data-test': 'test-value'
+ },
+ type: 'text',
+ content: 'test2 '
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse model attributes with true and false', () => {
var str =
'test2
';
- var result = {
- tagName: 'div',
- draggable: true,
- stuff: false,
- attributes: {
- id: 'test1',
- 'data-test': 'test-value'
- },
- type: 'text',
- content: 'test2 '
- };
+ var result = [
+ {
+ tagName: 'div',
+ draggable: true,
+ stuff: false,
+ attributes: {
+ id: 'test1',
+ 'data-test': 'test-value'
+ },
+ type: 'text',
+ content: 'test2 '
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse attributes with object inside', () => {
var str = `test2
`;
- var result = {
- tagName: 'div',
- attributes: {},
- type: 'text',
- test: {
- prop1: 'value1',
- prop2: 10,
- prop3: true
- },
- content: 'test2 '
- };
+ var result = [
+ {
+ tagName: 'div',
+ attributes: {},
+ type: 'text',
+ test: {
+ prop1: 'value1',
+ prop2: 10,
+ prop3: true
+ },
+ content: 'test2 '
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
test('Parse attributes with arrays inside', () => {
var str = `test2
`;
- var result = {
- tagName: 'div',
- attributes: {},
- type: 'text',
- test: ['value1', 'value2'],
- content: 'test2 '
- };
+ var result = [
+ {
+ tagName: 'div',
+ attributes: {},
+ type: 'text',
+ test: ['value1', 'value2'],
+ content: 'test2 '
+ }
+ ];
expect(obj.parse(str).html).toEqual(result);
});
});