mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-12 16:04:35 +08:00
Summary: This diff moves us up to React 0.13.2 and transitions some of the core React components to the new syntax based on plain Javascript objects. `setInitialState` is now just code in the constructor, `getDOMNode(@)` is now `React.findDOMNode(@)`, and `isMounted` is no longer necessary or available. This diff also adds `RegisteredComponent` to match `RegisteredRegion`. In another diff, I think we should change the names of these to be `DynamicComponent` and `DynamicComponentSet`. This diff also includes preliminary API Reference docs for Menu.cjsx and Popover.cjsx. You can build the docs using `grunt docs` from the build folder. It produces a simple html format now, but it's easy to customize. Also we now ignore "Unnecessary fat arrow" Test Plan: Run tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1437
45 lines
1.8 KiB
CoffeeScript
45 lines
1.8 KiB
CoffeeScript
# This tests the basic Contenteditable component. For various modules of
|
|
# the contenteditable (such as selection, tooltip, quoting, etc) see the
|
|
# related test files.
|
|
#
|
|
_ = require "underscore-plus"
|
|
React = require "react/addons"
|
|
ReactTestUtils = React.addons.TestUtils
|
|
ContenteditableComponent = require "../lib/contenteditable-component",
|
|
|
|
describe "ContenteditableComponent", ->
|
|
beforeEach ->
|
|
@onChange = jasmine.createSpy('onChange')
|
|
html = 'Test <strong>HTML</strong>'
|
|
@component = ReactTestUtils.renderIntoDocument(
|
|
<ContenteditableComponent html={html} onChange={@onChange}/>
|
|
)
|
|
@editableNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithAttr(@component, 'contentEditable'))
|
|
|
|
describe "render", ->
|
|
it 'should render into the document', ->
|
|
expect(ReactTestUtils.isCompositeComponentWithType @component, ContenteditableComponent).toBe true
|
|
|
|
it "should include a content-editable div", ->
|
|
expect(@editableNode).toBeDefined()
|
|
|
|
describe "when the html is changed", ->
|
|
beforeEach ->
|
|
@changedHtmlWithoutQuote = 'Changed <strong>NEW 1 HTML</strong><br>'
|
|
|
|
@performEdit = (newHTML, component = @component) =>
|
|
@editableNode.innerHTML = newHTML
|
|
ReactTestUtils.Simulate.input(@editableNode, {target: {value: newHTML}})
|
|
|
|
it "should fire `props.onChange`", ->
|
|
@performEdit('Test <strong>New HTML</strong>')
|
|
expect(@onChange).toHaveBeenCalled()
|
|
|
|
# One day we may make this more efficient. For now we aggressively
|
|
# re-render because of the manual cursor positioning.
|
|
it "should fire if the html is the same", ->
|
|
expect(@onChange.callCount).toBe(0)
|
|
@performEdit(@changedHtmlWithoutQuote)
|
|
expect(@onChange.callCount).toBe(1)
|
|
@performEdit(@changedHtmlWithoutQuote)
|
|
expect(@onChange.callCount).toBe(2)
|