Skip to content

Commit

Permalink
Update attributes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Dec 27, 2024
1 parent 9530442 commit e40b3f2
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions packages/core/test/specs/data_sources/dynamic_values/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Dynamic Attributes', () => {
testAttribute(cmp, 'dynamicAttribute', 'test-value');
testStaticAttributes(cmp);

changeDataSourceValue(dsm);
changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'changed-value');
});

Expand All @@ -78,7 +78,7 @@ describe('Dynamic Attributes', () => {
id: 'ds_id',
records: [
{ id: 'id1', value: 'test-value' },
{ id: 'id2', value: 'test-value2' },
{ id: 'id2', value: 'second-test-value' },
],
};
dsm.add(dataSource);
Expand All @@ -96,23 +96,29 @@ describe('Dynamic Attributes', () => {
attributes,
})[0];

cmp.setAttributes({ dynamicAttribute: 'some-static-value' });
testAttribute(cmp, 'dynamicAttribute', 'some-static-value');

cmp.setAttributes({
dynamicAttribute: {
type: DataVariableType,
defaultValue: 'default',
path: 'ds_id.id2.value',
},
});
changeDataSourceValue(dsm);
testAttribute(cmp, 'dynamicAttribute', 'test-value2');
changeDataSourceValue(dsm, 'id1');
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', () => {
const dataSource = {
id: 'ds_id',
records: [
{ id: 'id1', value: 'test-value' },
{ id: 'id2', value: 'test-value2' },
{ id: 'id2', value: 'second-test-value' },
],
};
dsm.add(dataSource);
Expand All @@ -130,15 +136,21 @@ describe('Dynamic Attributes', () => {
attributes,
})[0];

cmp.addAttributes({ dynamicAttribute: 'some-static-value' });
testAttribute(cmp, 'dynamicAttribute', 'some-static-value');

cmp.addAttributes({
dynamicAttribute: {
type: DataVariableType,
defaultValue: 'default',
path: 'ds_id.id2.value',
},
});
changeDataSourceValue(dsm);
testAttribute(cmp, 'dynamicAttribute', 'test-value2');
changeDataSourceValue(dsm, 'id1');
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', () => {
Expand Down Expand Up @@ -167,11 +179,11 @@ describe('Dynamic Attributes', () => {
cmp.setAttributes({
dynamicAttribute: 'static-value',
});
changeDataSourceValue(dsm);
changeDataSourceValue(dsm, 'id1');
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 = {
id: 'ds_id',
records: [{ id: 'id1', value: 'test-value' }],
Expand All @@ -195,7 +207,7 @@ describe('Dynamic Attributes', () => {
},
});
testAttribute(cmp, 'dynamicAttribute', 'test-value');
changeDataSourceValue(dsm);
changeDataSourceValue(dsm, 'id1');
testAttribute(cmp, 'dynamicAttribute', 'changed-value');
});

Expand Down Expand Up @@ -223,15 +235,17 @@ describe('Dynamic Attributes', () => {
testStaticAttributes(cmp);

cmp.removeAttributes('dynamicAttribute');
changeDataSourceValue(dsm);
changeDataSourceValue(dsm, 'id1');
expect(cmp?.getAttributes()['dynamicAttribute']).toBe(undefined);
const input = cmp.getEl();
expect(input?.getAttribute('dynamicAttribute')).toBe(null);
});
});

function changeDataSourceValue(dsm: DataSourceManager) {
dsm.get('ds_id').getRecord('id1')?.set('value', 'changed-value');
function changeDataSourceValue(dsm: DataSourceManager, id: string) {
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) {
Expand Down

0 comments on commit e40b3f2

Please sign in to comment.