|
|
|
@ -3,6 +3,7 @@ import { DataVariableType } from '../../../../../src/data_sources/model/DataVari |
|
|
|
import { |
|
|
|
DataCollectionType, |
|
|
|
DataCollectionVariableType, |
|
|
|
|
|
|
|
} from '../../../../../src/data_sources/model/data_collection/constants'; |
|
|
|
import { DataCollectionStateVariableType } from '../../../../../src/data_sources/model/data_collection/types'; |
|
|
|
import EditorModel from '../../../../../src/editor/model/Editor'; |
|
|
|
@ -27,6 +28,7 @@ describe('Collection component getters and setters', () => { |
|
|
|
{ id: 'user1', user: 'user1', firstName: 'Name1', age: '12' }, |
|
|
|
{ id: 'user2', user: 'user2', firstName: 'Name2', age: '14' }, |
|
|
|
{ id: 'user3', user: 'user3', firstName: 'Name3', age: '16' }, |
|
|
|
|
|
|
|
], |
|
|
|
}); |
|
|
|
|
|
|
|
@ -52,14 +54,16 @@ describe('Collection component getters and setters', () => { |
|
|
|
type: 'default', |
|
|
|
tagName: 'div', |
|
|
|
attributes: { |
|
|
|
'data-user': { |
|
|
|
dataUser: { |
|
|
|
type: DataCollectionVariableType, |
|
|
|
variableType: DataCollectionStateVariableType.currentItem, |
|
|
|
collectionId: 'my_collection', |
|
|
|
path: 'user', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
}, |
|
|
|
collectionConfig: { |
|
|
|
@ -69,6 +73,7 @@ describe('Collection component getters and setters', () => { |
|
|
|
dataSource: { |
|
|
|
type: DataVariableType, |
|
|
|
path: 'my_data_source_id', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
@ -77,25 +82,29 @@ describe('Collection component getters and setters', () => { |
|
|
|
|
|
|
|
test('getItemsCount should return the correct number of items', () => { |
|
|
|
expect(cmp.getItemsCount()).toBe(2); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('getConfigStartIndex should return the correct start index', () => { |
|
|
|
expect(cmp.getConfigStartIndex()).toBe(1); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('getConfigEndIndex should return the correct end index', () => { |
|
|
|
expect(cmp.getConfigEndIndex()).toBe(2); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('getComponentDef should return the correct component definition', () => { |
|
|
|
const componentDef = cmp.getComponentDef(); |
|
|
|
expect(componentDef.type).toBe('default'); |
|
|
|
expect(componentDef.components).toHaveLength(1); |
|
|
|
expect(componentDef.attributes?.['data-user']).toEqual({ |
|
|
|
expect(componentDef.attributes?.['dataUser']).toEqual({ |
|
|
|
type: DataCollectionVariableType, |
|
|
|
variableType: DataCollectionStateVariableType.currentItem, |
|
|
|
collectionId: 'my_collection', |
|
|
|
path: 'user', |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -104,11 +113,13 @@ describe('Collection component getters and setters', () => { |
|
|
|
expect(ds).toEqual({ |
|
|
|
type: DataVariableType, |
|
|
|
path: 'my_data_source_id', |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('getCollectionId should return the correct collection ID', () => { |
|
|
|
expect(cmp.getCollectionId()).toBe('my_collection'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('getItemsCount should return 0 when no records are present', () => { |
|
|
|
@ -116,25 +127,28 @@ describe('Collection component getters and setters', () => { |
|
|
|
dataSource.removeRecord('user2'); |
|
|
|
dataSource.removeRecord('user3'); |
|
|
|
expect(cmp.getItemsCount()).toBe(0); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('getConfigStartIndex should handle zero as a valid start index', () => { |
|
|
|
cmp.setStartIndex(0); |
|
|
|
|
|
|
|
expect(cmp.getConfigStartIndex()).toBe(0); |
|
|
|
expect(cmp.getItemsCount()).toBe(3); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('getConfigEndIndex should handle zero as a valid end index', () => { |
|
|
|
cmp.setEndIndex(0); |
|
|
|
expect(cmp.getConfigStartIndex()).toBe(1); |
|
|
|
expect(cmp.getConfigEndIndex()).toBe(0); |
|
|
|
expect(cmp.getItemsCount()).toBe(0); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Setters', () => { |
|
|
|
let cmp: ComponentDataCollection; |
|
|
|
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
cmp = wrapper.components({ |
|
|
|
type: DataCollectionType, |
|
|
|
@ -146,14 +160,16 @@ describe('Collection component getters and setters', () => { |
|
|
|
type: 'default', |
|
|
|
tagName: 'div', |
|
|
|
attributes: { |
|
|
|
'data-user': { |
|
|
|
dataUser: { |
|
|
|
type: DataCollectionVariableType, |
|
|
|
variableType: DataCollectionStateVariableType.currentItem, |
|
|
|
collectionId: 'my_collection', |
|
|
|
path: 'user', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
}, |
|
|
|
collectionConfig: { |
|
|
|
@ -163,6 +179,7 @@ describe('Collection component getters and setters', () => { |
|
|
|
dataSource: { |
|
|
|
type: DataVariableType, |
|
|
|
path: 'my_data_source_id', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
@ -182,13 +199,14 @@ describe('Collection component getters and setters', () => { |
|
|
|
variableType: DataCollectionStateVariableType.currentItem, |
|
|
|
collectionId: 'my_collection', |
|
|
|
path: 'firstName', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
}; |
|
|
|
cmp.setComponentDef(newComponentDef); |
|
|
|
|
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(2); |
|
|
|
expect(children.at(0).get('type')).toBe('newType'); |
|
|
|
@ -199,72 +217,72 @@ describe('Collection component getters and setters', () => { |
|
|
|
test('setStartIndex should update the start index and reflect in children', () => { |
|
|
|
cmp.setStartIndex(0); |
|
|
|
expect(cmp.getConfigStartIndex()).toBe(0); |
|
|
|
|
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(3); |
|
|
|
expect(children.at(0).getAttributes()['data-user']).toBe('user1'); |
|
|
|
expect(children.at(1).getAttributes()['data-user']).toBe('user2'); |
|
|
|
expect(children.at(2).getAttributes()['data-user']).toBe('user3'); |
|
|
|
expect(children.at(0).components().at(0).getAttributes()['dataUser']).toBe('user1'); |
|
|
|
expect(children.at(1).components().at(0).getAttributes()['dataUser']).toBe('user2'); |
|
|
|
expect(children.at(2).components().at(0).getAttributes()['dataUser']).toBe('user3'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('setEndIndex should update the end index and reflect in children', () => { |
|
|
|
cmp.setEndIndex(3); |
|
|
|
expect(cmp.getConfigEndIndex()).toBe(3); |
|
|
|
|
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(2); |
|
|
|
expect(children.at(0).getAttributes()['data-user']).toBe('user2'); |
|
|
|
expect(children.at(1).getAttributes()['data-user']).toBe('user3'); |
|
|
|
expect(children.at(0).components().at(0).getAttributes()['dataUser']).toBe('user2'); |
|
|
|
expect(children.at(1).components().at(0).getAttributes()['dataUser']).toBe('user3'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('setDataSource should update the data source and reflect in children', () => { |
|
|
|
dsm.add({ |
|
|
|
id: 'new_data_source_id', |
|
|
|
records: [ |
|
|
|
{ id: 'user4', user: 'user4', firstName: 'Name4', age: '20' }, |
|
|
|
], |
|
|
|
records: [{ id: 'user4', user: 'user4', firstName: 'Name4', age: '20' }], |
|
|
|
}); |
|
|
|
cmp.setDataSource({ |
|
|
|
type: DataVariableType, |
|
|
|
path: 'new_data_source_id', |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(1); // Only one record in the new data source
|
|
|
|
expect(children.at(0).getAttributes()['data-user']).toBe('user4'); |
|
|
|
expect(children).toHaveLength(1); |
|
|
|
expect(children.at(0).components().at(0).getAttributes()['dataUser']).toBe('user4'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('setStartIndex with zero should include the first record', () => { |
|
|
|
cmp.setStartIndex(0); |
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(3); // Includes all records
|
|
|
|
expect(children.at(0).getAttributes()['data-user']).toBe('user1'); |
|
|
|
expect(children).toHaveLength(3); |
|
|
|
expect(children.at(0).components().at(0).getAttributes()['dataUser']).toBe('user1'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('setEndIndex with zero should result in no children', () => { |
|
|
|
cmp.setEndIndex(0); |
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(0); // No records included
|
|
|
|
expect(children).toHaveLength(0); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('setDataSource with an empty data source should result in no children', () => { |
|
|
|
const emptyDataSource = dsm.add({ |
|
|
|
dsm.add({ |
|
|
|
id: 'empty_data_source_id', |
|
|
|
records: [], |
|
|
|
|
|
|
|
}); |
|
|
|
cmp.setDataSource({ |
|
|
|
type: DataVariableType, |
|
|
|
path: 'empty_data_source_id', |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
const children = cmp.components(); |
|
|
|
expect(children).toHaveLength(0); // No records in the data source
|
|
|
|
expect(children).toHaveLength(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('Impact on HTML output', () => { |
|
|
|
let cmp: ComponentDataCollection; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
cmp = wrapper.components({ |
|
|
|
type: DataCollectionType, |
|
|
|
@ -276,14 +294,16 @@ describe('Collection component getters and setters', () => { |
|
|
|
type: 'default', |
|
|
|
tagName: 'div', |
|
|
|
attributes: { |
|
|
|
'data-user': { |
|
|
|
dataUser: { |
|
|
|
type: DataCollectionVariableType, |
|
|
|
variableType: DataCollectionStateVariableType.currentItem, |
|
|
|
collectionId: 'my_collection', |
|
|
|
path: 'user', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
}, |
|
|
|
collectionConfig: { |
|
|
|
@ -293,6 +313,7 @@ describe('Collection component getters and setters', () => { |
|
|
|
dataSource: { |
|
|
|
type: DataVariableType, |
|
|
|
path: 'my_data_source_id', |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
@ -302,38 +323,39 @@ describe('Collection component getters and setters', () => { |
|
|
|
test('HTML output should reflect changes in startIndex', () => { |
|
|
|
cmp.setStartIndex(0); |
|
|
|
const html = cmp.toHTML(); |
|
|
|
expect(html).toContain('data-user="user1"'); |
|
|
|
expect(html).toContain('data-user="user2"'); |
|
|
|
expect(html).toContain('data-user="user3"'); |
|
|
|
expect(html).toContain('dataUser="user1"'); |
|
|
|
expect(html).toContain('dataUser="user2"'); |
|
|
|
expect(html).toContain('dataUser="user3"'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('HTML output should reflect changes in endIndex', () => { |
|
|
|
cmp.setEndIndex(3); |
|
|
|
const html = cmp.toHTML(); |
|
|
|
expect(html).toContain('data-user="user2"'); |
|
|
|
expect(html).toContain('data-user="user3"'); |
|
|
|
expect(html).toContain('dataUser="user2"'); |
|
|
|
expect(html).toContain('dataUser="user3"'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
test('HTML output should reflect changes in dataSource', () => { |
|
|
|
dsm.add({ |
|
|
|
id: 'new_data_source_id', |
|
|
|
records: [ |
|
|
|
{ id: 'user4', user: 'user4', firstName: 'Name4', age: '20' }, |
|
|
|
], |
|
|
|
records: [{ id: 'user4', user: 'user4', firstName: 'Name4', age: '20' }], |
|
|
|
}); |
|
|
|
cmp.setDataSource({ |
|
|
|
type: DataVariableType, |
|
|
|
path: 'new_data_source_id', |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
const html = cmp.toHTML(); |
|
|
|
expect(html).toContain('data-user="user4"'); |
|
|
|
expect(html).toContain('dataUser="user4"'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('HTML output should be empty when endIndex is zero', () => { |
|
|
|
cmp.setEndIndex(0); |
|
|
|
const html = cmp.toHTML(); |
|
|
|
expect(html).not.toContain('data-user'); |
|
|
|
expect(html).not.toContain('dataUser'); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |