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

feat: UPDATE strategy for data update #14

Merged
merged 1 commit into from
Aug 8, 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
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();
});
});
});