From ad047755e66e2d9529418bfbcaff0ae00b517cdd Mon Sep 17 00:00:00 2001 From: Jackie Luo Date: Thu, 21 Jul 2016 15:56:24 -0700 Subject: [PATCH] fix(quoted-text): Check that message is reply --- .../composer/spec/composer-view-spec.cjsx | 17 +--- .../composer/spec/quoted-text-spec.cjsx | 81 +++---------------- spec/spec-suite.coffee | 1 - spec/stores/draft-helpers-spec.es6 | 28 ++++++- src/flux/stores/draft-helpers.es6 | 4 +- 5 files changed, 44 insertions(+), 87 deletions(-) diff --git a/internal_packages/composer/spec/composer-view-spec.cjsx b/internal_packages/composer/spec/composer-view-spec.cjsx index 97b50e04d..cebd6b6aa 100644 --- a/internal_packages/composer/spec/composer-view-spec.cjsx +++ b/internal_packages/composer/spec/composer-view-spec.cjsx @@ -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 "Hello world" + expect(body).toBe "Hello world" describe "when sending a reply-to message", -> beforeEach -> - @replyBody = """
On Sep 3 2015, at 12:14 pm, Evan Morikawa <evan@evanmorikawa.com> wrote:
This is a test!
""" - 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 world" - @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 """Hello world#{@replyBody}""" - describe "when sending a forwarded message", -> beforeEach -> @fwdBody = """

diff --git a/internal_packages/composer/spec/quoted-text-spec.cjsx b/internal_packages/composer/spec/quoted-text-spec.cjsx index 0bc291118..abda5c62e 100644 --- a/internal_packages/composer/spec/quoted-text-spec.cjsx +++ b/internal_packages/composer/spec/quoted-text-spec.cjsx @@ -20,7 +20,7 @@ describe "Composer Quoted Text", -> @onChange = jasmine.createSpy('onChange') @htmlNoQuote = 'Test HTML
' - @htmlWithQuote = 'Test HTML
QUOTE
' + @htmlWithQuote = 'Test HTML

QUOTE
' @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.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 TEXT!" - 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 TEXT!" 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.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) -> "#{html}" - - 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 TEXT!" - 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
I'm a fake quote
" - 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) diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee index e6f6e57cb..5f0ebcedd 100644 --- a/spec/spec-suite.coffee +++ b/spec/spec-suite.coffee @@ -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 diff --git a/spec/stores/draft-helpers-spec.es6 b/spec/stores/draft-helpers-spec.es6 index 3b58dca1a..38379a8dd 100644 --- a/spec/stores/draft-helpers-spec.es6 +++ b/spec/stores/draft-helpers-spec.es6 @@ -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: `
hello!
`, + } + expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(true) + }) + + it('returns false if message is reply and has marker', () => { + const draft = { + replyToMessageId: 1, + body: `
hello!
Quoted Text`, + } + expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(false) + }) + + it('returns false if message is not reply', () => { + const draft = { + body: `
hello!
`, + } + expect(DraftHelpers.shouldAppendQuotedText(draft)).toBe(false) + }) + }) }); diff --git a/src/flux/stores/draft-helpers.es6 b/src/flux/stores/draft-helpers.es6 index 6d7aaa571..99dc040b5 100644 --- a/src/flux/stores/draft-helpers.es6 +++ b/src/flux/stores/draft-helpers.es6 @@ -34,8 +34,8 @@ export function isForwardedMessage({body, subject} = {}) { return bodyForwarded || bodyFwd || subjectFwd } -export function shouldAppendQuotedText({body = ''} = {}) { - return !body.includes('
') +export function shouldAppendQuotedText({body = '', replyToMessageId = false} = {}) { + return replyToMessageId && !body.includes('
') } export function messageMentionsAttachment({body} = {}) {