Skip to content

Commit

Permalink
fix: do not fail when saving a new item using dataProvider (#3533)
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo authored and vaadin-bot committed Mar 10, 2022
1 parent 9434057 commit 69d6441
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/crud/src/vaadin-crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ class Crud extends ElementMixin(ThemableMixin(PolymerElement)) {
this.items.push(item);
}
} else {
this.editedItem = this.editedItem || {};
Object.assign(this.editedItem, item);
}
this._grid.clearCache();
Expand Down
35 changes: 35 additions & 0 deletions packages/crud/test/crud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ describe('crud', () => {
});
});

describe('dataProvider', () => {
const items = [{ foo: 'bar' }];

beforeEach(async () => {
crud = fixtureSync('<vaadin-crud style="width: 300px;"></vaadin-crud>');
crud.dataProvider = (_, callback) => callback(items, items.length);
await nextRender(crud);
[btnSave, btnCancel, btnDelete] = crud.querySelectorAll('vaadin-button');
});

it('should save a new item', (done) => {
listenOnce(crud, 'save', (e) => {
expect(e.detail.item.foo).to.be.equal('baz');
done();
});
crud.$.new.click();
crud._form._fields[0].value = 'baz';
change(crud._form);
btnSave.click();
expect(crud.editedItem.foo).to.be.equal('baz');
});

it('should save an edited item', (done) => {
listenOnce(crud, 'save', (e) => {
expect(e.detail.item.foo).to.be.equal('baz');
done();
});
edit(items[0]);
crud._form._fields[0].value = 'baz';
change(crud._form);
btnSave.click();
expect(crud.editedItem.foo).to.be.equal('baz');
});
});

['default', 'slotted buttons'].forEach((mode) => {
describe(`[${mode}] items`, () => {
beforeEach(async () => {
Expand Down

0 comments on commit 69d6441

Please sign in to comment.