2015-03-06 08:00:56 +08:00
|
|
|
# This tests just quoted text within a contenteditable.
|
|
|
|
#
|
|
|
|
# For a test of the basic component itself see
|
|
|
|
# contenteditable-component-spec.cjsx
|
|
|
|
#
|
2015-05-20 07:06:59 +08:00
|
|
|
_ = require "underscore"
|
2015-03-06 08:00:56 +08:00
|
|
|
React = require "react/addons"
|
|
|
|
ReactTestUtils = React.addons.TestUtils
|
2015-09-23 07:02:44 +08:00
|
|
|
|
|
|
|
Fields = require '../lib/fields'
|
2015-10-31 08:03:33 +08:00
|
|
|
Composer = require "../lib/composer-view"
|
|
|
|
{DraftStore} = require 'nylas-exports'
|
2015-03-06 08:00:56 +08:00
|
|
|
|
2015-10-31 08:03:33 +08:00
|
|
|
describe "Composer Quoted Text", ->
|
2015-03-06 08:00:56 +08:00
|
|
|
beforeEach ->
|
|
|
|
@onChange = jasmine.createSpy('onChange')
|
2015-09-04 10:41:56 +08:00
|
|
|
@htmlNoQuote = 'Test <strong>HTML</strong><br>'
|
|
|
|
@htmlWithQuote = 'Test <strong>HTML</strong><br><blockquote class="gmail_quote">QUOTE</blockquote>'
|
|
|
|
|
2015-09-23 07:02:44 +08:00
|
|
|
@composer = ReactTestUtils.renderIntoDocument(<Composer draftClientId="unused"/>)
|
2015-10-31 08:03:33 +08:00
|
|
|
@composer._proxy = trigger: ->
|
|
|
|
spyOn(@composer, "_addToProxy")
|
|
|
|
|
|
|
|
spyOn(@composer, "_setupSession")
|
|
|
|
spyOn(@composer, "_teardownForDraft")
|
|
|
|
spyOn(@composer, "_deleteDraftIfEmpty")
|
|
|
|
spyOn(@composer, "_renderAttachments")
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
DraftStore._cleanupAllSessions()
|
2015-09-23 07:02:44 +08:00
|
|
|
|
2015-09-04 10:41:56 +08:00
|
|
|
# Must be called with the test's scope
|
|
|
|
setHTML = (newHTML) ->
|
|
|
|
@$contentEditable.innerHTML = newHTML
|
|
|
|
ReactTestUtils.Simulate.input(@$contentEditable, {target: {value: newHTML}})
|
|
|
|
|
|
|
|
describe "quoted-text-control toggle button", ->
|
|
|
|
|
|
|
|
describe "when there's no quoted text", ->
|
2015-03-18 07:19:40 +08:00
|
|
|
beforeEach ->
|
2015-09-23 07:02:44 +08:00
|
|
|
@composer.setState
|
|
|
|
body: @htmlNoQuote
|
|
|
|
showQuotedText: true
|
|
|
|
@contentEditable = @composer.refs[Fields.Body]
|
2015-09-04 10:41:56 +08:00
|
|
|
@$contentEditable = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithAttr(@contentEditable, 'contentEditable'))
|
2015-10-31 08:03:33 +08:00
|
|
|
@$composerBodyWrap = React.findDOMNode(@composer.refs.composerBodyWrap)
|
2015-03-18 07:19:40 +08:00
|
|
|
|
2015-09-04 10:41:56 +08:00
|
|
|
it 'should not display any quoted text', ->
|
|
|
|
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
|
2015-03-06 08:00:56 +08:00
|
|
|
|
2015-09-04 10:41:56 +08:00
|
|
|
it "allows the text to update", ->
|
|
|
|
textToAdd = "MORE <strong>TEXT</strong>!"
|
|
|
|
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
|
|
|
|
setHTML.call(@, textToAdd + @htmlNoQuote)
|
2015-10-31 08:03:33 +08:00
|
|
|
ev = @composer._addToProxy.mostRecentCall.args[0].body
|
|
|
|
expect(ev).toEqual(textToAdd + @htmlNoQuote)
|
2015-03-06 08:00:56 +08:00
|
|
|
|
2015-09-04 10:41:56 +08:00
|
|
|
it 'should not render the quoted-text-control toggle', ->
|
2015-10-31 08:03:33 +08:00
|
|
|
toggles = ReactTestUtils.scryRenderedDOMComponentsWithClass(@composer, 'quoted-text-control')
|
2015-09-04 10:41:56 +08:00
|
|
|
expect(toggles.length).toBe 0
|
|
|
|
|
|
|
|
|
|
|
|
describe 'when showQuotedText is true', ->
|
2015-03-06 08:00:56 +08:00
|
|
|
beforeEach ->
|
2015-09-23 07:02:44 +08:00
|
|
|
@composer.setState
|
|
|
|
body: @htmlWithQuote
|
|
|
|
showQuotedText: true
|
|
|
|
@contentEditable = @composer.refs[Fields.Body]
|
2015-09-04 10:41:56 +08:00
|
|
|
@$contentEditable = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithAttr(@contentEditable, 'contentEditable'))
|
2015-10-31 08:03:33 +08:00
|
|
|
@$composerBodyWrap = React.findDOMNode(@composer.refs.composerBodyWrap)
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
it 'should display the quoted text', ->
|
|
|
|
expect(@$contentEditable.innerHTML).toBe @htmlWithQuote
|
|
|
|
|
2015-10-31 08:03:33 +08:00
|
|
|
it "should call `_addToProxy` with the entire HTML string", ->
|
2015-09-04 10:41:56 +08:00
|
|
|
textToAdd = "MORE <strong>TEXT</strong>!"
|
|
|
|
expect(@$contentEditable.innerHTML).toBe @htmlWithQuote
|
|
|
|
setHTML.call(@, textToAdd + @htmlWithQuote)
|
2015-10-31 08:03:33 +08:00
|
|
|
ev = @composer._addToProxy.mostRecentCall.args[0].body
|
|
|
|
expect(ev).toEqual(textToAdd + @htmlWithQuote)
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
it "should allow the quoted text to be changed", ->
|
|
|
|
newText = 'Test <strong>NEW 1 HTML</strong><blockquote class="gmail_quote">QUOTE CHANGED!!!</blockquote>'
|
|
|
|
expect(@$contentEditable.innerHTML).toBe @htmlWithQuote
|
|
|
|
setHTML.call(@, newText)
|
2015-10-31 08:03:33 +08:00
|
|
|
ev = @composer._addToProxy.mostRecentCall.args[0].body
|
|
|
|
expect(ev).toEqual(newText)
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
describe 'quoted text control toggle button', ->
|
|
|
|
beforeEach ->
|
2015-10-31 08:03:33 +08:00
|
|
|
@toggle = ReactTestUtils.findRenderedDOMComponentWithClass(@composer, 'quoted-text-control')
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
it 'should be rendered', ->
|
|
|
|
expect(@toggle).toBeDefined()
|
2015-03-06 08:00:56 +08:00
|
|
|
|
2015-09-04 10:41:56 +08:00
|
|
|
it 'prompts to hide the quote', ->
|
|
|
|
expect(React.findDOMNode(@toggle).textContent).toEqual "•••Hide previous"
|
2015-03-06 08:00:56 +08:00
|
|
|
|
2015-09-04 10:41:56 +08:00
|
|
|
describe 'when showQuotedText is false', ->
|
|
|
|
beforeEach ->
|
2015-09-23 07:02:44 +08:00
|
|
|
@composer.setState
|
|
|
|
body: @htmlWithQuote
|
|
|
|
showQuotedText: false
|
|
|
|
@contentEditable = @composer.refs[Fields.Body]
|
2015-09-04 10:41:56 +08:00
|
|
|
@$contentEditable = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithAttr(@contentEditable, 'contentEditable'))
|
2015-10-31 08:03:33 +08:00
|
|
|
@$composerBodyWrap = React.findDOMNode(@composer.refs.composerBodyWrap)
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2015-10-31 08:03:33 +08:00
|
|
|
it "should let you change the text, and then append the quoted text part to the end before firing `_addToProxy`", ->
|
2015-09-04 10:41:56 +08:00
|
|
|
textToAdd = "MORE <strong>TEXT</strong>!"
|
|
|
|
expect(@$contentEditable.innerHTML).toBe @htmlNoQuote
|
|
|
|
setHTML.call(@, textToAdd + @htmlNoQuote)
|
2015-10-31 08:03:33 +08:00
|
|
|
ev = @composer._addToProxy.mostRecentCall.args[0].body
|
2015-09-04 10:41:56 +08:00
|
|
|
# Note that we expect the version WITH a quote while setting the
|
|
|
|
# version withOUT a quote.
|
2015-10-31 08:03:33 +08:00
|
|
|
expect(ev).toEqual(wrapBody(textToAdd + @htmlWithQuote))
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
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)
|
2015-10-31 08:03:33 +08:00
|
|
|
ev = @composer._addToProxy.mostRecentCall.args[0].body
|
2015-09-04 10:41:56 +08:00
|
|
|
# Note that we expect the version WITH a quote while setting the
|
|
|
|
# version withOUT a quote.
|
2015-10-31 08:03:33 +08:00
|
|
|
expect(ev).toEqual(wrapBody(textToAdd + @htmlWithQuote))
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
describe 'quoted text control toggle button', ->
|
2015-03-18 07:19:40 +08:00
|
|
|
beforeEach ->
|
2015-10-31 08:03:33 +08:00
|
|
|
@toggle = ReactTestUtils.findRenderedDOMComponentWithClass(@composer, 'quoted-text-control')
|
2015-09-04 10:41:56 +08:00
|
|
|
|
|
|
|
it 'should be rendered', ->
|
|
|
|
expect(@toggle).toBeDefined()
|
|
|
|
|
|
|
|
it 'prompts to hide the quote', ->
|
|
|
|
expect(React.findDOMNode(@toggle).textContent).toEqual "•••Show previous"
|