import { buildLookupEntries } from './helpers';
describe('helpers', function () {
    describe('buildLookupEntries', function () {
        it('should return empty array for empty lookup type', function () {
            expect(buildLookupEntries('type', { type: {} })).toEqual([]);
        });
        it('should return regular entries for lookups with no parents', function () {
            expect(buildLookupEntries('type', { type: { t1: { displayName: 't1' } } })).toEqual([{ value: 't1', label: 't1' }]);
        });
        it('should return entry with combined label if lookup code differs from displayName', function () {
            expect(buildLookupEntries('type', { type: { t1: { displayName: 'name-t1' } } })).toEqual([
                { value: 't1', label: 'name-t1 (t1)' }
            ]);
        });
        it('should return entry with code as label if displayName is empty', function () {
            expect(buildLookupEntries('type', { type: { t1: { displayName: '' } } })).toEqual([{ value: 't1', label: 't1' }]);
        });
        it('should return grouped entries for lookups with parents', function () {
            expect(buildLookupEntries('type', {
                type: {
                    t1: { displayName: 't1', parent: 'parentType.pt1' },
                    t2: { displayName: 't2', parent: 'parentType.pt2' }
                },
                parentType: {
                    pt1: { displayName: 'pt1', parent: 'grandParentType.gpt1' },
                    pt2: { displayName: 'pt2', parent: 'grandParentType.gpt1' }
                },
                grandParentType: {
                    gpt1: { displayName: 'gpt1' }
                }
            })).toEqual([
                {
                    label: 'gpt1',
                    values: [
                        { label: 'pt1', values: [{ value: 't1', label: 't1' }] },
                        { label: 'pt2', values: [{ value: 't2', label: 't2' }] }
                    ]
                }
            ]);
        });
        it('should return correct entries if lookup has special symbols in name', function () {
            var _a, _b, _c;
            expect(buildLookupEntries('type', {
                type: (_a = {},
                    _a['Test Country U.S.'] = { displayName: 'Test Country U.S.', parent: 'parentType.Parent 1.2.3' },
                    _a['With. symbols/.12$%'] = { displayName: 'With. symbols/.12$%', parent: 'parentType.Parent 3/2/1' },
                    _a),
                parentType: (_b = {},
                    _b['Parent 1.2.3'] = { displayName: 'Parent 1.2.3', parent: 'grandParentType.GrandParent.' },
                    _b['Parent 3/2/1'] = { displayName: 'Parent 3/2/1', parent: 'grandParentType.GrandParent.' },
                    _b),
                grandParentType: (_c = {},
                    _c['GrandParent.'] = { displayName: 'GrandParent.' },
                    _c)
            })).toEqual([
                {
                    label: 'GrandParent.',
                    values: [
                        { label: 'Parent 1.2.3', values: [{ value: 'Test Country U.S.', label: 'Test Country U.S.' }] },
                        { label: 'Parent 3/2/1', values: [{ value: 'With. symbols/.12$%', label: 'With. symbols/.12$%' }] }
                    ]
                }
            ]);
        });
        it('should sort entries by label', function () {
            expect(buildLookupEntries('type', {
                type: {
                    t1: { displayName: 'E', parent: 'parentType.pt1' },
                    t2: { displayName: 'D', parent: 'parentType.pt1' },
                    t3: { displayName: 'G', parent: 'parentType.pt2' },
                    t4: { displayName: 'F', parent: 'parentType.pt2' }
                },
                parentType: {
                    pt1: { displayName: 'C', parent: 'grandParentType.gpt1' },
                    pt2: { displayName: 'B', parent: 'grandParentType.gpt1' }
                },
                grandParentType: {
                    gpt1: { displayName: 'A' }
                }
            })).toEqual([
                {
                    label: 'A (gpt1)',
                    values: [
                        {
                            label: 'B (pt2)',
                            values: [
                                { value: 't4', label: 'F (t4)' },
                                { value: 't3', label: 'G (t3)' }
                            ]
                        },
                        {
                            label: 'C (pt1)',
                            values: [
                                { value: 't2', label: 'D (t2)' },
                                { value: 't1', label: 'E (t1)' }
                            ]
                        }
                    ]
                }
            ]);
        });
        it('should not fail if there is no parent lookup', function () {
            expect(buildLookupEntries('Country', {
                Continent: {
                    AS: { displayName: 'Asia' }
                },
                Country: {
                    IT: { displayName: 'Italy', parent: 'Continent.EU' }
                }
            })).toEqual([
                {
                    label: 'EU',
                    values: [
                        {
                            label: 'Italy (IT)',
                            value: 'IT'
                        }
                    ]
                }
            ]);
        });
    });
});
