Skip to content

Commit

Permalink
Merge pull request #28 from itsravenous/honour_preview_prop_lifecycle
Browse files Browse the repository at this point in the history
Honour preview prop lifecycle
  • Loading branch information
aweiksnar committed Dec 11, 2015
2 parents c57d06e + 59d5b1b commit 1e8b03f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/markdown-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export default class MarkdownEditor extends React.Component {
this.setState({previewing: !!this.props.previewing});
}

componentWillReceiveProps(nextProps) {
// If previewing prop has changed, update internal state
if (typeof nextProps.previewing === 'boolean') {
this.setState({
previewing: nextProps.previewing
});
}
}

render() {
var previewIcon;
if (this.state.previewing) {
Expand Down
22 changes: 22 additions & 0 deletions test/components/markdown-editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@ describe('MarkdownEditor', () => {
});
});

describe("#componentWillReceiveProps", () => {
it("should set state.previewing to the value of the previewing prop (after mount)", () => {
// We can't manipulate props of editor directly, so create a parent component to do it via render
var TestParent = React.createFactory(React.createClass({
getInitialState() {
return {
previewing: true
};
},
render() {
return <MarkdownEditor ref="editor" previewing={this.state.previewing} value="##blah blash" />
}
}));

var parent = TestUtils.renderIntoDocument(TestParent());
parent.setState({
previewing: false
});
expect(parent.refs.editor.state.previewing).to.be.false;
});
});

describe("#render", () => {
[["insert-link", "InsertLink"],
["insert-image", "InsertImage"],
Expand Down

0 comments on commit 1e8b03f

Please sign in to comment.