From f00e14cf661411160407821d39d1cf6009a1e854 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Wed, 11 Dec 2024 03:45:44 +0200 Subject: [PATCH] Add unit test for addAttribute and setAttributes --- .../data_sources/dynamic_values/attributes.ts | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/core/test/specs/data_sources/dynamic_values/attributes.ts b/packages/core/test/specs/data_sources/dynamic_values/attributes.ts index 407e5533c..94bfadd57 100644 --- a/packages/core/test/specs/data_sources/dynamic_values/attributes.ts +++ b/packages/core/test/specs/data_sources/dynamic_values/attributes.ts @@ -74,8 +74,41 @@ describe('TraitDataVariable', () => { testAttribute(cmp, 'dynamicAttribute', 'changed-value'); }); - // TODO: Decide what to do about watching traits - test.skip('dynamic attributes should listen to the latest dynamic value', () => { + test('(Component.setAttributes) dynamic attributes should listen to the latest dynamic value', () => { + const dataSource = { + id: 'ds_id', + records: [ + { id: 'id1', value: 'test-value' }, + { id: 'id2', value: 'test-value' }, + ], + }; + dsm.add(dataSource); + + const attributes = { + ...staticAttributes, + dynamicAttribute: { + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id1.value', + }, + }; + const cmp = cmpRoot.append({ + tagName: 'input', + attributes, + })[0]; + + cmp.setAttributes({ + dynamicAttribute: { + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id2.value', + }, + }); + changeDataSourceValue(dsm); + testAttribute(cmp, 'dynamicAttribute', 'test-value'); + }); + + test('(Component.addAttributes) dynamic attributes should listen to the latest dynamic value', () => { const dataSource = { id: 'ds_id', records: [