From 56f6c132d86ffa5d36758f800f011f2ec07c6f89 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Thu, 26 Dec 2024 07:51:26 +0200 Subject: [PATCH] Update test name and fix tests --- .../src/dom_components/model/Component.ts | 2 +- .../data_sources/dynamic_values/attributes.ts | 394 +++++++++--------- 2 files changed, 197 insertions(+), 199 deletions(-) diff --git a/packages/core/src/dom_components/model/Component.ts b/packages/core/src/dom_components/model/Component.ts index feceea313..4d73cf581 100644 --- a/packages/core/src/dom_components/model/Component.ts +++ b/packages/core/src/dom_components/model/Component.ts @@ -346,7 +346,7 @@ export default class Component extends StyleableModel { let options: ComponentSetOptions = { skipWatcherUpdates: false }; if (typeof keyOrAttributes === 'object') { attributes = keyOrAttributes; - options = valueOrOptions as ComponentSetOptions; + options = valueOrOptions || options as ComponentSetOptions; } else if (typeof keyOrAttributes === 'string') { attributes = { [keyOrAttributes as string]: valueOrOptions }; options = optionsOrUndefined || options; 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 bd36359b1..d150079f5 100644 --- a/packages/core/test/specs/data_sources/dynamic_values/attributes.ts +++ b/packages/core/test/specs/data_sources/dynamic_values/attributes.ts @@ -6,7 +6,7 @@ import { setupTestEditor } from '../../../common'; import { Component } from '../../../../src'; const staticAttributeValue = 'some tiltle'; -describe('TraitDataVariable', () => { +describe('Dynamic Attributes', () => { let em: Editor; let dsm: DataSourceManager; let cmpRoot: ComponentWrapper; @@ -22,213 +22,211 @@ describe('TraitDataVariable', () => { em.destroy(); }); - describe('dynamic attributes', () => { - test('static and dynamic attributes', () => { - const inputDataSource = { - id: 'ds_id', - records: [{ id: 'id1', value: 'test-value' }], - }; - dsm.add(inputDataSource); - - const attributes = { - ...staticAttributes, - dynamicAttribute: { - type: DataVariableType, - defaultValue: 'default', - path: 'ds_id.id1.value', - }, - }; - const cmp = cmpRoot.append({ - tagName: 'input', - attributes, - })[0]; - - testAttribute(cmp, 'dynamicAttribute', 'test-value'); - testStaticAttributes(cmp); - }); + test('static and dynamic attributes', () => { + const inputDataSource = { + id: 'ds_id', + records: [{ id: 'id1', value: 'test-value' }], + }; + dsm.add(inputDataSource); + + const attributes = { + ...staticAttributes, + dynamicAttribute: { + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id1.value', + }, + }; + const cmp = cmpRoot.append({ + tagName: 'input', + attributes, + })[0]; + + testAttribute(cmp, 'dynamicAttribute', 'test-value'); + testStaticAttributes(cmp); + }); - test('dynamic attributes should listen to change', () => { - const dataSource = { - id: 'ds_id', - records: [{ id: 'id1', 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]; - - testAttribute(cmp, 'dynamicAttribute', 'test-value'); - testStaticAttributes(cmp); - - changeDataSourceValue(dsm); - testAttribute(cmp, 'dynamicAttribute', 'changed-value'); - }); + test('dynamic attributes should listen to change', () => { + const dataSource = { + id: 'ds_id', + records: [{ id: 'id1', 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]; + + testAttribute(cmp, 'dynamicAttribute', 'test-value'); + testStaticAttributes(cmp); + + changeDataSourceValue(dsm); + testAttribute(cmp, 'dynamicAttribute', 'changed-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-value2' }, - ], - }; - 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-value2'); + 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-value2' }, + ], + }; + 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-value2'); + }); - 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' }, - ], - }; - 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.addAttributes({ - dynamicAttribute: { - type: DataVariableType, - defaultValue: 'default', - path: 'ds_id.id2.value', - }, - }); - changeDataSourceValue(dsm); - testAttribute(cmp, 'dynamicAttribute', 'test-value2'); + 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' }, + ], + }; + 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.addAttributes({ + dynamicAttribute: { + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id2.value', + }, }); + changeDataSourceValue(dsm); + testAttribute(cmp, 'dynamicAttribute', 'test-value2'); + }); - test('dynamic attributes should stop listening to change if the value changed to static', () => { - const dataSource = { - id: 'ds_id', - records: [{ id: 'id1', 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]; - - testAttribute(cmp, 'dynamicAttribute', 'test-value'); - testStaticAttributes(cmp); - - cmp.setAttributes({ - dynamicAttribute: 'static-value', - }); - changeDataSourceValue(dsm); - testAttribute(cmp, 'dynamicAttribute', 'static-value'); + test('dynamic attributes should stop listening to change if the value changed to static', () => { + const dataSource = { + id: 'ds_id', + records: [{ id: 'id1', 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]; + + testAttribute(cmp, 'dynamicAttribute', 'test-value'); + testStaticAttributes(cmp); + + cmp.setAttributes({ + dynamicAttribute: 'static-value', }); + changeDataSourceValue(dsm); + testAttribute(cmp, 'dynamicAttribute', 'static-value'); + }); - test('dynamic attributes should stop listening to change if the value changed to dynamic value', () => { - const dataSource = { - id: 'ds_id', - records: [{ id: 'id1', value: 'test-value' }], - }; - dsm.add(dataSource); - - const attributes = { - ...staticAttributes, - dynamicAttribute: 'static-value', - }; - const cmp = cmpRoot.append({ - tagName: 'input', - attributes, - })[0]; - - cmp.setAttributes({ - dynamicAttribute: { - type: DataVariableType, - defaultValue: 'default', - path: 'ds_id.id1.value', - }, - }); - testAttribute(cmp, 'dynamicAttribute', 'test-value'); - changeDataSourceValue(dsm); - testAttribute(cmp, 'dynamicAttribute', 'changed-value'); + test('dynamic attributes should stop listening to change if the value changed to dynamic value', () => { + const dataSource = { + id: 'ds_id', + records: [{ id: 'id1', value: 'test-value' }], + }; + dsm.add(dataSource); + + const attributes = { + ...staticAttributes, + dynamicAttribute: 'static-value', + }; + const cmp = cmpRoot.append({ + tagName: 'input', + attributes, + })[0]; + + cmp.setAttributes({ + dynamicAttribute: { + type: DataVariableType, + defaultValue: 'default', + path: 'ds_id.id1.value', + }, }); + testAttribute(cmp, 'dynamicAttribute', 'test-value'); + changeDataSourceValue(dsm); + testAttribute(cmp, 'dynamicAttribute', 'changed-value'); + }); - test('dynamic attributes should stop listening to change if the attribute was removed', () => { - const dataSource = { - id: 'ds_id', - records: [{ id: 'id1', 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]; - - testAttribute(cmp, 'dynamicAttribute', 'test-value'); - testStaticAttributes(cmp); - - cmp.removeAttributes('dynamicAttribute'); - changeDataSourceValue(dsm); - expect(cmp?.getAttributes()['dynamicAttribute']).toBe(undefined); - const input = cmp.getEl(); - expect(input?.getAttribute('dynamicAttribute')).toBe(null); - }); + test('dynamic attributes should stop listening to change if the attribute was removed', () => { + const dataSource = { + id: 'ds_id', + records: [{ id: 'id1', 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]; + + testAttribute(cmp, 'dynamicAttribute', 'test-value'); + testStaticAttributes(cmp); + + cmp.removeAttributes('dynamicAttribute'); + changeDataSourceValue(dsm); + expect(cmp?.getAttributes()['dynamicAttribute']).toBe(undefined); + const input = cmp.getEl(); + expect(input?.getAttribute('dynamicAttribute')).toBe(null); }); });