fix(quoted-text): Fix + test case for Sentry 8323, body el is quoted text

This commit is contained in:
Ben Gotow 2016-01-11 11:14:34 -08:00
parent 65ee221bc9
commit db7bc9e81c
4 changed files with 27 additions and 11 deletions

View file

@ -1,6 +1,6 @@
_ = require 'underscore'
Reflux = require 'reflux'
{Actions} = require 'nylas-exports'
NylasStore = require 'nylas-store'
VERBOSE = false
DISPLAY_TIME = 3000 # in ms
@ -34,9 +34,8 @@ class Notification
toString: ->
"Notification.#{@constructor.name}(#{@tag})"
module.exports =
NotificationStore = Reflux.createStore
init: ->
class NotificationStore extends NylasStore
constructor: ->
@_flush()
# The notification store listens for user interaction with notififcations
@ -53,12 +52,12 @@ NotificationStore = Reflux.createStore
######### PUBLIC #######################################################
notifications: ->
notifications: =>
console.log(JSON.stringify(@_notifications)) if VERBOSE
sorted = _.sortBy(_.values(@_notifications), (n) -> -1*(n.creation + n.tag))
_.reject sorted, (n) -> n.sticky
stickyNotifications: ->
stickyNotifications: =>
console.log(JSON.stringify(@_notifications)) if VERBOSE
sorted = _.sortBy(_.values(@_notifications), (n) -> -1*(n.creation + n.tag))
_.filter sorted, (n) -> n.sticky
@ -67,10 +66,10 @@ NotificationStore = Reflux.createStore
########### PRIVATE ####################################################
_flush: ->
_flush: =>
@_notifications = {}
_postNotification: (notification) ->
_postNotification: (notification) =>
console.log "Queue Notification.#{notification}" if VERBOSE
@_notifications[notification.tag] = notification
if notification.expiry?
@ -94,5 +93,7 @@ NotificationStore = Reflux.createStore
# If the window matches the given context then we can show a
# notification.
_inWindowContext: (context={}) ->
_inWindowContext: (context={}) =>
return true
module.exports = new NotificationStore()

View file

@ -46,7 +46,7 @@ describe 'NotificationStore', ->
it 'should unregister on removeNotification', ->
Actions.postNotification({type: 'info', message: 'hi'})
n = NotificationsStore.notifications()[0]
NotificationsStore._removeNotification(n)()
NotificationsStore._removeNotification(n)
expect(NotificationsStore.notifications().length).toEqual 0
describe "with a few notifications", ->

View file

@ -256,6 +256,18 @@ describe "QuotedHTMLTransformer", ->
<br></body>
"""
# Test 11: The <body> tag itself is just a quoted text block.
# I believe this is https://sentry.nylas.com/sentry/edgehill/group/8323/
tests.push
before: """
<body id="OLK_SRC_BODY_SECTION">
This entire thing is quoted text!
</body>
"""
after: """<head></head><body></body>
"""
it 'works with these manual test cases', ->
for {before, after} in tests
opts = keepIfWholeBodyIsQuote: true

View file

@ -45,8 +45,11 @@ class QuotedHTMLTransformer
return doc.children[0].innerHTML
else
DOMUtils.Mutating.removeElements(quoteElements, options)
childNodes = doc.body.childNodes
# It's possible that the entire body was quoted text and we've removed everything.
return "<head></head><body></body>" unless doc.body
childNodes = doc.body.childNodes
extraTailBrTags = []
for i in [(childNodes.length - 1)..0] by -1
curr = childNodes[i]