Skip to content

Commit ef800a3

Browse files
committed
Fixes mac-s-g#95 The updated_src after an onEdit restores the initial props.src instead of the current props.src
1 parent 3f069f2 commit ef800a3

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/js/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ export default class extends React.Component {
7878
}
7979
}
8080

81+
componentDidUpdate() {
82+
ObjectAttributes.set(
83+
this.rjvId,
84+
'global',
85+
'src',
86+
this.props.src
87+
);
88+
}
89+
8190
init = (props) => {
8291
for (let i in this.defaults) {
8392
if (props[i] !== undefined) {

test/tests/js/components/VariableEditor-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ describe('<VariableEditor />', function () {
121121
).to.equal(0);
122122
});
123123

124+
it('VariableEditor edit after src change should respect current src', function () {
125+
const oldSrc = {edited: true, other: 'old'};
126+
const currentSrc = {edited: true, other: 'current'};
127+
128+
const wrapper = mount(
129+
<Index
130+
src={oldSrc}
131+
theme='rjv-default'
132+
onEdit={(edit) => {
133+
expect(edit.updated_src.other).to.equal(currentSrc.other);
134+
return true;
135+
}}
136+
rjvId={rjvId}
137+
/>
138+
);
139+
wrapper.setProps({src: currentSrc});
140+
141+
wrapper.find('.click-to-edit-icon').first().simulate('click');
142+
expect(
143+
wrapper.state('onEdit')
144+
).to.not.equal(false);
145+
expect(
146+
wrapper.find('.variable-editor').length
147+
).to.equal(1);
148+
wrapper.find('.edit-check.string-value').simulate('click');
149+
expect(
150+
wrapper.find('.variable-editor').length
151+
).to.equal(0);
152+
});
153+
124154
it('VariableEditor detected null', function () {
125155
const wrapper = shallow(
126156
<VariableEditor

0 commit comments

Comments
 (0)