fix(quoted-text): Check that message is reply

This commit is contained in:
Jackie Luo 2016-07-21 15:56:24 -07:00
parent ba32391351
commit ad047755e6
5 changed files with 44 additions and 87 deletions

View file

@ -97,33 +97,24 @@ describe "ComposerView", ->
expect(@session.changes.add).toHaveBeenCalled()
expect(@session.changes.add.calls.length).toBe 1
body = @session.changes.add.calls[0].args[0].body
expect(body).toBe "<head></head><body>Hello <strong>world</strong></body>"
expect(body).toBe "Hello <strong>world</strong>"
describe "when sending a reply-to message", ->
beforeEach ->
@replyBody = """<blockquote class="gmail_quote">On Sep 3 2015, at 12:14 pm, Evan Morikawa &lt;evan@evanmorikawa.com&gt; wrote:<br>This is a test!</blockquote>"""
useDraft.call @,
from: [u1]
to: [u2]
subject: "Test Reply Message 1"
body: @replyBody
body: ""
replyToMessageId: "1"
makeComposer.call @
@editableNode = ReactDOM.findDOMNode(@composer).querySelector('[contenteditable]')
spyOn(@session.changes, "add")
it 'begins with the replying message collapsed', ->
it 'begins with empty body', ->
expect(@editableNode.innerHTML).toBe ""
it 'saves the full new body, plus quoted text', ->
@editableNode.innerHTML = "Hello <strong>world</strong>"
@composer.refs[Fields.Body]._onDOMMutated(["mutated"])
expect(@session.changes.add).toHaveBeenCalled()
expect(@session.changes.add.calls.length).toBe 1
body = @session.changes.add.calls[0].args[0].body
expect(body).toBe """<head></head><body>Hello <strong>world</strong>#{@replyBody}</body>"""
describe "when sending a forwarded message", ->
beforeEach ->
@fwdBody = """<br><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

View file

@ -20,7 +20,7 @@ describe "Composer Quoted Text", ->
@onChange = jasmine.createSpy('onChange')
@htmlNoQuote = 'Test <strong>HTML</strong><br>'
@htmlWithQuote = 'Test <strong>HTML</strong><br><blockquote class="gmail_quote">QUOTE</blockquote>'
@htmlWithQuote = 'Test <strong>HTML</strong><div id="n1-quoted-text-marker"></div><br><blockquote class="gmail_quote">QUOTE</blockquote>'
@draft = new Message(draft: true, clientId: "client-123")
@session =
@ -39,36 +39,24 @@ describe "Composer Quoted Text", ->
@$contentEditable.innerHTML = newHTML
@contentEditable._onDOMMutated(["mutated"])
describe "quoted-text-control toggle button", ->
describe "when there's no quoted text", ->
describe "when the message is a reply", ->
beforeEach ->
@draft.body = @htmlNoQuote
@composer = ReactTestUtils.renderIntoDocument(
<Composer draft={@draft} session={@session}/>
)
@composer.setState
showQuotedText: true
showQuotedText: false
showQuotedTextControl: true
@contentEditable = @composer.refs[Fields.Body]
@$contentEditable = ReactDOM.findDOMNode(@contentEditable).querySelector('[contenteditable]')
@$composerBodyWrap = ReactDOM.findDOMNode(@composer.refs.composerBodyWrap)
it 'should not display any quoted text', ->
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
it "allows the text to update", ->
textToAdd = "MORE <strong>TEXT</strong>!"
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
setHTML.call(@, textToAdd + @htmlNoQuote)
ev = @session.changes.add.mostRecentCall.args[0].body
expect(ev).toEqual(textToAdd + @htmlNoQuote)
it 'should not render the quoted-text-control toggle', ->
it 'should render the quoted-text-control toggle', ->
toggles = ReactTestUtils.scryRenderedDOMComponentsWithClass(@composer, 'quoted-text-control')
expect(toggles.length).toBe 0
expect(toggles.length).toBe 1
describe 'when there is quoted text, and showQuotedText is true', ->
describe 'when the quoted text has been expanded', ->
beforeEach ->
@draft.body = @htmlWithQuote
@composer = ReactTestUtils.renderIntoDocument(
@ -76,13 +64,11 @@ describe "Composer Quoted Text", ->
)
@composer.setState
showQuotedText: true
showQuotedTextControl: false
@contentEditable = @composer.refs[Fields.Body]
@$contentEditable = ReactDOM.findDOMNode(@contentEditable).querySelector('[contenteditable]')
@$composerBodyWrap = ReactDOM.findDOMNode(@composer.refs.composerBodyWrap)
it 'should display the quoted text', ->
expect(@$contentEditable.innerHTML).toBe @htmlWithQuote
it "should call add changes with the entire HTML string", ->
textToAdd = "MORE <strong>TEXT</strong>!"
expect(@$contentEditable.innerHTML).toBe @htmlWithQuote
@ -98,51 +84,6 @@ describe "Composer Quoted Text", ->
expect(ev).toEqual(newText)
describe 'quoted text control toggle button', ->
beforeEach ->
@toggle = ReactTestUtils.findRenderedDOMComponentWithClass(@composer, 'quoted-text-control')
it 'should be rendered', ->
expect(@toggle).toBeDefined()
describe 'when there is quoted text, an showQuotedText is false', ->
beforeEach ->
@draft.body = @htmlWithQuote
@composer = ReactTestUtils.renderIntoDocument(
<Composer draft={@draft} session={@session}/>
)
@composer.setState
showQuotedText: false
@contentEditable = @composer.refs[Fields.Body]
@$contentEditable = ReactDOM.findDOMNode(@contentEditable).querySelector('[contenteditable]')
@$composerBodyWrap = ReactDOM.findDOMNode(@composer.refs.composerBodyWrap)
# The quoted text dom parser wraps stuff inertly in body tags
wrapBody = (html) -> "<head></head><body>#{html}</body>"
it 'should not display any quoted text', ->
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
it "should let you change the text, and then append the quoted text part to the end before firing adding changes", ->
textToAdd = "MORE <strong>TEXT</strong>!"
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
setHTML.call(@, textToAdd + @htmlNoQuote)
ev = @session.changes.add.mostRecentCall.args[0].body
# Note that we expect the version WITH a quote while setting the
# version withOUT a quote.
expect(ev).toEqual(wrapBody(textToAdd + @htmlWithQuote))
it "should let you add more html that looks like quoted text, and still properly appends the old quoted text", ->
textToAdd = "Yo <blockquote class=\"gmail_quote\">I'm a fake quote</blockquote>"
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
setHTML.call(@, textToAdd + @htmlNoQuote)
ev = @session.changes.add.mostRecentCall.args[0].body
# Note that we expect the version WITH a quote while setting the
# version withOUT a quote.
expect(ev).toEqual(wrapBody(textToAdd + @htmlWithQuote))
describe 'quoted text control toggle button', ->
beforeEach ->
@toggle = ReactTestUtils.findRenderedDOMComponentWithClass(@composer, 'quoted-text-control')
it 'should be rendered', ->
expect(@toggle).toBeDefined()
it 'should not be rendered', ->
toggles = ReactTestUtils.scryRenderedDOMComponentsWithClass(@composer, 'quoted-text-control')
expect(toggles.length).toBe(0)

View file

@ -12,7 +12,6 @@ requireSpecs = (specDirectory) ->
regex = /-spec\.(coffee|js|jsx|cjsx|es6|es)$/
for specFilePath in fs.listTreeSync(specDirectory)
console.log(specFilePath)
require(specFilePath) if regex.test(specFilePath)
# Set spec directory on spec for setting up the project in spec-helper

View file

@ -2,11 +2,12 @@ import {
Actions,
Message,
DraftHelpers,
DatabaseStore,
SyncbackDraftFilesTask,
} from 'nylas-exports';
describe('DraftHelpers', function describeBlock() {
describe('prepareForSyncback', () => {
describe('prepareDraftForSyncback', () => {
beforeEach(() => {
spyOn(DraftHelpers, 'applyExtensionTransformsToDraft').andCallFake((draft) => Promise.resolve(draft))
spyOn(Actions, 'queueTask')
@ -33,4 +34,29 @@ describe('DraftHelpers', function describeBlock() {
});
});
});
fdescribe('shouldAppendQuotedText', () => {
it('returns true if message is reply and has no marker', () => {
const draft = {
replyToMessageId: 1,
body: `<div>hello!</div>`,
}
expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(true)
})
it('returns false if message is reply and has marker', () => {
const draft = {
replyToMessageId: 1,
body: `<div>hello!</div><div id="n1-quoted-text-marker"></div>Quoted Text`,
}
expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(false)
})
it('returns false if message is not reply', () => {
const draft = {
body: `<div>hello!</div>`,
}
expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(false)
})
})
});

View file

@ -34,8 +34,8 @@ export function isForwardedMessage({body, subject} = {}) {
return bodyForwarded || bodyFwd || subjectFwd
}
export function shouldAppendQuotedText({body = ''} = {}) {
return !body.includes('<div id="n1-quoted-text-marker">')
export function shouldAppendQuotedText({body = '', replyToMessageId = false} = {}) {
return replyToMessageId && !body.includes('<div id="n1-quoted-text-marker">')
}
export function messageMentionsAttachment({body} = {}) {