From c98b78b020470ad55623f2386ee5e56c5d0e858a Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Mon, 24 Feb 2025 19:52:14 +0200 Subject: [PATCH] Add getters to ComponentDataVariable --- .../model/ComponentDataVariable.ts | 8 +++ ... ComponentDataVariable.getters-setters.ts} | 71 +++++++------------ 2 files changed, 34 insertions(+), 45 deletions(-) rename packages/core/test/specs/data_sources/model/{ComponentDataVariable.setters.ts => ComponentDataVariable.getters-setters.ts} (62%) diff --git a/packages/core/src/data_sources/model/ComponentDataVariable.ts b/packages/core/src/data_sources/model/ComponentDataVariable.ts index b5805f7ff..cc870c2a3 100644 --- a/packages/core/src/data_sources/model/ComponentDataVariable.ts +++ b/packages/core/src/data_sources/model/ComponentDataVariable.ts @@ -22,6 +22,14 @@ export default class ComponentDataVariable extends Component { this.dataResolver = new DataVariable({ type, path, defaultValue }, opt); } + getPath() { + return this.dataResolver.get('path'); + } + + getDefaultValue() { + return this.dataResolver.get('defaultValue'); + } + getDataValue() { return this.dataResolver.getDataValue(); } diff --git a/packages/core/test/specs/data_sources/model/ComponentDataVariable.setters.ts b/packages/core/test/specs/data_sources/model/ComponentDataVariable.getters-setters.ts similarity index 62% rename from packages/core/test/specs/data_sources/model/ComponentDataVariable.setters.ts rename to packages/core/test/specs/data_sources/model/ComponentDataVariable.getters-setters.ts index 8e7c7a028..de8cfd768 100644 --- a/packages/core/test/specs/data_sources/model/ComponentDataVariable.setters.ts +++ b/packages/core/test/specs/data_sources/model/ComponentDataVariable.getters-setters.ts @@ -29,81 +29,62 @@ describe('ComponentDataVariable - setPath and setDefaultValue', () => { test('component updates when path is changed using setPath', () => { const cmp = cmpRoot.append({ - tagName: 'div', - type: 'default', - components: [ - { - type: DataVariableType, - defaultValue: 'default', - path: 'ds_id.id1.name', - }, - ], - })[0]; + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id1.name', + })[0] as ComponentDataVariable; expect(cmp.getEl()?.innerHTML).toContain('Name1'); + expect(cmp.getPath()).toBe('ds_id.id1.name'); - (cmp.components().at(0) as ComponentDataVariable).setPath('ds_id.id2.name'); + cmp.setPath('ds_id.id2.name'); expect(cmp.getEl()?.innerHTML).toContain('Name2'); + expect(cmp.getPath()).toBe('ds_id.id2.name'); }); test('component updates when default value is changed using setDefaultValue', () => { const cmp = cmpRoot.append({ - tagName: 'div', - type: 'default', - components: [ - { - type: DataVariableType, - defaultValue: 'default', - path: 'unknown.id1.name', - }, - ], - })[0]; + type: DataVariableType, + defaultValue: 'default', + path: 'unknown.id1.name', + })[0] as ComponentDataVariable; expect(cmp.getEl()?.innerHTML).toContain('default'); + expect(cmp.getDefaultValue()).toBe('default'); - (cmp.components().at(0) as ComponentDataVariable).setDefaultValue('new default'); + cmp.setDefaultValue('new default'); expect(cmp.getEl()?.innerHTML).toContain('new default'); + expect(cmp.getDefaultValue()).toBe('new default'); }); test('component updates correctly after path and default value are changed', () => { const cmp = cmpRoot.append({ - tagName: 'div', - type: 'default', - components: [ - { - type: DataVariableType, - defaultValue: 'default', - path: 'ds_id.id1.name', - }, - ], - })[0]; + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id1.name', + })[0] as ComponentDataVariable; expect(cmp.getEl()?.innerHTML).toContain('Name1'); - (cmp.components().at(0) as ComponentDataVariable).setPath('ds_id.id2.name'); + cmp.setPath('ds_id.id2.name'); expect(cmp.getEl()?.innerHTML).toContain('Name2'); - (cmp.components().at(0) as ComponentDataVariable).setDefaultValue('new default'); + cmp.setDefaultValue('new default'); dsm.all.reset(); expect(cmp.getEl()?.innerHTML).toContain('new default'); + expect(cmp.getDefaultValue()).toBe('new default'); }); test('component updates correctly after path is changed and data is updated', () => { const cmp = cmpRoot.append({ - tagName: 'div', - type: 'default', - components: [ - { - type: DataVariableType, - defaultValue: 'default', - path: 'ds_id.id1.name', - }, - ], - })[0]; + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id1.name', + })[0] as ComponentDataVariable; expect(cmp.getEl()?.innerHTML).toContain('Name1'); - (cmp.components().at(0) as ComponentDataVariable).setPath('ds_id.id2.name'); + cmp.setPath('ds_id.id2.name'); expect(cmp.getEl()?.innerHTML).toContain('Name2'); const ds = dsm.get('ds_id');