Skip to content
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
Fixes #95 The updated_src after an onEdit restores the initial props.…
…src instead of the current props.src
  • Loading branch information
shybyte committed Aug 8, 2017
commit ef800a3a0e59d38c32f52abc874260f0624499cd
9 changes: 9 additions & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export default class extends React.Component {
}
}

componentDidUpdate() {
ObjectAttributes.set(
this.rjvId,
'global',
'src',
this.props.src
);
}

init = (props) => {
for (let i in this.defaults) {
if (props[i] !== undefined) {
Expand Down
30 changes: 30 additions & 0 deletions test/tests/js/components/VariableEditor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,36 @@ describe('<VariableEditor />', function () {
).to.equal(0);
});

it('VariableEditor edit after src change should respect current src', function () {
const oldSrc = {edited: true, other: 'old'};
const currentSrc = {edited: true, other: 'current'};

const wrapper = mount(
<Index
src={oldSrc}
theme='rjv-default'
onEdit={(edit) => {
expect(edit.updated_src.other).to.equal(currentSrc.other);
return true;
}}
rjvId={rjvId}
/>
);
wrapper.setProps({src: currentSrc});

wrapper.find('.click-to-edit-icon').first().simulate('click');
expect(
wrapper.state('onEdit')
).to.not.equal(false);
expect(
wrapper.find('.variable-editor').length
).to.equal(1);
wrapper.find('.edit-check.string-value').simulate('click');
expect(
wrapper.find('.variable-editor').length
).to.equal(0);
});

it('VariableEditor detected null', function () {
const wrapper = shallow(
<VariableEditor
Expand Down