"use strict";
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);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var react_2 = require("@testing-library/react");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var no_photo_svg_1 = require("./no-photo.svg");
var EntityAvatar_1 = require("./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_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues }, children));
    };
    return (0, react_2.render)(react_1.default.createElement(EntityAvatar_1.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(react_2.screen.getByRole('img')).toHaveAttribute('src', 'http://images.reltio.com/images/defaultImage/typeImage_gender_neutral.png');
        expect(react_2.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 = react_2.screen.getByRole('img');
        react_2.fireEvent.error(image);
        expect(image).toHaveAttribute('src', (0, mdm_sdk_1.svg2Url)(no_photo_svg_1.DEFAULT_PROFILE_IMAGE));
    });
});
