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 { dissoc } from 'ramda';
import { render, screen, fireEvent } from '@testing-library/react';
import { SourceIcon } from '../SourceIcon';
import { MdmModuleProvider } from '../contexts/MdmModuleContext';
var defaultMetadata = {
    sources: [
        {
            uri: 'configuration/sources/Reltio',
            label: 'Reltio',
            icon: 'images/source/reltio.png',
            abbreviation: 'Reltio'
        }
    ]
};
var defaultProps = {
    sourceType: 'configuration/sources/Reltio',
    className: 'someClassName'
};
var defaultMdmValues = { metadata: defaultMetadata };
var setUp = function (_a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? defaultProps : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d;
    var Providers = function (_a) {
        var children = _a.children;
        return (React.createElement(MdmModuleProvider, { values: mdmValues }, children));
    };
    return render(React.createElement(SourceIcon, __assign({}, props)), { wrapper: Providers });
};
describe('Source icon tests', function () {
    it('should show correct icon based on metadata', function () {
        setUp();
        expect(screen.queryByText('R')).not.toBeInTheDocument();
        expect(screen.getByRole('img')).toHaveAttribute('src', 'https://s3.amazonaws.com/reltio.images/api/images/source/reltio.png');
    });
    it('should make correct avatarText if the source label is undefined', function () {
        var _a;
        var metadata = { sources: [dissoc('label', (_a = defaultMetadata.sources) === null || _a === void 0 ? void 0 : _a[0])] };
        var mdmValues = { metadata: metadata };
        setUp({ mdmValues: mdmValues });
        var image = screen.getByRole('img');
        fireEvent.error(image);
        screen.getByText('R');
    });
    it('should render correctly if source is empty', function () {
        var props = __assign(__assign({}, defaultProps), { sourceType: 'notExist' });
        setUp({ props: props });
        expect(screen.queryByRole('img')).not.toBeInTheDocument();
    });
});
