fix(T1242): Warn when sending an empty body, or a body that is all quoted text and not a forward.

Summary: Resolves T1242

Test Plan: Run new tests

Reviewers: evan

Reviewed By: evan

Maniphest Tasks: T1242

Differential Revision: https://review.inboxapp.com/D1509
This commit is contained in:
Ben Gotow 2015-05-15 10:53:22 -07:00
parent f1cec289af
commit e42e683f06
3 changed files with 39 additions and 2 deletions

View file

@ -263,7 +263,6 @@ class ComposerView extends React.Component
# focused depending on the draft type, or you can pass a field as
# the first parameter.
focus: (field = null) =>
if component?.isForwardedMessage()
field ?= "textFieldTo"
else
@ -368,6 +367,14 @@ class ComposerView extends React.Component
if (draft.files ? []).length is 0 and @_hasAttachment(draft.body)
warnings.push('without an attachment')
# Warn if the user tries to send a message with no body, or with a body that
# is only quoted text and not a forward.
body = draft.body.toLowerCase().trim()
forwarded = Utils.isForwardedMessage(draft)
quotedTextIndex = Utils.quotedTextIndex(body)
if body.length is 0 or (0 <= quotedTextIndex <= 10 and not forwarded)
warnings.push('without a body')
# Check third party warnings added via DraftStore extensions
for extension in DraftStore.extensions()
continue unless extension.warningsForSending

View file

@ -197,6 +197,36 @@ describe "populated composer", ->
dialogArgs = @dialog.showMessageBox.mostRecentCall.args[1]
expect(dialogArgs.buttons).toEqual ['Edit Message']
it "shows a warning if the body of the email is empty", ->
useDraft.call @, to: [u1], body: ""
makeComposer.call(@)
@composer._sendDraft()
expect(Actions.sendDraft).not.toHaveBeenCalled()
expect(@dialog.showMessageBox).toHaveBeenCalled()
dialogArgs = @dialog.showMessageBox.mostRecentCall.args[1]
expect(dialogArgs.buttons).toEqual ['Cancel', 'Send Anyway']
it "shows a warning if the body of the email is all quoted text", ->
useDraft.call @,
to: [u1]
subject: "Hello World"
body: "<br><br><blockquote class='gmail_quote'>This is my quoted text!</blockquote>"
makeComposer.call(@)
@composer._sendDraft()
expect(Actions.sendDraft).not.toHaveBeenCalled()
expect(@dialog.showMessageBox).toHaveBeenCalled()
dialogArgs = @dialog.showMessageBox.mostRecentCall.args[1]
expect(dialogArgs.buttons).toEqual ['Cancel', 'Send Anyway']
it "does not show a warning if the body of the email is all quoted text, but the email is a forward", ->
useDraft.call @,
to: [u1]
subject: "Fwd: Hello World"
body: "<br><br><blockquote class='gmail_quote'>This is my quoted text!</blockquote>"
makeComposer.call(@)
@composer._sendDraft()
expect(Actions.sendDraft).toHaveBeenCalled()
it "shows a warning if there's no subject", ->
useDraft.call @, to: [u1], subject: ""
makeComposer.call(@)

View file

@ -1,6 +1,6 @@
React = require 'react/addons'
moment = require 'moment'
Utils = require 'inbox-exports'
{Utils} = require 'inbox-exports'
class ActivityBarLongPollItem extends React.Component
@displayName: 'ActivityBarLongPollItem'