Browse Source

Update test name and fix tests

pull/6351/head
mohamedsalem401 1 year ago
parent
commit
56f6c132d8
  1. 2
      packages/core/src/dom_components/model/Component.ts
  2. 394
      packages/core/test/specs/data_sources/dynamic_values/attributes.ts

2
packages/core/src/dom_components/model/Component.ts

@ -346,7 +346,7 @@ export default class Component extends StyleableModel<ComponentProperties> {
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;

394
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);
});
});

Loading…
Cancel
Save