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

Fix buffer notification on changes discard #53

Merged
merged 2 commits into from
Dec 3, 2019
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
4 changes: 2 additions & 2 deletions addon/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default Mixin.create({
},

discardBufferedChanges(onlyTheseKeys) {
const buffer = get(this, 'buffer');
const { buffer, content } = getProperties(this, ['buffer', 'content']);

this.initializeBuffer(onlyTheseKeys);

Expand All @@ -107,7 +107,7 @@ export default Mixin.create({
return;
}

notifyPropertyChange(this, key);
notifyPropertyChange(content, key);
});

if (empty(get(this, 'buffer'))) {
Expand Down
26 changes: 26 additions & 0 deletions tests/acceptance/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,30 @@ module('Acceptance | application', function(hooks) {
assert.dom('#user-email').hasText('test@dot.com');
assert.dom('#buffer-has-changes').hasText('false');
});

test('verify if buffer is notified about discarding changes', async function(assert) {
await visit('/');

assert.equal(currentURL(), '/');

// Init: Buffer's and content's property value are the same
assert.dom('#buffer-firstname').hasText('stefan');
assert.dom('#buffer-firstname-backward').hasText('nafets');
assert.dom('#user-firstname').hasText('stefan');
assert.dom('#buffer-has-changes').hasText('false');

// Change buffer value: there should be a difference between buffer and content
await fillIn('#firstname-input', 'tomek');
assert.dom('#buffer-firstname').hasText('tomek');
assert.dom('#buffer-firstname-backward').hasText('kemot');
assert.dom('#user-firstname').hasText('stefan');
assert.dom('#buffer-has-changes').hasText('true');

// Discard buffer changes and verify
await click('button#discard-changes');
assert.dom('#buffer-firstname').hasText('stefan');
assert.dom('#buffer-firstname-backward').hasText('nafets');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a fix, the test fails here. A computed property that transforms buffered firstName property to be spelled backward is not notified about the change (on discardBufferedChanges action).

So the last change is still there (kemot).

assert.dom('#user-firstname').hasText('stefan');
assert.dom('#buffer-has-changes').hasText('false');
});
});
6 changes: 6 additions & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import BufferedProxy from 'ember-buffered-proxy/proxy';

export default Controller.extend({

computedOnBuffer: computed('buffer.firstName', function() {
return this.get('buffer.firstName').split('').reverse().join('');
}),

init() {
this._super(...arguments);

Expand Down
2 changes: 2 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<div id="buffer-email">{{buffer.email}}</div>
<div id="user-email">{{user.email}}</div>

<div id="buffer-firstname-backward">{{computedOnBuffer}}</div>

<div id="buffer-has-changes">{{buffer.hasChanges}}</div>

{{input id="firstname-input" value=buffer.firstName onChange=(action (mut buffer.firstName))}}
Expand Down