Browse Source

Add getters to ComponentDataVariable

pull/6419/head
mohamedsalem401 2 years ago
parent
commit
c98b78b020
  1. 8
      packages/core/src/data_sources/model/ComponentDataVariable.ts
  2. 71
      packages/core/test/specs/data_sources/model/ComponentDataVariable.getters-setters.ts

8
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();
}

71
packages/core/test/specs/data_sources/model/ComponentDataVariable.setters.ts → 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');
Loading…
Cancel
Save