Skip to content

Commit

Permalink
Merge (partial) fixture changes from proxy with current state
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidiuch committed Dec 4, 2016
1 parent 0b7b959 commit 1b98298
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Expand Up @@ -401,18 +401,28 @@ module.exports = React.createClass({
this.setState({ isEditorFocused: isFocused });
},

onFixtureUpdate(fixtureContents) {
onFixtureUpdate(fixtureBody) {
const {
isEditorFocused,
fixtureContents,
} = this.state;

// Don't update fixture contents while the user is editing the fixture
if (this.state.isEditorFocused) {
if (isEditorFocused) {
return;
}

// We assume data received in this handler is serializable (& thus
// part of state.fixtureContents)
const newFixtureContents = {
...fixtureContents,
...fixtureBody,
};

this.setState({
fixtureContents,
fixtureContents: newFixtureContents,
fixtureUserInput:
this.constructor.getStringifiedFixtureContents(fixtureContents),
this.constructor.getStringifiedFixtureContents(newFixtureContents),
isFixtureUserInputValid: true,
});
},
Expand Down
Expand Up @@ -25,7 +25,9 @@ describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, () => {
data: {
type: 'fixtureUpdate',
fixtureBody: {
foo: 'bar',
state: {
somethingHappened: true,
},
},
},
});
Expand All @@ -42,7 +44,12 @@ describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, () => {
});

it('should override serializable fixture part', () => {
expect(stateSet.fixtureContents).to.deep.equal({ foo: 'bar' });
expect(stateSet.fixtureContents).to.deep.equal({
...fixture.state.fixtureContents,
state: {
somethingHappened: true,
},
});
});

it('should keep unserializable fixture part', () => {
Expand All @@ -52,8 +59,12 @@ describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, () => {
});

it('should update stringified child snapshot state', () => {
expect(stateSet.fixtureUserInput)
.to.equal(JSON.stringify({ foo: 'bar' }, null, 2));
expect(stateSet.fixtureUserInput).to.equal(JSON.stringify({
...fixture.state.fixtureContents,
state: {
somethingHappened: true,
},
}, null, 2));
});
});

Expand Down

0 comments on commit 1b98298

Please sign in to comment.