Skip to content

Commit

Permalink
Further improvements to tests
Browse files Browse the repository at this point in the history
- focus on wrapper cases
- divs and sections
- extra case for <div><b></b></div>
  • Loading branch information
ErisDS authored and kevinansfield committed Dec 10, 2018
1 parent 2eed96e commit 83356fa
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions tests/unit/parsers/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
['<div><p>first</p><p>second</p></div>', ['first', 'second']],
['<div><div><p>first</p><p>second</p></div></div>', ['first', 'second']],
['<div><div><p>first</p></div><p>second</p></div>', ['first', 'second']],
['<div><p>first</p><div><p>second</p></div></div>', ['first', 'second']]
['<section><p>first</p><p>second</p></section>', ['first','second'], 'one level'],
['<section><div><p>first</p><p>second</p></div></section>', ['first', 'second'], 'two levels'],
['<section><div><div><p>first</p><p>second</p></div></div></section>', ['first', 'second'], 'three levels'],
['<section><div><p>first</p></div><p>second</p></section>', ['first', 'second'], 'offset left'],
['<section><p>first</p><div><p>second</p></div></section>', ['first', 'second'], 'offset right']
];

expectations.forEach(([html, dslText]) => {
Expand All @@ -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")']);
Expand Down Expand Up @@ -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('<div><b><em>stray</em> markup tags</b></div>');
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';
Expand Down

0 comments on commit 83356fa

Please sign in to comment.