Skip to content

Commit

Permalink
Merge pull request #14 from vueda/update-data-strategy
Browse files Browse the repository at this point in the history
feat: UPDATE strategy for data update
  • Loading branch information
angeliski authored Aug 8, 2019
2 parents 87ed834 + cce0f15 commit 656f082
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/TabulatorComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default class TabulatorComponent extends Vue {
if (this.tabulatorInstance) {
if (this.integration && this.integration.updateStrategy === UpdateStrategy.REPLACE) {
this.tabulatorInstance.replaceData(this.tableData);
} else if (this.integration && this.tableData
&& this.integration.updateStrategy === UpdateStrategy.UPDATE) {
this.tabulatorInstance.updateData(this.tableData);
} else {
this.tabulatorInstance.setData(this.tableData);
}
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable import/prefer-default-export */
export enum UpdateStrategy {
DATA = 'DATA',
REPLACE= 'REPLACE'
REPLACE = 'REPLACE',
UPDATE = 'UPDATE'
}

export interface IntegrationOptions {
Expand Down
25 changes: 24 additions & 1 deletion tests/unit/TabulatorComponent-IntegrationModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { UpdateStrategy } from '@/types';

const mockSetData = jest.fn();
const mockReplaceData = jest.fn();
const mockUpdateData = jest.fn();

jest.mock('tabulator-tables', () => jest.fn().mockImplementation(() => ({
setData: mockSetData,
replaceData: mockReplaceData,
updateData: mockUpdateData,
})));
const Tabulator = require('tabulator-tables');


const options : Tabulator.Options = {
columns: [
{
Expand All @@ -29,6 +31,7 @@ describe('TabulatorComponent.vue | Integration Module', () => {
Tabulator.mockClear();
mockSetData.mockClear();
mockReplaceData.mockClear();
mockUpdateData.mockClear();
});

describe('Watchers', () => {
Expand Down Expand Up @@ -66,5 +69,25 @@ describe('TabulatorComponent.vue | Integration Module', () => {
expect(mockSetData).not.toHaveBeenCalled();
expect(mockReplaceData).toHaveBeenCalled();
});

test('update de v-model should use UpdateStrategy.UPDATE', () => {
const wrapper = mount(TabulatorComponent, {
propsData: {
tableData: [{ id: 1, name: 'Someone to update' }],
options,
integration: {
updateStrategy: UpdateStrategy.UPDATE,
},
},
});

wrapper.setProps({
tableData: [{ id: 1, name: 'Someone updated' }],
});

expect(mockSetData).not.toHaveBeenCalled();
expect(mockReplaceData).not.toHaveBeenCalled();
expect(mockUpdateData).toHaveBeenCalled();
});
});
});

0 comments on commit 656f082

Please sign in to comment.