var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { svg2Url } from '@reltio/mdm-sdk';
import { MdmModuleProvider } from '../contexts/MdmModuleContext';
import { DEFAULT_PROFILE_IMAGE } from './no-photo.svg';
import { EntityAvatar } from './EntityAvatar';
var defaultMetadata = {
    entityTypes: [
        {
            uri: 'configuration/entityTypes/HCP',
            typeImage: 'images/defaultImage/typeImage_gender_neutral.png'
        }
    ]
};
var defaultAbsoluteImagePath = 'http://images.reltio.com';
var defaultMdmValues = {
    metadata: defaultMetadata,
    absoluteImagePath: defaultAbsoluteImagePath
};
var setUp = function (props, mdmValues) {
    if (mdmValues === void 0) { mdmValues = defaultMdmValues; }
    var Providers = function (_a) {
        var children = _a.children;
        return (React.createElement(MdmModuleProvider, { values: mdmValues }, children));
    };
    return render(React.createElement(EntityAvatar, __assign({}, props)), { wrapper: Providers });
};
describe('EntityAvatar tests', function () {
    it('should show avatar correctly', function () {
        var entity = { type: 'configuration/entityTypes/HCP', uri: 'entities/123' };
        setUp({ entity: entity });
        expect(screen.getByRole('img')).toHaveAttribute('src', 'http://images.reltio.com/images/defaultImage/typeImage_gender_neutral.png');
        expect(screen.queryByAltText('fallback entity avatar')).not.toBeInTheDocument();
    });
    it('shoul show default avatar if image failed to load', function () {
        var entity = { type: 'configuration/entityTypes/HCP', uri: 'entities/123' };
        setUp({ entity: entity });
        var image = screen.getByRole('img');
        fireEvent.error(image);
        expect(image).toHaveAttribute('src', svg2Url(DEFAULT_PROFILE_IMAGE));
    });
});
