Browse Source

Update attributes tests

pull/6351/head
mohamedsalem401 1 year ago
parent
commit
e40b3f2a3b
  1. 40
      packages/core/test/specs/data_sources/dynamic_values/attributes.ts

40
packages/core/test/specs/data_sources/dynamic_values/attributes.ts

@ -69,7 +69,7 @@ describe('Dynamic Attributes', () => {
testAttribute(cmp, 'dynamicAttribute', 'test-value'); testAttribute(cmp, 'dynamicAttribute', 'test-value');
testStaticAttributes(cmp); testStaticAttributes(cmp);
changeDataSourceValue(dsm); changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'changed-value'); testAttribute(cmp, 'dynamicAttribute', 'changed-value');
}); });
@ -78,7 +78,7 @@ describe('Dynamic Attributes', () => {
id: 'ds_id', id: 'ds_id',
records: [ records: [
{ id: 'id1', value: 'test-value' }, { id: 'id1', value: 'test-value' },
{ id: 'id2', value: 'test-value2' }, { id: 'id2', value: 'second-test-value' },
], ],
}; };
dsm.add(dataSource); dsm.add(dataSource);
@ -96,6 +96,9 @@ describe('Dynamic Attributes', () => {
attributes, attributes,
})[0]; })[0];
cmp.setAttributes({ dynamicAttribute: 'some-static-value' });
testAttribute(cmp, 'dynamicAttribute', 'some-static-value');
cmp.setAttributes({ cmp.setAttributes({
dynamicAttribute: { dynamicAttribute: {
type: DataVariableType, type: DataVariableType,
@ -103,8 +106,11 @@ describe('Dynamic Attributes', () => {
path: 'ds_id.id2.value', path: 'ds_id.id2.value',
}, },
}); });
changeDataSourceValue(dsm); changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'test-value2'); testAttribute(cmp, 'dynamicAttribute', 'second-test-value');
changeDataSourceValue(dsm, 'id2');
testAttribute(cmp, 'dynamicAttribute', 'changed-value');
}); });
test('(Component.addAttributes) dynamic attributes should listen to the latest dynamic value', () => { test('(Component.addAttributes) dynamic attributes should listen to the latest dynamic value', () => {
@ -112,7 +118,7 @@ describe('Dynamic Attributes', () => {
id: 'ds_id', id: 'ds_id',
records: [ records: [
{ id: 'id1', value: 'test-value' }, { id: 'id1', value: 'test-value' },
{ id: 'id2', value: 'test-value2' }, { id: 'id2', value: 'second-test-value' },
], ],
}; };
dsm.add(dataSource); dsm.add(dataSource);
@ -130,6 +136,9 @@ describe('Dynamic Attributes', () => {
attributes, attributes,
})[0]; })[0];
cmp.addAttributes({ dynamicAttribute: 'some-static-value' });
testAttribute(cmp, 'dynamicAttribute', 'some-static-value');
cmp.addAttributes({ cmp.addAttributes({
dynamicAttribute: { dynamicAttribute: {
type: DataVariableType, type: DataVariableType,
@ -137,8 +146,11 @@ describe('Dynamic Attributes', () => {
path: 'ds_id.id2.value', path: 'ds_id.id2.value',
}, },
}); });
changeDataSourceValue(dsm); changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'test-value2'); testAttribute(cmp, 'dynamicAttribute', 'second-test-value');
changeDataSourceValue(dsm, 'id2');
testAttribute(cmp, 'dynamicAttribute', 'changed-value');
}); });
test('dynamic attributes should stop listening to change if the value changed to static', () => { test('dynamic attributes should stop listening to change if the value changed to static', () => {
@ -167,11 +179,11 @@ describe('Dynamic Attributes', () => {
cmp.setAttributes({ cmp.setAttributes({
dynamicAttribute: 'static-value', dynamicAttribute: 'static-value',
}); });
changeDataSourceValue(dsm); changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'static-value'); testAttribute(cmp, 'dynamicAttribute', 'static-value');
}); });
test('dynamic attributes should stop listening to change if the value changed to dynamic value', () => { test('dynamic attributes should start listening to change if the value changed to dynamic value', () => {
const dataSource = { const dataSource = {
id: 'ds_id', id: 'ds_id',
records: [{ id: 'id1', value: 'test-value' }], records: [{ id: 'id1', value: 'test-value' }],
@ -195,7 +207,7 @@ describe('Dynamic Attributes', () => {
}, },
}); });
testAttribute(cmp, 'dynamicAttribute', 'test-value'); testAttribute(cmp, 'dynamicAttribute', 'test-value');
changeDataSourceValue(dsm); changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'changed-value'); testAttribute(cmp, 'dynamicAttribute', 'changed-value');
}); });
@ -223,15 +235,17 @@ describe('Dynamic Attributes', () => {
testStaticAttributes(cmp); testStaticAttributes(cmp);
cmp.removeAttributes('dynamicAttribute'); cmp.removeAttributes('dynamicAttribute');
changeDataSourceValue(dsm); changeDataSourceValue(dsm, 'id1');
expect(cmp?.getAttributes()['dynamicAttribute']).toBe(undefined); expect(cmp?.getAttributes()['dynamicAttribute']).toBe(undefined);
const input = cmp.getEl(); const input = cmp.getEl();
expect(input?.getAttribute('dynamicAttribute')).toBe(null); expect(input?.getAttribute('dynamicAttribute')).toBe(null);
}); });
}); });
function changeDataSourceValue(dsm: DataSourceManager) { function changeDataSourceValue(dsm: DataSourceManager, id: string) {
dsm.get('ds_id').getRecord('id1')?.set('value', 'changed-value'); dsm.get('ds_id').getRecord(id)?.set('value', 'intermediate-value1');
dsm.get('ds_id').getRecord(id)?.set('value', 'intermediate-value2');
dsm.get('ds_id').getRecord(id)?.set('value', 'changed-value');
} }
function testStaticAttributes(cmp: Component) { function testStaticAttributes(cmp: Component) {

Loading…
Cancel
Save