From 83356fac141a908b15a4f36a0478555c56ade25c Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 24 Oct 2018 19:25:53 +0100 Subject: [PATCH] Further improvements to tests - focus on wrapper cases - divs and sections - extra case for
--- tests/unit/parsers/dom-test.js | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/unit/parsers/dom-test.js b/tests/unit/parsers/dom-test.js index 9c4d3dbeb..b1a10f53d 100644 --- a/tests/unit/parsers/dom-test.js +++ b/tests/unit/parsers/dom-test.js @@ -67,12 +67,15 @@ let expectations = [ // See https://github.com/bustle/mobiledoc-kit/issues/333 ['abc\ndef', ['abc def']], +]; +let structures = [ // See https://github.com/bustle/mobiledoc-kit/issues/648 - ['

first

second

', ['first', 'second']], - ['

first

second

', ['first', 'second']], - ['

first

second

', ['first', 'second']], - ['

first

second

', ['first', 'second']] + ['

first

second

', ['first','second'], 'one level'], + ['

first

second

', ['first', 'second'], 'two levels'], + ['

first

second

', ['first', 'second'], 'three levels'], + ['

first

second

', ['first', 'second'], 'offset left'], + ['

first

second

', ['first', 'second'], 'offset right'] ]; expectations.forEach(([html, dslText]) => { @@ -84,6 +87,15 @@ expectations.forEach(([html, dslText]) => { }); }); +structures.forEach(([html, dslText, name]) => { + test(`wrapped#parse ${html} -> ${dslText} (${name})`, (assert) => { + let post = parser.parse(buildDOM(html)); + let { post: expected } = buildFromText(dslText); + + assert.postIsSimilar(post, expected); + }); +}); + test('editor#parse fixes text in atom headTextNode when atom is at start of section', (assert) => { let done = assert.async(); let {post: expected} = buildFromText(['X@("name": "mention", "value": "bob")']); @@ -221,6 +233,28 @@ test('strong tag + em + text node creates section', (assert) => { assert.ok(!m2.hasMarkup('em'), 'm1 is not em'); }); +test('wrapped strong tag + em + text node creates section', (assert) => { + let element = buildDOM('
stray markup tags
'); + const post = parser.parse(element); + + assert.equal(post.sections.length, 1, 'parse 1 section'); + assert.equal(post.sections.objectAt(0).text, 'stray markup tags'); + + let markers = post.sections.objectAt(0).markers.toArray(); + assert.equal(markers.length, 2, '2 markers'); + + let [m1, m2] = markers; + + assert.equal(m1.value, 'stray'); + assert.equal(m2.value, ' markup tags'); + + assert.ok(m1.hasMarkup('b'), 'm1 is b'); + assert.ok(m1.hasMarkup('em'), 'm1 is em'); + + assert.ok(m2.hasMarkup('b'), 'm2 is b'); + assert.ok(!m2.hasMarkup('em'), 'm1 is not em'); +}); + test('link (A tag) is parsed', (assert) => { let url = 'http://bustle.com', rel = 'nofollow';