|
|
@ -1,5 +1,5 @@ |
|
|
import { isSymbol } from 'underscore'; |
|
|
import { isSymbol } from 'underscore'; |
|
|
import { Component, DataSource, DataSourceManager } from '../../../../../src'; |
|
|
import { Component, DataRecord, DataSource, DataSourceManager } from '../../../../../src'; |
|
|
import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; |
|
|
import { DataVariableType } from '../../../../../src/data_sources/model/DataVariable'; |
|
|
import { |
|
|
import { |
|
|
CollectionComponentType, |
|
|
CollectionComponentType, |
|
|
@ -16,6 +16,8 @@ describe('Collection component', () => { |
|
|
let dsm: DataSourceManager; |
|
|
let dsm: DataSourceManager; |
|
|
let dataSource: DataSource; |
|
|
let dataSource: DataSource; |
|
|
let wrapper: Component; |
|
|
let wrapper: Component; |
|
|
|
|
|
let firstRecord: DataRecord; |
|
|
|
|
|
let secondRecord: DataRecord; |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
({ em, dsm } = setupTestEditor()); |
|
|
({ em, dsm } = setupTestEditor()); |
|
|
@ -28,6 +30,9 @@ describe('Collection component', () => { |
|
|
{ id: 'user3', user: 'user3', age: '16' }, |
|
|
{ id: 'user3', user: 'user3', age: '16' }, |
|
|
], |
|
|
], |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
firstRecord = dataSource.getRecord('user1')!; |
|
|
|
|
|
secondRecord = dataSource.getRecord('user2')!; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
afterEach(() => { |
|
|
afterEach(() => { |
|
|
@ -85,39 +90,57 @@ describe('Collection component', () => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
describe('Collection variables', () => { |
|
|
describe('Collection variables', () => { |
|
|
test('Properties', () => { |
|
|
describe('Properties', () => { |
|
|
const cmp = wrapper.components({ |
|
|
let cmp: Component; |
|
|
type: CollectionComponentType, |
|
|
let firstChild!: Component; |
|
|
collectionDefinition: { |
|
|
let secondChild!: Component; |
|
|
block: { |
|
|
|
|
|
type: 'default', |
|
|
beforeEach(() => { |
|
|
content: { |
|
|
cmp = wrapper.components({ |
|
|
type: CollectionVariableType, |
|
|
type: CollectionComponentType, |
|
|
variable_type: CollectionStateVariableType.current_item, |
|
|
collectionDefinition: { |
|
|
path: 'user', |
|
|
block: { |
|
|
}, |
|
|
type: 'default', |
|
|
custom_property: { |
|
|
content: { |
|
|
type: CollectionVariableType, |
|
|
type: CollectionVariableType, |
|
|
variable_type: CollectionStateVariableType.current_item, |
|
|
variable_type: CollectionStateVariableType.current_item, |
|
|
path: 'user', |
|
|
path: 'user', |
|
|
|
|
|
}, |
|
|
|
|
|
custom_property: { |
|
|
|
|
|
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); |
|
|
secondChild = cmp.components().at(1); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('Evaluating to static value', () => { |
|
|
|
|
|
expect(firstChild.get('content')).toBe('user1'); |
|
|
|
|
|
expect(firstChild.get('custom_property')).toBe('user1'); |
|
|
|
|
|
|
|
|
|
|
|
expect(secondChild.get('content')).toBe('user2'); |
|
|
|
|
|
expect(secondChild.get('custom_property')).toBe('user2'); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
expect(firstChild.get('content')).toBe('user1'); |
|
|
test('Updating the record', async () => { |
|
|
expect(firstChild.get('custom_property')).toBe('user1'); |
|
|
firstRecord.set('user', 'new_user1_value'); |
|
|
|
|
|
expect(firstChild.get('content')).toBe('new_user1_value'); |
|
|
|
|
|
expect(firstChild.get('custom_property')).toBe('new_user1_value'); |
|
|
|
|
|
|
|
|
expect(secondChild.get('content')).toBe('user2'); |
|
|
expect(secondChild.get('content')).toBe('user2'); |
|
|
expect(secondChild.get('custom_property')).toBe('user2'); |
|
|
expect(secondChild.get('custom_property')).toBe('user2'); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
test('Attributes', () => { |
|
|
test('Attributes', () => { |
|
|
@ -332,3 +355,7 @@ describe('Collection component', () => { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function delay(ms: number): Promise<void> { |
|
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms)); |
|
|
|
|
|
} |
|
|
|