import React from 'react';
import { mockResizeObserver } from 'jsdom-testing-mocks';
import { render, screen, act } from '@testing-library/react';
import ReadOnlyAttributeValuesBlock from './ReadOnlyAttributeValuesBlock';
describe('Read only attribute values block tests', function () {
    var resizeObserver = mockResizeObserver();
    it('should render read only attribute correctly', function () {
        var values = [
            {
                uri: 'entities/1/attributes/CountryCode/1',
                type: 'configuration/entityTypes/HCP/attributes/CountryCode',
                value: 'Italy',
                lookupCode: 'IT',
                ov: true
            }
        ];
        var attributeType = {
            uri: 'configuration/entityTypes/HCP',
            label: 'HCP',
            name: 'HCP',
            type: 'String',
            attributes: [
                {
                    label: 'Country Code',
                    name: 'CountryCode',
                    type: 'String',
                    uri: 'configuration/entityTypes/HCP/attributes/CountryCode'
                }
            ]
        };
        render(React.createElement(ReadOnlyAttributeValuesBlock, { attributeType: attributeType, values: values }));
        screen.getByText('Italy (IT)');
    });
    it('should render read only image attributes line', function () {
        var attributeType = {
            name: 'ImageGallery',
            type: 'Image',
            uri: 'configuration/entityTypes/Series/attributes/ImageGallery',
            attributes: [
                {
                    name: 'Url',
                    type: 'String',
                    uri: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/Url'
                },
                {
                    name: 'UrlThumbnail',
                    type: 'String',
                    uri: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/UrlThumbnail'
                }
            ]
        };
        var values = [
            {
                value: {
                    Url: [
                        {
                            type: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/Url',
                            ov: true,
                            value: '/test.jpg',
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZv/Url/39V5GWWMh'
                        }
                    ],
                    UrlThumbnail: [
                        {
                            type: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/UrlThumbnail',
                            ov: true,
                            value: '/test.jpg',
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZv/UrlThumbnail/39V5GWWMh'
                        }
                    ]
                },
                ov: true,
                uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZv'
            }
        ];
        var container = render(React.createElement(ReadOnlyAttributeValuesBlock, { attributeType: attributeType, values: values })).container;
        resizeObserver.mockElementSize(container.children[0], { contentBoxSize: { inlineSize: 600 } });
        act(function () {
            resizeObserver.resize();
        });
        expect(screen.getByRole('img')).toHaveAttribute('src', '/test.jpg');
    });
    it('should render nested read only attribute correctly', function () {
        var attributeType = {
            type: 'Nested',
            uri: 'configuration/entityTypes/HCP/attributes/NestedTest',
            name: 'NestedTest',
            label: 'Nested Test',
            attributes: [
                {
                    uri: 'configuration/entityTypes/HCP/attributes/NestedTest/attributes/FirstName',
                    name: 'FirstName',
                    label: 'First Name',
                    type: 'String'
                },
                {
                    uri: 'configuration/entityTypes/HCP/attributes/NestedTest/attributes/LastName',
                    name: 'LastName',
                    label: 'Last Name',
                    type: 'String'
                }
            ]
        };
        var values = [
            {
                label: 'Nested test label 1',
                value: {
                    FirstName: [
                        {
                            value: 'Viktor',
                            uri: 'entities/eNt1/attributes/NestedTest/gd42423/FirstName/8fBsP38A'
                        }
                    ]
                },
                uri: 'entities/eNt1/attributes/NestedTest/gd42423'
            },
            {
                label: 'Nested test label 2',
                value: {
                    LastName: [
                        {
                            value: 'Ivanov',
                            uri: 'entities/eNt1/attributes/NestedTest/ksApL29/LastName/o7BnD6mJ'
                        }
                    ]
                },
                uri: 'entities/eNt1/attributes/NestedTest/ksApL29'
            }
        ];
        render(React.createElement(ReadOnlyAttributeValuesBlock, { expanded: true, attributeType: attributeType, values: values }));
        screen.getByText('Nested test label 1');
        screen.getByText('First Name');
        screen.getByText('Viktor');
        screen.getByText('Nested test label 2');
        screen.getByText('Last Name');
        screen.getByText('Ivanov');
    });
});
