import { DataTypes } from '@reltio/mdm-sdk';
import { attributeValueToEditorValue } from './attributesView';
describe('attributesView tests', function () {
    describe('attributeValueToEditorValue', function () {
        it('should return true if attribute is boolean and value is string', function () {
            var attributeValue = {
                value: 'true',
                uri: 'configuration/entityTypes/HCP/attributes/Active'
            };
            var attributeType = {
                type: DataTypes.TYPE_BOOLEAN,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toBe(true);
        });
        it('should return false if attribute is boolean and value is string', function () {
            var attributeValue = {
                value: 'false',
                uri: 'configuration/entityTypes/HCP/attributes/Active'
            };
            var attributeType = {
                type: DataTypes.TYPE_BOOLEAN,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toBe(false);
        });
        it('should return the same true if attribute is boolean', function () {
            var attributeValue = {
                value: true,
                uri: 'configuration/entityTypes/HCP/attributes/Active'
            };
            var attributeType = {
                type: DataTypes.TYPE_BOOLEAN,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toBe(true);
        });
        it('should return value of boolean if attribute is string', function () {
            var attributeValue = {
                value: 'false',
                uri: 'configuration/entityTypes/HCP/attributes/Active'
            };
            var attributeType = {
                type: DataTypes.TYPE_STRING,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toBe('false');
        });
        it('should return date plus local TZ offset if attribute is date and value is string', function () {
            var attributeValue = {
                value: '2018-05-12',
                uri: 'configuration/entityTypes/HCP/attributes/Active'
            };
            var attributeType = {
                type: DataTypes.TYPE_DATE,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            var date = new Date(attributeValue.value);
            var expectedTimestamp = date.getTime() + date.getTimezoneOffset() * 60 * 1000;
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toEqual(new Date(expectedTimestamp));
        });
        it('should return null if attribute is date and value is undefined', function () {
            var attributeValue = { uri: 'configuration/entityTypes/HCP/attributes/Active', value: undefined };
            var attributeType = {
                type: DataTypes.TYPE_DATE,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toBe(null);
        });
        it('should return lookup value+lookupCode if attribute is lookup', function () {
            var attributeValue = {
                value: 'KT',
                lookupCode: 'Units Of Measures',
                uri: 'configuration/entityTypes/HCP/attributes/Active'
            };
            var attributeType = {
                type: DataTypes.TYPE_LOOKUP,
                uri: 'configuration/entityTypes/HCP/attributes/Active',
                name: 'Active'
            };
            expect(attributeValueToEditorValue(attributeValue, attributeType)).toEqual({
                lookupCode: 'Units Of Measures',
                value: 'KT'
            });
        });
    });
});
