fix(send-warnings): One character is valid body (T1929) and attachment is valid body (T1881)

Summary: This fixes T1881 and fixes T1929 and adds two additional test cases

Test Plan: Run 2 new tests

Reviewers: evan

Reviewed By: evan

Maniphest Tasks: T1929, T1881

Differential Revision: https://phab.nylas.com/D1645
This commit is contained in:
Ben Gotow 2015-06-17 12:29:21 -07:00
parent 19378ef5b0
commit fc796dc7aa
2 changed files with 70 additions and 38 deletions

View file

@ -469,18 +469,24 @@ class ComposerView extends React.Component
})
return
warnings = []
if draft.subject.length is 0
warnings.push('without a subject line')
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)
hasAttachment = (draft.files ? []).length > 0
# Note: In a completely empty reply, quotedTextIndex is 8
# due to opening elements.
bodyIsEmpty = body.length is 0 or 0 <= quotedTextIndex <= 8
warnings = []
if draft.subject.length is 0
warnings.push('without a subject line')
if @_mentionsAttachment(draft.body) and not hasAttachment
warnings.push('without an attachment')
if bodyIsEmpty and not forwarded and not hasAttachment
warnings.push('without a body')
# Check third party warnings added via DraftStore extensions
@ -506,7 +512,7 @@ class ComposerView extends React.Component
Actions.sendDraft(@props.localId)
_hasAttachment: (body) =>
_mentionsAttachment: (body) =>
body = body.toLowerCase().trim()
attachIndex = body.indexOf("attach")
if attachIndex >= 0

View file

@ -5,6 +5,7 @@ React = require "react/addons"
ReactTestUtils = React.addons.TestUtils
{Actions,
File,
Contact,
Message,
Namespace,
@ -24,6 +25,9 @@ u2 = new Contact(name: "Michael Grinich", email: "mg@nylas.com")
u3 = new Contact(name: "Evan Morikawa", email: "evan@nylas.com")
u4 = new Contact(name: "Zoë Leiper", email: "zip@nylas.com")
u5 = new Contact(name: "Ben Gotow", email: "ben@nylas.com")
file = new File(id: 'file_1_id', filename: 'a.png', contentType: 'image/png', size: 10, object: "file")
users = [u1, u2, u3, u4, u5]
NamespaceStore._current = new Namespace(
{name: u1.name, provider: "inbox", emailAddress: u1.email})
@ -290,35 +294,57 @@ 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']
describe "empty body warning", ->
it "warns 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 "warns 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 "does not warn 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 "does not warn if the user has typed a single character in their reply", ->
useDraft.call @,
to: [u1]
subject: "Hello World"
body: "1<br><br><blockquote class='gmail_quote'>This is my quoted text!</blockquote>"
makeComposer.call(@)
@composer._sendDraft()
expect(Actions.sendDraft).toHaveBeenCalled()
expect(@dialog.showMessageBox).not.toHaveBeenCalled()
it "does not warn if the user has attached a file", ->
useDraft.call @,
to: [u1]
subject: "Hello World"
body: ""
files: [file]
makeComposer.call(@)
@composer._sendDraft()
expect(Actions.sendDraft).toHaveBeenCalled()
expect(@dialog.showMessageBox).not.toHaveBeenCalled()
it "shows a warning if there's no subject", ->
useDraft.call @, to: [u1], subject: ""
@ -364,7 +390,7 @@ describe "populated composer", ->
subject: "Subject"
to: [u1]
body: "Check out attached file"
files: [{id: "123", object: "file", filename:"abc"}]
files: [file]
makeComposer.call(@); @composer._sendDraft()
expect(Actions.sendDraft).toHaveBeenCalled()
expect(@dialog.showMessageBox).not.toHaveBeenCalled()