var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import { DataTypes, ParticipationStatus } from '@reltio/mdm-sdk';
import { COLUMNS_DATA, countAttributeValues, getBasicTableColumnsData, getBasicTableRowsData, getRuleTypeValues, getWinnerCrosswalks, collectRuleNames } from './helpers';
import { HeadCellRenderer } from './components/HeadCellRenderer';
import { AttributesHeadCellRenderer } from './components/AttributesHeadCellRenderer';
import { OvValuesRenderer } from './components/OvValuesRenderer';
import { AttributeValuesRenderer } from './components/AttributeValuesRenderer';
import { RuleTypeRenderer } from './components/RuleTypeRenderer';
import { WinnerSourcesRenderer } from './components/WinnerSourcesRenderer';
import { CountRenderer } from './components/CountRenderer';
describe('helpers tests', function () {
    describe('getBasicTableColumnsData', function () {
        it('should return correct columns data', function () {
            expect(getBasicTableColumnsData(COLUMNS_DATA)).toEqual([
                {
                    id: 'ovValues',
                    label: 'Attributes & OV',
                    autoResize: false,
                    sortable: false,
                    resizable: true,
                    initialWidth: 360,
                    minWidth: 250,
                    headCellRenderer: AttributesHeadCellRenderer,
                    rowCellValueRenderer: OvValuesRenderer
                },
                {
                    id: 'winnerSources',
                    label: 'Winner source systems',
                    autoResize: false,
                    sortable: false,
                    resizable: true,
                    initialWidth: 220,
                    headCellRenderer: HeadCellRenderer,
                    rowCellValueRenderer: WinnerSourcesRenderer
                },
                {
                    id: 'ruleType',
                    label: 'Rule type',
                    autoResize: false,
                    sortable: false,
                    resizable: true,
                    initialWidth: 200,
                    headCellRenderer: HeadCellRenderer,
                    rowCellValueRenderer: RuleTypeRenderer
                },
                {
                    id: 'count',
                    label: 'Count',
                    autoResize: false,
                    sortable: false,
                    resizable: true,
                    initialWidth: 80,
                    minWidth: 80,
                    headCellRenderer: HeadCellRenderer,
                    rowCellValueRenderer: CountRenderer
                },
                {
                    id: 'values',
                    label: 'Attribute values',
                    autoResize: true,
                    sortable: false,
                    resizable: true,
                    headCellRenderer: HeadCellRenderer,
                    rowCellValueRenderer: AttributeValuesRenderer
                }
            ]);
        });
    });
    describe('getBasicTableRowsData', function () {
        it('should return correct rows data', function () {
            var attrTypes = [
                {
                    label: 'Country Code',
                    name: 'CountryCode',
                    type: 'String',
                    uri: 'configuration/entityTypes/HCP/attributes/CountryCode'
                },
                {
                    label: 'Date',
                    name: 'Date',
                    type: 'Date',
                    uri: 'configuration/entityTypes/HCP/attributes/Date'
                },
                {
                    label: 'Address',
                    name: 'Address',
                    type: 'Reference',
                    uri: 'configuration/entityTypes/HCP/attributes/Address'
                }
            ];
            var metadata = {
                entityTypes: [
                    {
                        uri: 'configuration/entityTypes/HCP',
                        label: 'HCP',
                        attributes: attrTypes,
                        survivorshipGroups: [
                            {
                                uri: 'configuration/entityTypes/HCP/survivorshipGroups/default',
                                default: true,
                                mapping: [
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/CountryCode',
                                        survivorshipStrategy: 'LUD'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Date',
                                        survivorshipStrategy: 'Frequency'
                                    }
                                ]
                            }
                        ]
                    }
                ],
                survivorshipStrategies: [
                    {
                        uri: 'configuration/survivorshipStrategies/LUD',
                        label: 'Recency'
                    },
                    {
                        uri: 'configuration/survivorshipStrategies/Frequency',
                        label: 'Frequency'
                    }
                ]
            };
            var crosswalks = [
                {
                    uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                    type: 'configuration/sources/Reltio',
                    value: 'nQpZyQt',
                    reltioLoadDate: '2021-06-11T08:24:31.726Z',
                    createDate: '2018-11-19T12:14:00.735Z',
                    updateDate: '2018-11-19T12:14:00.735Z',
                    attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                    singleAttributeUpdateDates: {
                        'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                    }
                },
                {
                    uri: 'entities/j8K1vc9/crosswalks/1CwTinUzm',
                    type: 'configuration/sources/AHA',
                    value: 'AHA_LEV',
                    reltioLoadDate: '2021-06-09T11:32:16.434Z',
                    sourcePublishDate: '1970-01-01T00:00:00.000Z',
                    createDate: '2018-11-28T13:16:18.540Z',
                    updateDate: '2018-11-28T13:16:18.540Z',
                    attributes: ['entities/1/attributes/Date/1'],
                    singleAttributeUpdateDates: {
                        'entities/1/attributes/Date/1': '2021-06-09T11:32:16.434Z'
                    }
                }
            ];
            var columns = COLUMNS_DATA.map(function (_a) {
                var id = _a.id;
                return id;
            });
            var attributes = {
                CountryCode: [
                    {
                        uri: 'entities/1/attributes/CountryCode/1',
                        type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                        value: 'Italy',
                        lookupCode: 'IT',
                        ov: true
                    },
                    {
                        uri: 'entities/1/attributes/CountryCode/uri$$1',
                        type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                        value: 'Russia',
                        lookupCode: 'RU'
                    }
                ],
                Date: [
                    {
                        uri: 'entities/1/attributes/Date/1',
                        type: 'configuration/entityTypes/HCP/attributes/Date',
                        value: '123456',
                        ov: false
                    }
                ],
                Address: [
                    {
                        label: '3588 Granada Aveue Santa Clara',
                        relationshipLabel: 'Office',
                        value: {
                            AddressLine1: [
                                {
                                    type: 'configuration/entityTypes/Location/attributes/AddressLine1',
                                    ov: true,
                                    value: '3588 Granada Aveue',
                                    uri: 'entities/1/attributes/Address/1/AddressLine1/1'
                                }
                            ]
                        },
                        ov: true,
                        uri: 'entities/1/attributes/Address/1',
                        refEntity: {
                            type: 'configuration/entityTypes/Location',
                            crosswalks: [
                                {
                                    uri: 'entities/1/crosswalks/1YWdmjzf.3VKnDCovj',
                                    type: 'configuration/sources/HMS',
                                    value: 'cww1',
                                    createDate: '2020-09-02T16:19:12.943Z',
                                    updateDate: '2020-09-02T16:19:12.943Z',
                                    attributeURIs: [
                                        'entities/1/attributes/Address/1/AddressLine1/1',
                                        'entities/1/attributes/Address/1'
                                    ]
                                }
                            ],
                            objectURI: 'entities/1'
                        },
                        refRelation: {
                            type: 'configuration/relationTypes/HasAddress',
                            crosswalks: [
                                {
                                    uri: 'entities/1/crosswalks/uAGtqeB.3VKnDCtBz',
                                    type: 'configuration/sources/HMS',
                                    value: 'cww2',
                                    createDate: '2020-09-02T16:19:12.943Z',
                                    updateDate: '2020-09-02T16:19:12.943Z',
                                    attributeURIs: [
                                        'entities/1/attributes/Address/1/AddressLine/1',
                                        'entities/1/attributes/Address/1'
                                    ]
                                }
                            ],
                            startRefPinned: false,
                            endRefPinned: false,
                            startRefIgnored: false,
                            endRefIgnored: false,
                            objectURI: 'relations/1'
                        },
                        startObjectCrosswalks: [
                            {
                                type: 'configuration/sources/HMS',
                                value: 'cww3'
                            }
                        ]
                    }
                ]
            };
            var entityCrosswalksMap = {
                'entities/1/attributes/CountryCode/1': [crosswalks[0]],
                'entities/1/attributes/Date/1': [crosswalks[0], crosswalks[1]],
                'entities/1/attributes/CountryCode/uri$$1': [crosswalks[1]]
            };
            var relationCrosswalksMap = {
                'entities/1/attributes/Address/1/AddressLine/1': attributes['Address'][0]['refRelation']['crosswalks'],
                'entities/1/attributes/Address/1': attributes['Address'][0]['refRelation']['crosswalks']
            };
            expect(getBasicTableRowsData(metadata, 'configuration/entityTypes/HCP', attrTypes, columns, { entity: entityCrosswalksMap, relation: relationCrosswalksMap }, attributes)).toEqual([
                {
                    ovValues: {
                        values: [attributes['CountryCode'][0]],
                        attributeType: metadata.entityTypes[0].attributes[0]
                    },
                    winnerSources: {
                        crosswalks: [crosswalks[0]]
                    },
                    ruleType: {
                        ruleTypes: [
                            {
                                data: {
                                    strategy: {
                                        uri: 'configuration/survivorshipStrategies/LUD',
                                        label: 'Recency'
                                    },
                                    comparisonAttributeUri: undefined,
                                    primaryAttributeUri: undefined,
                                    sourcesUriOrder: undefined
                                },
                                type: 'rule',
                                valueUri: 'entities/1/attributes/CountryCode/1'
                            }
                        ]
                    },
                    count: 2,
                    values: {
                        attributeType: metadata.entityTypes[0].attributes[0],
                        crosswalksMap: entityCrosswalksMap,
                        attributeValues: attributes['CountryCode']
                    },
                    rawValue: attributes['CountryCode']
                },
                {
                    ovValues: {
                        values: [],
                        attributeType: metadata.entityTypes[0].attributes[1]
                    },
                    winnerSources: {
                        crosswalks: []
                    },
                    ruleType: {
                        ruleTypes: [
                            {
                                data: {
                                    strategy: {
                                        uri: 'configuration/survivorshipStrategies/Frequency',
                                        label: 'Frequency'
                                    },
                                    comparisonAttributeUri: undefined,
                                    primaryAttributeUri: undefined,
                                    sourcesUriOrder: undefined
                                },
                                type: 'rule',
                                valueUri: 'entities/1/attributes/Date/1'
                            }
                        ]
                    },
                    count: 2,
                    values: {
                        attributeType: metadata.entityTypes[0].attributes[1],
                        crosswalksMap: entityCrosswalksMap,
                        attributeValues: attributes['Date']
                    },
                    rawValue: attributes['Date']
                },
                {
                    ovValues: {
                        values: attributes['Address'],
                        attributeType: metadata.entityTypes[0].attributes[2]
                    },
                    winnerSources: {
                        crosswalks: attributes['Address'][0]['refRelation']['crosswalks']
                    },
                    ruleType: {
                        ruleTypes: [
                            {
                                data: {
                                    strategy: {
                                        uri: 'configuration/survivorshipStrategies/LUD',
                                        label: 'Recency'
                                    },
                                    comparisonAttributeUri: undefined,
                                    primaryAttributeUri: undefined,
                                    sourcesUriOrder: undefined
                                },
                                type: 'rule',
                                valueUri: 'entities/1/attributes/Address/1'
                            }
                        ]
                    },
                    count: 1,
                    values: {
                        attributeType: metadata.entityTypes[0].attributes[2],
                        crosswalksMap: relationCrosswalksMap,
                        attributeValues: attributes['Address']
                    },
                    rawValue: attributes['Address']
                }
            ]);
        });
        describe('countAttributeValues', function () {
            var crosswalks = [
                {
                    uri: 'entities/j8K1vc9/crosswalks/12jf9nL05',
                    type: 'configuration/sources/Reltio',
                    value: 'nQpZyQt',
                    reltioLoadDate: '2021-06-11T08:24:31.726Z',
                    createDate: '2018-11-19T12:14:00.735Z',
                    updateDate: '2018-11-19T12:14:00.735Z',
                    attributes: ['entities/1/attributes/CountryCode/1', 'entities/1/attributes/Date/1'],
                    singleAttributeUpdateDates: {
                        'entities/1/attributes/Date/1': '2018-11-29T05:39:56.445Z'
                    }
                },
                {
                    uri: 'entities/j8K1vc9/crosswalks/1CwTinUzm',
                    type: 'configuration/sources/AHA',
                    value: 'AHA_LEV',
                    reltioLoadDate: '2021-06-09T11:32:16.434Z',
                    sourcePublishDate: '1970-01-01T00:00:00.000Z',
                    createDate: '2018-11-28T13:16:18.540Z',
                    updateDate: '2018-11-28T13:16:18.540Z',
                    attributes: ['entities/1/attributes/Date/1'],
                    singleAttributeUpdateDates: {
                        'entities/1/attributes/Date/1': '2021-06-09T11:32:16.434Z'
                    }
                }
            ];
            var values = [
                {
                    uri: 'entities/1/attributes/Date/1',
                    type: 'configuration/entityTypes/HCP/attributes/Date',
                    value: '123456',
                    ov: false
                }
            ];
            var crosswalksMap = {
                'entities/1/attributes/Date/1': [crosswalks[0], crosswalks[1]]
            };
            it('should return correct values count for simple attribute', function () {
                expect(countAttributeValues(DataTypes.TYPE_STRING, values, crosswalksMap)).toBe(2);
            });
            it('should return correct values count for simple attribute if crosswalksMap is empty', function () {
                expect(countAttributeValues(DataTypes.TYPE_STRING, values, {})).toBe(0);
            });
            it('should return correct values count for reference attribute', function () {
                expect(countAttributeValues(DataTypes.TYPE_REFERENCE, values, crosswalksMap)).toBe(1);
            });
            it('should return correct values count for nested attribute', function () {
                expect(countAttributeValues(DataTypes.TYPE_NESTED, values, crosswalksMap)).toBe(1);
            });
            it('should return correct values count for image attribute', function () {
                expect(countAttributeValues(DataTypes.TYPE_IMAGE, values, crosswalksMap)).toBe(1);
            });
            it('should return 0 for empty values', function () {
                expect(countAttributeValues(DataTypes.TYPE_STRING, undefined, crosswalksMap)).toBe(0);
                expect(countAttributeValues(DataTypes.TYPE_NESTED, undefined, crosswalksMap)).toBe(0);
            });
        });
        describe('getRuleTypeValues', function () {
            var metadata = {
                entityTypes: [
                    {
                        uri: 'configuration/entityTypes/HCP',
                        label: 'HCP',
                        attributes: [
                            {
                                label: 'Country Code',
                                name: 'CountryCode',
                                type: 'String',
                                uri: 'configuration/entityTypes/HCP/attributes/CountryCode'
                            },
                            {
                                label: 'Int',
                                name: 'Int',
                                type: 'Int',
                                uri: 'configuration/entityTypes/HCP/attributes/Int'
                            }
                        ],
                        survivorshipGroups: [
                            {
                                uri: 'configuration/entityTypes/HCP/survivorshipGroups/default',
                                default: true,
                                mapping: [
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Int',
                                        survivorshipStrategy: 'Aggregation'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Gender',
                                        survivorshipStrategy: 'SRC_SYS'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/ScheduledDrug',
                                        survivorshipStrategy: 'OtherAttributeWinnerCrosswalk',
                                        primaryAttributeUri: 'configuration/entityTypes/HCP/attributes/CountryCode'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Address',
                                        survivorshipStrategy: 'MinValue',
                                        comparisonAttributeUri: 'configuration/entityTypes/HCP/attributes/Address/attributes/Status'
                                    }
                                ]
                            },
                            {
                                uri: 'configuration/entityTypes/HCP/survivorshipGroups/allRecency',
                                default: false,
                                mapping: [
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Int',
                                        survivorshipStrategy: 'Recency'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Gender',
                                        survivorshipStrategy: 'Recency'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/ScheduledDrug',
                                        survivorshipStrategy: 'Recency'
                                    },
                                    {
                                        attribute: 'configuration/entityTypes/HCP/attributes/Address',
                                        survivorshipStrategy: 'Recency'
                                    }
                                ]
                            }
                        ]
                    }
                ],
                survivorshipStrategies: [
                    {
                        uri: 'configuration/survivorshipStrategies/LUD',
                        label: 'Recency'
                    },
                    {
                        uri: 'configuration/survivorshipStrategies/Aggregation',
                        label: 'Aggregation'
                    },
                    {
                        uri: 'configuration/survivorshipStrategies/Frequency',
                        label: 'Frequency'
                    },
                    {
                        uri: 'configuration/survivorshipStrategies/SRC_SYS',
                        label: 'Source system'
                    },
                    {
                        uri: 'configuration/survivorshipStrategies/OtherAttributeWinnerCrosswalk',
                        label: 'Other Attribute Winner Crosswalk'
                    },
                    {
                        uri: 'configuration/survivorshipStrategies/MinValue',
                        label: 'Minimum value'
                    }
                ],
                sources: [
                    {
                        uri: 'configuration/sources/TEST',
                        label: 'TEST',
                        description: 'test',
                        icon: 'images/source/source_s.png',
                        abbreviation: 'TEST'
                    }
                ]
            };
            it('should return correct simple rule type', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/1/attributes/Int/1',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/Aggregation',
                                    label: 'Aggregation'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/1/attributes/Int/1'
                        }
                    ]
                });
            });
            it('should return correct rule type based on active strategy', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/1/attributes/Int/1',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues, 'configuration/entityTypes/HCP/survivorshipGroups/allRecency')).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/LUD',
                                    label: 'Recency'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/1/attributes/Int/1'
                        }
                    ]
                });
            });
            it('should use default one if strategy url is incorrect', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/1/attributes/Int/1',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues, 'configuration/entityTypes/HCP/survivorshipGroups/unexisting')).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/Aggregation',
                                    label: 'Aggregation'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/1/attributes/Int/1'
                        }
                    ]
                });
            });
            it('should return correct rule type with sourcesUriOrder', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Gender',
                    type: 'String',
                    name: 'Gender',
                    label: 'Gender'
                };
                var attributeValues = [
                    {
                        uri: 'entities/1/attributes/Gender/1',
                        type: 'configuration/entityTypes/HCP/attributes/Gender',
                        value: 'F',
                        ov: true
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/SRC_SYS',
                                    label: 'Source system'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: ['configuration/sources/TEST', 'configuration/sources/Reltio']
                            },
                            type: 'rule',
                            valueUri: 'entities/1/attributes/Gender/1'
                        }
                    ]
                });
            });
            it('should return correct rule type with primaryAttributeUri', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/ScheduledDrug',
                    type: 'String',
                    name: 'ScheduledDrug',
                    label: 'ScheduledDrug'
                };
                var attributeValues = [
                    {
                        uri: 'entities/1/attributes/ScheduledDrug/1',
                        type: 'configuration/entityTypes/HCP/attributes/ScheduledDrug',
                        value: 'Aspirin',
                        ov: true
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/OtherAttributeWinnerCrosswalk',
                                    label: 'Other Attribute Winner Crosswalk'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: 'configuration/entityTypes/HCP/attributes/CountryCode',
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/1/attributes/ScheduledDrug/1'
                        }
                    ]
                });
            });
            it('should return correct rule type with comparisonAttributeUri', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Address',
                    type: 'Reference',
                    name: 'Address',
                    label: 'Address',
                    referencedAttributeURIs: ['configuration/relationTypes/HasAddress/attributes/Status']
                };
                var attributeValues = [
                    {
                        uri: 'entities/1/attributes/Address/1',
                        type: 'configuration/entityTypes/HCP/attributes/Address',
                        value: {},
                        ov: true
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/MinValue',
                                    label: 'Minimum value'
                                },
                                comparisonAttributeUri: 'configuration/relationTypes/HasAddress/attributes/Status',
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/1/attributes/Address/1'
                        }
                    ]
                });
            });
            it('should return rule type with fallback labels if last applied survivorship rules differ from default one', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/123abc/attributes/Int/345fgh',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: {
                                SRC_SYS: [{ SRC_SYS: ['SRC_SYS', 'Aggregation'] }, { SRC_SYS: ['LUD'] }, 'Frequency']
                            }
                        }
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/Frequency',
                                    label: 'Frequency'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Int/345fgh'
                        }
                    ]
                });
            });
            it('should return rule types per OV value with duplicates and ignore non-OV values', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/123abc/attributes/Int/345fgh',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: {
                                SRC_SYS: [{ SRC_SYS: ['SRC_SYS', 'Aggregation'] }, 'Frequency']
                            }
                        }
                    },
                    {
                        uri: 'entities/123abc/attributes/Int/ghj565',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1006',
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: {
                                SRC_SYS: [{ SRC_SYS: ['SRC_SYS', 'Aggregation'] }, 'Frequency']
                            }
                        }
                    },
                    {
                        uri: 'entities/123abc/attributes/Int/nonOvValue',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1006-non-ov',
                        ov: false,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: {
                                SRC_SYS: [{ SRC_SYS: ['SRC_SYS', 'Aggregation'] }, 'Aggregation']
                            }
                        }
                    },
                    {
                        uri: 'entities/123abc/attributes/Int/xfjhy6',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1007',
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: {
                                SRC_SYS: [{ SRC_SYS: ['SRC_SYS', 'Aggregation'] }, { SRC_SYS: ['LUD'] }]
                            }
                        }
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/Frequency',
                                    label: 'Frequency'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Int/345fgh'
                        },
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/Frequency',
                                    label: 'Frequency'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Int/ghj565'
                        },
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/LUD',
                                    label: 'Recency'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Int/xfjhy6'
                        }
                    ]
                });
            });
            it('should return default rule type if applied survivorship rules are invalid', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/123abc/attributes/Int/345fgh',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: 'N/A'
                        }
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/Aggregation',
                                    label: 'Aggregation'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Int/345fgh'
                        }
                    ]
                });
            });
            it('should return rule type with sourcesUriOrder from applied survivorship rules', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Int',
                    type: 'Int',
                    name: 'Int',
                    label: 'Int'
                };
                var attributeValues = [
                    {
                        uri: 'entities/123abc/attributes/Int/345fgh',
                        type: 'configuration/entityTypes/HCP/attributes/Int',
                        value: '1005',
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: 'SRC_SYS'
                        }
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/SRC_SYS',
                                    label: 'Source system'
                                },
                                comparisonAttributeUri: undefined,
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: ['configuration/sources/TEST', 'configuration/sources/Reltio']
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Int/345fgh'
                        }
                    ]
                });
            });
            it('should return default rule type for complex attribute even if there are different applied survivorship rules', function () {
                var attributeType = {
                    uri: 'configuration/entityTypes/HCP/attributes/Address',
                    type: 'Reference',
                    name: 'Address',
                    label: 'Address',
                    referencedAttributeURIs: ['configuration/relationTypes/HasAddress/attributes/Status']
                };
                var attributeValues = [
                    {
                        uri: 'entities/123abc/attributes/Address/345fgh',
                        type: 'configuration/entityTypes/HCP/attributes/Address',
                        value: {
                            Status: [
                                {
                                    uri: 'entities/123abc/attributes/Status/345fgh',
                                    type: 'configuration/relationTypes/HasAddress/attributes/Status',
                                    value: '1005'
                                }
                            ]
                        },
                        ov: true,
                        ovDetails: {
                            participationStatus: ParticipationStatus.Strategy,
                            appliedSurvivorshipRules: 'Aggregation'
                        }
                    }
                ];
                expect(getRuleTypeValues(metadata, attributeType, 'configuration/entityTypes/HCP', attributeValues)).toEqual({
                    ruleTypes: [
                        {
                            data: {
                                strategy: {
                                    uri: 'configuration/survivorshipStrategies/MinValue',
                                    label: 'Minimum value'
                                },
                                comparisonAttributeUri: 'configuration/relationTypes/HasAddress/attributes/Status',
                                primaryAttributeUri: undefined,
                                sourcesUriOrder: undefined
                            },
                            type: 'rule',
                            valueUri: 'entities/123abc/attributes/Address/345fgh'
                        }
                    ]
                });
            });
        });
        describe('getWinnerCrosswalks', function () {
            var crosswalksMap = {
                'entities/1YWdnqBn/attributes/City/3VKnDJHZz': [
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/3VKnDGwfD',
                        type: 'configuration/sources/HMS',
                        value: 'cw71',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    },
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/3VKnDJQ6V"',
                        type: 'configuration/sources/HMS',
                        value: 'cwv1',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    }
                ],
                'entities/1YWdnqBn/attributes/Country/1EfZhJQ': [
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/abc',
                        type: 'configuration/sources/Reltio',
                        value: 'cw71',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    },
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/3VKnDJQ6V"',
                        type: 'configuration/sources/HMS',
                        value: 'cwv1',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    }
                ],
                'entities/1YWdnqBn/attributes/FirstLevelNested/1CwTioWve': [
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/1CwTinuZK',
                        type: 'configuration/sources/Reltio',
                        value: 'cw71',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    },
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/1vLQ8Mihl',
                        type: 'configuration/sources/Reltio',
                        value: '2',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    }
                ],
                'entities/1YWdnqBn/attributes/FirstLevelNested/1CwTioWve/FirstLevelNestedSub1/1vLQ8PGPJ': [
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/1vLQ8NL45',
                        type: 'configuration/sources/AOA',
                        value: 'AOA3',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    }
                ],
                'entities/1YWdnqBn/attributes/NestedWithoutParent/1CwTioWve/NestedWithoutParentSub1/1vLQ8PGPJ': [
                    {
                        uri: 'entities/1YWdnqBn/crosswalks/1vLQ8NL45',
                        type: 'configuration/sources/AOA',
                        value: 'AOA3',
                        createDate: '2021-05-14T05:21:14.532Z',
                        updateDate: '2021-05-14T05:21:14.532Z',
                        reltioLoadDate: '2019-07-24T06:18:18.041Z',
                        singleAttributeUpdateDates: {},
                        attributes: []
                    }
                ]
            };
            it('should return correct winner crosswalk', function () {
                var attributeValues = [
                    {
                        ov: true,
                        value: 'Santa Clara',
                        uri: 'entities/1YWdnqBn/attributes/City/3VKnDJHZz'
                    },
                    {
                        ov: false,
                        value: 'one',
                        uri: 'entities/1YWdnqBn/attributes/Country/1EfZhJQ'
                    }
                ];
                expect(getWinnerCrosswalks(attributeValues, crosswalksMap)).toEqual(crosswalksMap['entities/1YWdnqBn/attributes/City/3VKnDJHZz']);
            });
            it('should retrun winner crosswalk without duplicates', function () {
                var attributeValues = [
                    {
                        ov: true,
                        value: 'Santa Clara',
                        uri: 'entities/1YWdnqBn/attributes/City/3VKnDJHZz'
                    },
                    {
                        ov: true,
                        value: 'one',
                        uri: 'entities/1YWdnqBn/attributes/Country/1EfZhJQ'
                    }
                ];
                expect(getWinnerCrosswalks(attributeValues, crosswalksMap)).toEqual(__spreadArray(__spreadArray([], crosswalksMap['entities/1YWdnqBn/attributes/City/3VKnDJHZz'], true), [
                    crosswalksMap['entities/1YWdnqBn/attributes/Country/1EfZhJQ'][0]
                ], false));
            });
            it('should return correct winner crosswalk for nested attribute', function () {
                var attributeValues = [
                    {
                        ov: true,
                        uri: 'entities/1YWdnqBn/attributes/FirstLevelNested/1CwTioWve',
                        value: {
                            FirstLevelNestedSub1: [
                                {
                                    type: 'configuration/entityTypes/HCA/attributes/FirstLevelNested/attributes/FirstLevelNestedSub1',
                                    ov: true,
                                    value: 'Afrikaans',
                                    uri: 'entities/1YWdnqBn/attributes/FirstLevelNested/1CwTioWve/FirstLevelNestedSub1/1vLQ8PGPJ'
                                }
                            ]
                        }
                    }
                ];
                expect(getWinnerCrosswalks(attributeValues, crosswalksMap)).toEqual(__spreadArray(__spreadArray([], crosswalksMap['entities/1YWdnqBn/attributes/FirstLevelNested/1CwTioWve'], true), crosswalksMap['entities/1YWdnqBn/attributes/FirstLevelNested/1CwTioWve/FirstLevelNestedSub1/1vLQ8PGPJ'], true));
            });
            it('should return correct winner crosswalk for nested attribute if there is no crosswalk for parent attribute', function () {
                var attributeValues = [
                    {
                        ov: true,
                        uri: 'entities/1YWdnqBn/attributes/NestedWithoutParent/1CwTioWve',
                        value: {
                            FirstLevelNestedSub1: [
                                {
                                    type: 'configuration/entityTypes/HCA/attributes/NestedWithoutParent/attributes/NestedWithoutParentSub1',
                                    ov: true,
                                    value: 'Afrikaans',
                                    uri: 'entities/1YWdnqBn/attributes/NestedWithoutParent/1CwTioWve/NestedWithoutParentSub1/1vLQ8PGPJ'
                                }
                            ]
                        }
                    }
                ];
                expect(getWinnerCrosswalks(attributeValues, crosswalksMap)).toEqual(crosswalksMap['entities/1YWdnqBn/attributes/NestedWithoutParent/1CwTioWve/NestedWithoutParentSub1/1vLQ8PGPJ']);
            });
            it('should return empty array for empty values', function () {
                expect(getWinnerCrosswalks(undefined, crosswalksMap)).toEqual([]);
            });
        });
        describe('collectRuleNames', function () {
            it('should return single rule when input is a string', function () {
                expect(collectRuleNames('LUD')).toEqual(['LUD']);
            });
            it('should return empty array for empty object', function () {
                expect(collectRuleNames({})).toEqual([]);
            });
            it('should flatten nested applied survivorship rules', function () {
                var rules = {
                    SRC_SYS: [{ SRC_SYS: ['SRC_SYS', 'Aggregation'] }, { SRC_SYS: ['LUD'] }, 'Frequency']
                };
                expect(collectRuleNames(rules)).toEqual([
                    'SRC_SYS',
                    'SRC_SYS',
                    'SRC_SYS',
                    'Aggregation',
                    'SRC_SYS',
                    'LUD',
                    'Frequency'
                ]);
            });
            it('should handle rules with multiple top-level keys', function () {
                var rules = {
                    SRC_SYS: ['LUD', { SRC_SYS: ['SRC_SYS', 'Aggregation'] }],
                    SRC_SYS2: ['Aggregation']
                };
                expect(collectRuleNames(rules)).toEqual([
                    'SRC_SYS',
                    'LUD',
                    'SRC_SYS',
                    'SRC_SYS',
                    'Aggregation',
                    'SRC_SYS2',
                    'Aggregation'
                ]);
            });
            it('should handle rules with empty nested arrays', function () {
                var rules = { SRC_SYS: ['LUD', { SRC_SYS: [] }] };
                expect(collectRuleNames(rules)).toEqual(['SRC_SYS', 'LUD', 'SRC_SYS']);
            });
        });
    });
});
