Mailspring/spec-nylas/dom-utils-spec.coffee
Evan Morikawa 98a57e434c fix(quoted-text): new system to remove quoted text
Summary:
We need to remove quoted text completely from bodies in a composer.
Unfortunately, that makes it very difficult to determine how to put it
back in.

For now the scheme is to append the quoted text at the end. However, that
means that we need to only pull out quoted text at the end of a message.

Unfortunately there are lots of places that quoted text appears inline
with regular text.

Determining whether or not some content is at the "end" of a message
turned out to be non-trivial.

We now have a new `DOMUtils` that looks for empty areas at the end.

We also have a new quoted HTML parser that finds trailing quotes.

Fixes T2335

Test Plan: lots of new quoted text tests

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T2335

Differential Revision: https://phab.nylas.com/D1773
2015-07-21 11:34:47 -07:00

80 lines
1.3 KiB
CoffeeScript

_ = require 'underscore'
DOMUtils = require '../src/dom-utils'
describe 'nodesWithContent', ->
tests = {
"": null
"<br>": null
"<div><br><br/><p></p></div>": null
"""
<br id="1">
<img>
<br id="2">
""": "<img>"
"""
Hello
""": "Hello"
"""
<div>Hello</div>
""": "<div>Hello</div>"
"""
<div>Hello</div>
Foobar
""": "Foobar"
"""
<br>
<span>Hello</span>
<br>
""": "<span>Hello</span>"
"""
<br>
<span id="a">Hello</span>
<br>
<span id="b">World</span>
<br>
<br>
""": """<span id="b">World</span>"""
"""
<div>Hello</div>
<div>
<p></p>
<span></span>
</div>
""": "<div>Hello</div>"
"""
<div>Hello</div>
<div style="display:none">
I'm hidden
</div>
""": "<div>Hello</div>"
"""
<div>Hello</div>
<div style="opacity:0">
I'm hidden
</div>
""": "<div>Hello</div>"
}
it "tests nodesWithContent", ->
for input, output of tests
nodes = DOMUtils.nodesWithContent(input)
node = _.last(nodes) ? null
if node
tmp = document.createElement('div')
tmp.appendChild(node)
expect(tmp.innerHTML.trim()).toEqual output
else
expect(node).toEqual output