"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
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));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var moment_1 = __importDefault(require("moment"));
var helpers_1 = require("./helpers");
var attributes_test_data_1 = require("./attributes.test-data");
var constants_1 = require("./constants");
describe('helpers tests', function () {
    describe('getFormattedSystemImageAttributeValue tests', function () {
        it('should return correct time if CreationTimestamp was provided', function () {
            var value = {
                value: { CreationTimestamp: [{ uri: '1', value: '2021-06-09T13:13:16.563Z' }] }
            };
            var key = 'CreationTime';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe((0, moment_1.default)('2021-06-09T13:13:16.563Z').format('HH:mm:ss'));
        });
        it('should return undefined if CreationTimestamp was not provided', function () {
            var value = { value: { CreationTimestamp: [{ uri: '1', value: '' }] } };
            var key = 'CreationTime';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe(undefined);
        });
        it('should return correct date if CreationTimestamp was provided', function () {
            var value = {
                value: { CreationTimestamp: [{ uri: '1', value: '2021-06-09T13:13:16.563Z' }] }
            };
            var key = 'CreationDate';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe('06-09-2021');
        });
        it('should return url if Url was provided', function () {
            var value = { value: { Url: [{ uri: '1', value: 'vk.com' }] } };
            var key = 'Url';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe('vk.com');
        });
        it('should return undefined if Url was not provided', function () {
            var value = { value: { Url: [{ uri: '1', value: '' }] } };
            var key = 'Url';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe('');
        });
        it('should return dimensions if Dimensions was provided', function () {
            var value = {
                value: { Height: [{ uri: '1', value: '10' }], Width: [{ uri: '1', value: '10' }] }
            };
            var key = 'Dimensions';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe('10 x 10 pixels');
        });
        it('should return undefined if height was not provided', function () {
            var value = {
                value: { Height: [{ uri: '1', value: '' }], Width: [{ uri: '1', value: '10' }] }
            };
            var key = 'Dimensions';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe(undefined);
        });
        it('should return undefined if width was not provided', function () {
            var value = {
                value: { Height: [{ uri: '1', value: '10' }], Width: [{ uri: '1', value: '' }] }
            };
            var key = 'Dimensions';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe(undefined);
        });
        it('should return size if Size was provided', function () {
            var value = { value: { Size: [{ uri: '1', value: '10000' }] } };
            var key = 'Size';
            expect((0, helpers_1.getFormattedSystemImageAttributeValue)(value, key)).toBe('10.00 KB');
        });
    });
    describe('isLink tests', function () {
        it.each(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n            key                  | expected\n            ", "             | ", "\n            ", "      | ", "\n            ", "    | ", "\n            ", "          | ", "\n            ", "   | ", "\n            ", " | ", "\n            ", "         | ", "\n            ", "        | ", "\n        "], ["\n            key                  | expected\n            ", "             | ", "\n            ", "      | ", "\n            ", "    | ", "\n            ", "          | ", "\n            ", "   | ", "\n            ", " | ", "\n            ", "         | ", "\n            ", "        | ", "\n        "])), 'Url', true, 'UrlPreview', true, 'UrlThumbnail', true, 'CdnUrl', true, 'CdnUrlPreview', true, 'CdnUrlThumbnail', true, undefined, false, 'MimeType', false)('return $expected if $key', function (_a) {
            var key = _a.key, expected = _a.expected;
            expect((0, helpers_1.isLink)(key)).toEqual(expected);
        });
    });
    describe('filterByFieldsOrder tests', function () {
        it('should ignore excludeNames if includeNames exists', function () {
            var keys = ['VideoLink', 'AudioLink', 'FullSize'];
            var fieldsOrder = {
                includeNames: ['VideoLink', 'AudioLink'],
                excludeNames: ['AudioLink']
            };
            expect((0, helpers_1.filterByFieldsOrder)(keys, fieldsOrder)).toEqual(fieldsOrder.includeNames);
        });
        it('should exclude keys', function () {
            var keys = Object.keys(constants_1.SYSTEM_ATTRIBUTES_TITLES);
            var fieldsOrder = {
                excludeNames: ['MimeType', 'CreationTime', 'Dimensions', 'UrlThumbnail', 'CdnUrlPreview']
            };
            var expectedResult = ['CreationDate', 'Size', 'Url', 'UrlPreview', 'CdnUrl', 'CdnUrlThumbnail'];
            expect((0, helpers_1.filterByFieldsOrder)(keys, fieldsOrder)).toEqual(expectedResult);
        });
        it('should sort keys', function () {
            var keys = __spreadArray(__spreadArray([], Object.keys(constants_1.SYSTEM_ATTRIBUTES_TITLES), true), ['VideoLink', 'AudioLink', 'FullSize'], false);
            var fieldsOrder = {
                excludeNames: ['MimeType', 'CreationTime', 'Dimensions', 'UrlThumbnail', 'CdnUrlPreview', 'VideoLink'],
                order: ['FullSize', 'Url', 'AudioLink', 'CdnUrl', 'CreationDate']
            };
            var expectedResult = [
                'FullSize',
                'Url',
                'AudioLink',
                'CdnUrl',
                'CreationDate',
                'Size',
                'UrlPreview',
                'CdnUrlThumbnail'
            ];
            expect((0, helpers_1.filterByFieldsOrder)(keys, fieldsOrder)).toStrictEqual(expectedResult);
        });
    });
    describe('getMoreAttrTypes tests', function () {
        it('should return only attributes with system key is "false" correctly', function () {
            expect((0, helpers_1.getMoreAttrTypes)(attributes_test_data_1.attributeType)).toEqual([
                {
                    label: 'String',
                    name: 'String',
                    type: 'String',
                    system: false,
                    uri: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/String'
                },
                {
                    label: 'Long',
                    name: 'Long',
                    type: 'Long',
                    system: false,
                    uri: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/Long'
                },
                {
                    label: 'Date',
                    name: 'Date',
                    type: 'Date',
                    system: false,
                    uri: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/Date'
                }
            ]);
        });
    });
    describe('getSystemAttributesList tests', function () {
        it('should work correctly', function () {
            var expectedResult = [
                {
                    isLink: false,
                    title: 'Creation Time',
                    value: (0, moment_1.default)('2021-07-09T06:42:27.103+0000').format('HH:mm:ss')
                },
                {
                    isLink: false,
                    title: 'Creation Date',
                    value: '07-09-2021'
                },
                {
                    isLink: false,
                    title: 'Dimensions',
                    value: '1034 x 1933 pixels'
                },
                {
                    isLink: false,
                    title: 'Mime Type',
                    value: 'image/jpeg'
                },
                {
                    isLink: false,
                    title: 'Size',
                    value: '637.21 KB'
                },
                {
                    isLink: true,
                    title: 'Full image URL (S3)',
                    value: 'https://vk.com'
                },
                {
                    isLink: true,
                    title: 'Preview image URL (S3)',
                    value: 'https://github.com'
                },
                {
                    isLink: true,
                    title: 'Small image URL (S3)',
                    value: 'https://bitbucket.com'
                },
                {
                    isLink: true,
                    title: 'Full image URL (CDN)',
                    value: 'https://google.com'
                },
                {
                    isLink: true,
                    title: 'Preview image URL (CDN)',
                    value: 'https://twitter.com'
                },
                {
                    isLink: true,
                    title: 'Small image URL (CDN)',
                    value: 'https://facebook.com'
                }
            ];
            expect((0, helpers_1.getSystemAttributesList)(attributes_test_data_1.complexAttributeValue, {})).toEqual(expectedResult);
        });
    });
    describe('getNotSystemAttributesList tests', function () {
        it('should work correctly', function () {
            var expectedResult = [
                {
                    attrType: {
                        label: 'String',
                        name: 'String',
                        system: false,
                        type: 'String',
                        uri: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/String'
                    },
                    values: [
                        {
                            ov: true,
                            type: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/String',
                            uri: 'entities/15RRKaId/attributes/ImageGallery/3aL9d7zDM/String/3aL9d8oMS',
                            value: 'rere'
                        },
                        {
                            type: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/String',
                            uri: 'entities/15RRKaId/attributes/ImageGallery/3aL9d7zDM/String/uri$$1626678443648',
                            value: ''
                        }
                    ]
                },
                {
                    attrType: {
                        label: 'Date',
                        name: 'Date',
                        system: false,
                        type: 'Date',
                        uri: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/Date'
                    },
                    values: [
                        {
                            type: 'configuration/entityTypes/HCP/attributes/ImageGallery/attributes/Date',
                            uri: 'entities/15RRKaId/attributes/ImageGallery/3aL9d7zDM/Date/uri$$1626678310141',
                            value: '2021-07-07'
                        }
                    ]
                }
            ];
            expect((0, helpers_1.getNotSystemAttributesList)(attributes_test_data_1.complexAttributeValue, attributes_test_data_1.attributeType, {})).toEqual(expectedResult);
        });
    });
});
var templateObject_1;
