Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honour preview prop lifecycle #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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