Browse Source

Update collection attributes tests

collection-component
mohamedsalem401 2 years ago
parent
commit
5bd74d577b
  1. 171
      packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts

171
packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts

@ -243,35 +243,162 @@ describe('Collection component', () => {
}); });
}); });
test('Attributes', () => { describe('Attributes', () => {
const cmp = wrapper.components({ let cmp: Component;
type: CollectionComponentType, let firstChild!: Component;
collectionDefinition: { let firstGrandchild!: Component;
block: { let secondChild!: Component;
type: 'default', let secondGrandchild!: Component;
attributes: { let thirdChild!: Component;
custom_attribute: {
type: CollectionVariableType, beforeEach(() => {
variable_type: CollectionStateVariableType.current_item, cmp = wrapper.components({
path: 'user', type: CollectionComponentType,
collectionDefinition: {
block: {
type: 'default',
components: [
{
type: 'default',
attributes: {
content: {
type: CollectionVariableType,
variable_type: CollectionStateVariableType.current_item,
path: 'user',
}
},
},
],
attributes: {
content: {
type: CollectionVariableType,
variable_type: CollectionStateVariableType.current_item,
path: 'user',
}
}, },
}, },
}, config: {
config: { dataSource: {
dataSource: { type: DataVariableType,
type: DataVariableType, path: 'my_data_source_id',
path: 'my_data_source_id', },
}, },
}, },
}, })[0];
})[0];
const firstChild = cmp.components().at(0); firstChild = cmp.components().at(0);
const secondChild = cmp.components().at(1); firstGrandchild = firstChild.components().at(0);
secondChild = cmp.components().at(1);
secondGrandchild = secondChild.components().at(0);
thirdChild = cmp.components().at(2);
});
test('Evaluating to static value', () => {
expect(firstChild.getAttributes()['content']).toBe('user1');
expect(firstGrandchild.getAttributes()['content']).toBe('user1');
expect(secondChild.getAttributes()['content']).toBe('user2');
expect(secondGrandchild.getAttributes()['content']).toBe('user2');
});
test('Updating the record', async () => {
firstRecord.set('user', 'new_user1_value');
expect(firstChild.getAttributes()['content']).toBe('new_user1_value');
expect(firstGrandchild.getAttributes()['content']).toBe('new_user1_value');
expect(secondChild.getAttributes()['content']).toBe('user2');
expect(secondGrandchild.getAttributes()['content']).toBe('user2');
});
test('Updating the value to a static value', async () => {
firstChild.setAttributes({ content: 'new_content_value' });
expect(firstChild.getAttributes()['content']).toBe('new_content_value');
expect(secondChild.getAttributes()['content']).toBe('new_content_value');
firstRecord.set('user', 'wrong_value');
expect(firstChild.getAttributes()['content']).toBe('new_content_value');
expect(secondChild.getAttributes()['content']).toBe('new_content_value');
firstGrandchild.setAttributes({ content: 'new_content_value' });
expect(firstGrandchild.getAttributes()['content']).toBe('new_content_value');
expect(secondGrandchild.getAttributes()['content']).toBe('new_content_value');
firstRecord.set('user', 'wrong_value');
expect(firstGrandchild.getAttributes()['content']).toBe('new_content_value');
expect(secondGrandchild.getAttributes()['content']).toBe('new_content_value');
});
test('Updating the value to a diffirent collection variable', async () => {
firstChild.setAttributes({
content: {
// @ts-ignore
type: CollectionVariableType,
variable_type: CollectionStateVariableType.current_item,
path: 'age',
}
});
expect(firstChild.getAttributes()['content']).toBe('12');
expect(secondChild.getAttributes()['content']).toBe('14');
firstRecord.set('age', 'new_value_12');
secondRecord.set('age', 'new_value_14');
firstRecord.set('user', 'wrong_value');
secondRecord.set('user', 'wrong_value');
expect(firstChild.getAttributes()['content']).toBe('new_value_12');
expect(secondChild.getAttributes()['content']).toBe('new_value_14');
firstGrandchild.setAttributes({
content: {
// @ts-ignore
type: CollectionVariableType,
variable_type: CollectionStateVariableType.current_item,
path: 'age',
}
});
expect(firstGrandchild.getAttributes()['content']).toBe('new_value_12');
expect(secondGrandchild.getAttributes()['content']).toBe('new_value_14');
firstRecord.set('age', 'most_new_value_12');
secondRecord.set('age', 'most_new_value_14');
expect(firstGrandchild.getAttributes()['content']).toBe('most_new_value_12');
expect(secondGrandchild.getAttributes()['content']).toBe('most_new_value_14');
});
test('Updating the value to a diffirent dynamic variable', async () => {
firstChild.setAttributes({
content: {
// @ts-ignore
type: DataVariableType,
path: 'my_data_source_id.user2.user',
}
});
expect(firstChild.getAttributes()['content']).toBe('user2');
expect(secondChild.getAttributes()['content']).toBe('user2');
expect(thirdChild.getAttributes()['content']).toBe('user2');
secondRecord.set('user', 'new_value');
expect(firstChild.getAttributes()['content']).toBe('new_value');
expect(secondChild.getAttributes()['content']).toBe('new_value');
expect(thirdChild.getAttributes()['content']).toBe('new_value');
firstGrandchild.setAttributes({
content: {
// @ts-ignore
type: DataVariableType,
path: 'my_data_source_id.user2.user',
}
});
expect(firstGrandchild.getAttributes()['content']).toBe('new_value');
expect(secondGrandchild.getAttributes()['content']).toBe('new_value');
expect(firstChild.getAttributes()['custom_attribute']).toBe('user1'); secondRecord.set('user', 'most_new_value');
expect(secondChild.getAttributes()['custom_attribute']).toBe('user2'); expect(firstGrandchild.getAttributes()['content']).toBe('most_new_value');
expect(secondGrandchild.getAttributes()['content']).toBe('most_new_value');
});
}); });
test('Traits', () => { test('Traits', () => {

Loading…
Cancel
Save