# This tests just quoted text within a contenteditable.
#
# For a test of the basic component itself see
# contenteditable-component-spec.cjsx
#
_ = require "underscore"
React = require "react/addons"
ReactTestUtils = React.addons.TestUtils
Fields = require '../lib/fields'
Composer = require "../lib/composer-view"
ComposerEditor = require '../lib/composer-editor'
{Message, DraftStore, ComponentRegistry} = require 'nylas-exports'
describe "Composer Quoted Text", ->
beforeEach ->
# TODO
# Extract ComposerEditor tests instead of rendering injected component
# here
ComposerEditor.containerRequired = false
ComponentRegistry.register(ComposerEditor, role: "Composer:Editor")
@onChange = jasmine.createSpy('onChange')
@htmlNoQuote = 'Test HTML
'
@htmlWithQuote = 'Test HTML
QUOTE' spyOn(Composer.prototype, "_prepareForDraft") @draft = new Message(draft: true, clientId: "client-123") @composer = ReactTestUtils.renderIntoDocument(
QUOTE CHANGED!!!' expect(@$contentEditable.innerHTML).toBe @htmlWithQuote setHTML.call(@, newText) ev = @composer._addToProxy.mostRecentCall.args[0].body 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() it 'prompts to hide the quote', -> expect(React.findDOMNode(@toggle).textContent).toEqual "•••Hide previous" describe 'when showQuotedText is false', -> beforeEach -> @composer.setState body: @htmlWithQuote showQuotedText: false @contentEditable = @composer.refs[Fields.Body] @$contentEditable = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithAttr(@contentEditable, 'contentEditable')) @$composerBodyWrap = React.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 `_addToProxy`", -> textToAdd = "MORE TEXT!" expect(@$contentEditable.innerHTML).toBe @htmlNoQuote setHTML.call(@, textToAdd + @htmlNoQuote) ev = @composer._addToProxy.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 = @composer._addToProxy.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 'prompts to hide the quote', -> expect(React.findDOMNode(@toggle).textContent).toEqual "•••Show previous"