From 377d24ec90741318b07f83ef5f5ea711b9809481 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 13 Feb 2024 23:29:16 +0400 Subject: [PATCH] Up tests --- src/parser/model/ParserHtml.ts | 2 +- test/specs/parser/model/ParserHtml.ts | 106 +++++++++++++------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/parser/model/ParserHtml.ts b/src/parser/model/ParserHtml.ts index df0699ab4..42482c27a 100644 --- a/src/parser/model/ParserHtml.ts +++ b/src/parser/model/ParserHtml.ts @@ -273,7 +273,7 @@ const ParserHtml = (em?: EditorModel, config: ParserConfig & { returnArray?: boo break; } - if (cType == 'textnode') { + if (cType === 'textnode') { foundTextNode = 1; } } diff --git a/test/specs/parser/model/ParserHtml.ts b/test/specs/parser/model/ParserHtml.ts index f588824a4..3a8fe7d33 100644 --- a/test/specs/parser/model/ParserHtml.ts +++ b/test/specs/parser/model/ParserHtml.ts @@ -9,7 +9,7 @@ describe('ParserHtml', () => { beforeEach(() => { const em = new Editor({}); - var dom = new DomComponents(em); + const dom = new DomComponents(em); obj = ParserHtml(em, { textTags: ['br', 'b', 'i', 'u'], textTypes: ['text', 'textnode', 'comment'], @@ -19,20 +19,20 @@ describe('ParserHtml', () => { }); test('Simple div node', () => { - var str = '
'; - var result = [{ tagName: 'div' }]; + const str = '
'; + const result = [{ tagName: 'div' }]; expect(obj.parse(str).html).toEqual(result); }); test('Simple article node', () => { - var str = '
'; - var result = [{ tagName: 'article' }]; + const str = '
'; + const result = [{ tagName: 'article' }]; expect(obj.parse(str).html).toEqual(result); }); test('Node with attributes', () => { - var str = '
'; - var result = [ + const str = '
'; + const result = [ { tagName: 'div', classes: ['test2', 'test3'], @@ -47,8 +47,8 @@ describe('ParserHtml', () => { }); test('Parse style string to object', () => { - var str = 'color:black; width:100px; test:value;'; - var result = { + const str = 'color:black; width:100px; test:value;'; + const result = { color: 'black', width: '100px', test: 'value', @@ -57,8 +57,8 @@ describe('ParserHtml', () => { }); test('Parse style string with values containing colon to object', () => { - var str = 'background-image:url("https://some-website.ex"); test:value;'; - var result = { + const str = 'background-image:url("https://some-website.ex"); test:value;'; + const result = { 'background-image': 'url("https://some-website.ex")', test: 'value', }; @@ -76,20 +76,20 @@ describe('ParserHtml', () => { }); test('Parse class string to array', () => { - var str = 'test1 test2 test3 test-4'; - var result = ['test1', 'test2', 'test3', 'test-4']; + const str = 'test1 test2 test3 test-4'; + const result = ['test1', 'test2', 'test3', 'test-4']; expect(obj.parseClass(str)).toEqual(result); }); test('Parse class string to array with special classes', () => { - var str = 'test1 test2 test3 test-4 gjs-test'; - var result = ['test1', 'test2', 'test3', 'test-4', 'gjs-test']; + const str = 'test1 test2 test3 test-4 gjs-test'; + const result = ['test1', 'test2', 'test3', 'test-4', 'gjs-test']; expect(obj.parseClass(str)).toEqual(result); }); test('Style attribute is isolated', () => { - var str = '
'; - var result = [ + const str = '
'; + const result = [ { tagName: 'div', attributes: { id: 'test1' }, @@ -104,8 +104,8 @@ describe('ParserHtml', () => { }); test('Class attribute is isolated', () => { - var str = '
'; - var result = [ + const str = '
'; + const result = [ { tagName: 'div', attributes: { id: 'test1' }, @@ -116,8 +116,8 @@ describe('ParserHtml', () => { }); test('Parse images nodes', () => { - var str = ''; - var result = [ + const str = ''; + const result = [ { tagName: 'img', type: 'image', @@ -131,8 +131,8 @@ describe('ParserHtml', () => { }); test('Parse text nodes', () => { - var str = '
test2
'; - var result = [ + const str = '
test2
'; + const result = [ { tagName: 'div', attributes: { id: 'test1' }, @@ -144,8 +144,8 @@ describe('ParserHtml', () => { }); test('Parse text with few text tags', () => { - var str = '

test2
a b b i u test
'; - var result = [ + const str = '

test2
a b b i u test
'; + const result = [ { tagName: 'div', attributes: { id: 'test1' }, @@ -200,8 +200,8 @@ describe('ParserHtml', () => { }); test('Parse text with few text tags and nested node', () => { - var str = '
a b b ic
ABC
i u test
'; - var result = [ + const str = '
a b b ic
ABC
i u test
'; + const result = [ { tagName: 'div', attributes: { id: 'test1' }, @@ -269,8 +269,8 @@ describe('ParserHtml', () => { }); test('Parse text with few text tags and comment', () => { - var str = '
Some text
Bold
'; - var result = [ + const str = '
Some text
Bold
'; + const result = [ { tagName: 'div', attributes: { id: 'test1' }, @@ -299,9 +299,9 @@ describe('ParserHtml', () => { }); test('Parse nested nodes', () => { - var str = + const str = '
Text mid
'; - var result = [ + const result = [ { tagName: 'article', attributes: { id: 'test1' }, @@ -334,8 +334,8 @@ describe('ParserHtml', () => { }); test('Parse nested text nodes', () => { - var str = '
content1
nested
content2
'; - var result = [ + const str = '
content1
nested
content2
'; + const result = [ { tagName: 'div', type: 'text', @@ -362,8 +362,8 @@ describe('ParserHtml', () => { }); test('Parse nested span text nodes', () => { - var str = '
content1
nested
content2
'; - var result = [ + const str = '
content1
nested
content2
'; + const result = [ { tagName: 'div', components: [ @@ -394,21 +394,21 @@ describe('ParserHtml', () => { }); test('Parse multiple nodes', () => { - var str = '
'; - var result = [{ tagName: 'div' }, { tagName: 'div' }]; + const str = '
'; + const result = [{ tagName: 'div' }, { tagName: 'div' }]; expect(obj.parse(str).html).toEqual(result); }); test('Remove script tags', () => { - var str = '
'; - var result = [{ tagName: 'div' }, { tagName: 'div' }]; + const str = '
'; + const result = [{ tagName: 'div' }, { tagName: 'div' }]; expect(obj.parse(str).html).toEqual(result); }); test('Isolate styles', () => { - var str = '
'; - var resHtml = [{ tagName: 'div' }, { tagName: 'div' }]; - var resCss = [ + const str = '
'; + const resHtml = [{ tagName: 'div' }, { tagName: 'div' }]; + const resCss = [ { selectors: ['a'], style: { color: 'red' }, @@ -418,7 +418,7 @@ describe('ParserHtml', () => { style: { color: 'blue' }, }, ]; - var res = obj.parse(str, ParserCss()); + const res = obj.parse(str, ParserCss()); expect(res.html).toEqual(resHtml); expect(res.css).toEqual(resCss); }); @@ -466,8 +466,8 @@ describe('ParserHtml', () => { }); test('Parse nested div with text and spaces', () => { - var str = '

TestText

'; - var result = [ + const str = '

TestText

'; + const result = [ { tagName: 'div', type: 'text', @@ -494,9 +494,9 @@ describe('ParserHtml', () => { }); test('Parse node with model attributes to fetch', () => { - var str = + const str = '
test2
'; - var result = [ + const result = [ { tagName: 'div', draggable: '.myselector', @@ -513,8 +513,8 @@ describe('ParserHtml', () => { }); test('Parse model attributes with true and false', () => { - var str = '
test2
'; - var result = [ + const str = '
test2
'; + const result = [ { tagName: 'div', draggable: true, @@ -531,8 +531,8 @@ describe('ParserHtml', () => { }); test('Parse attributes with object inside', () => { - var str = '
test2
'; - var result = [ + const str = '
test2
'; + const result = [ { tagName: 'div', attributes: {}, @@ -549,8 +549,8 @@ describe('ParserHtml', () => { }); test('Parse attributes with arrays inside', () => { - var str = '
test2
'; - var result = [ + const str = '
test2
'; + const result = [ { tagName: 'div', attributes: {},